Skip to content

Commit

Permalink
feat: use golang 1.19 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
allisson authored Oct 13, 2022
1 parent 031344a commit fc197fa
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 115 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand All @@ -42,7 +42,7 @@ jobs:
run: go mod download

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-pkg-cache: true
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
linters:
enable:
- gosec
- rowserrcheck
- sqlclosecheck
- ifshort
- goimports
linters-settings:
goimports:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### development stage
FROM golang:1.16-buster AS build-env
FROM golang:1.19 AS build-env

# set envvar
ENV CGO_ENABLED=0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-protobuf:
lint:
if [ ! -f ./bin/golangci-lint ] ; \
then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.43.0; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.0; \
fi;
./bin/golangci-lint run --fix

Expand Down
37 changes: 28 additions & 9 deletions cmd/hammer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/allisson/hammer"
pb "github.com/allisson/hammer/api/v1"
Expand All @@ -34,10 +35,11 @@ import (
)

var (
sqlDB *sqlx.DB
sqlConn *sql.Conn
grpcEndpoint string
httpEndpoint string
sqlDB *sqlx.DB
sqlConn *sql.Conn
grpcEndpoint string
httpEndpoint string
readHeaderTimeout time.Duration
)

type appContext struct {
Expand Down Expand Up @@ -86,14 +88,18 @@ func gatewayServer() {
defer cancel()

mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := pb.RegisterHammerHandlerFromEndpoint(ctx, mux, grpcEndpoint, opts)
if err != nil {
zap.L().Error("gateway-http-server", zap.Error(err))
return
}

if err := http.ListenAndServe(httpEndpoint, mux); err != nil {
server := &http.Server{
Addr: httpEndpoint,
Handler: mux,
ReadHeaderTimeout: readHeaderTimeout,
}
if err := server.ListenAndServe(); err != nil {
zap.L().Error("gateway-http-server", zap.Error(err))
}
}
Expand All @@ -106,7 +112,12 @@ func metricsServer() {
port := env.GetInt("HAMMER_METRICS_PORT", 4001)
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(fmt.Sprintf(":%d", port), mux)
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: mux,
ReadHeaderTimeout: readHeaderTimeout,
}
err := server.ListenAndServe()
if err != nil {
zap.L().Error("metrics-server-failed-to-start", zap.Error(err))
}
Expand Down Expand Up @@ -134,7 +145,12 @@ func healthCheckServer() {
}
mux.HandleFunc("/liveness", handler)
mux.HandleFunc("/readiness", handler)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), mux)
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: mux,
ReadHeaderTimeout: readHeaderTimeout,
}
err := server.ListenAndServe()
if err != nil {
zap.L().Error("health-check-server-failed-to-start", zap.Error(err))
}
Expand Down Expand Up @@ -162,6 +178,9 @@ func init() {

// Set http endpoint
httpEndpoint = fmt.Sprintf(":%d", env.GetInt("HAMMER_HTTP_PORT", 8000))

// Set ReadHeaderTimeout
readHeaderTimeout = 60 * time.Second
}

func main() {
Expand Down
52 changes: 26 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
module github.com/allisson/hammer

go 1.17
go 1.19

require (
github.com/DATA-DOG/go-txdb v0.1.4
github.com/DATA-DOG/go-txdb v0.1.5
github.com/allisson/go-env v0.3.0
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/golang-migrate/migrate/v4 v4.15.1
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/huandu/go-sqlbuilder v1.13.0
github.com/jmoiron/sqlx v1.3.4
github.com/huandu/go-sqlbuilder v1.16.0
github.com/jmoiron/sqlx v1.3.5
github.com/joho/godotenv v1.4.0
github.com/lib/pq v1.10.4
github.com/oklog/ulid/v2 v2.0.2
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0
go.uber.org/zap v1.19.1
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
github.com/lib/pq v1.10.7
github.com/oklog/ulid/v2 v2.1.0
github.com/prometheus/client_golang v1.13.0
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.19.2
go.uber.org/zap v1.23.0
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458
google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e
google.golang.org/grpc v1.50.0
google.golang.org/protobuf v1.28.1
)

require (
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit fc197fa

Please sign in to comment.