From 4698cac99b08c810fc0ea82e8fb841ccb56790ac Mon Sep 17 00:00:00 2001 From: justin0u0 Date: Tue, 5 Mar 2024 11:54:35 +0800 Subject: [PATCH] ci: upgrade Go and some actions version --- .github/workflows/main.yml | 12 ++++++------ .golangci.yml | 10 +--------- cmd/comment/gateway.go | 4 +++- cmd/video/gateway.go | 4 +++- modules/video/dao/video.go | 7 ++++--- pkg/otelkit/prometheus.go | 1 + 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9c6db44..9b6d9e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,19 +11,19 @@ jobs: uses: actions/checkout@v3 - name: setup go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: '1.21' - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: - version: v1.44.2 + version: v1.55.2 # test should be run inside a container to start helper services (ex: mongo) test: - runs-on: ubuntu-20.04 - container: golang:1.17 + runs-on: ubuntu-22.04 + container: golang:1.21 services: mongo: image: mongo:5 diff --git a/.golangci.yml b/.golangci.yml index 3f7cbed..fb41e57 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,4 @@ linters-settings: - depguard: - list-type: blacklist - packages: - # logging is allowed only by logutils.Log, logrus - # is allowed to use only in logutils package - - github.com/sirupsen/logrus - packages-with-error-message: - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" dupl: threshold: 100 funlen: @@ -69,7 +61,6 @@ linters: enable: - bodyclose - deadcode - - depguard - dogsled - dupl - errcheck @@ -106,6 +97,7 @@ linters: # don't enable: # - asciicheck + # - depguard # - scopelint # - gochecknoglobals # - gocognit diff --git a/cmd/comment/gateway.go b/cmd/comment/gateway.go index 4840fcb..117caa8 100644 --- a/cmd/comment/gateway.go +++ b/cmd/comment/gateway.go @@ -5,6 +5,7 @@ import ( "log" "net" "net/http" + "time" "github.com/NTHU-LSALAB/NTHU-Distributed-System/modules/comment/pb" "github.com/NTHU-LSALAB/NTHU-Distributed-System/pkg/grpckit" @@ -72,7 +73,8 @@ func serveHTTP(lis net.Listener, conn *grpc.ClientConn, logger *logkit.Logger) r mux := runtime.NewServeMux() httpServer := &http.Server{ - Handler: mux, + Handler: mux, + ReadHeaderTimeout: 10 * time.Second, } return func(ctx context.Context) error { diff --git a/cmd/video/gateway.go b/cmd/video/gateway.go index 147f709..aff19b6 100644 --- a/cmd/video/gateway.go +++ b/cmd/video/gateway.go @@ -5,6 +5,7 @@ import ( "log" "net" "net/http" + "time" "github.com/NTHU-LSALAB/NTHU-Distributed-System/modules/video/gateway" "github.com/NTHU-LSALAB/NTHU-Distributed-System/modules/video/pb" @@ -80,7 +81,8 @@ func serveHTTP(lis net.Listener, conn *grpc.ClientConn, logger *logkit.Logger) r } httpServer := &http.Server{ - Handler: mux, + Handler: mux, + ReadHeaderTimeout: 10 * time.Second, } return func(ctx context.Context) error { diff --git a/modules/video/dao/video.go b/modules/video/dao/video.go index f692907..3cc7c17 100644 --- a/modules/video/dao/video.go +++ b/modules/video/dao/video.go @@ -77,6 +77,7 @@ func listVideoKey(limit, skip int64) string { // id that is useful for testing func NewFakeVideo() *Video { id := primitive.NewObjectID() + baseURL := "https://storage.example.com/videos/" + id.Hex() // Note that timestamp is hard to test equally, // so ignore the `createdAt` and `updatedAt` field @@ -87,11 +88,11 @@ func NewFakeVideo() *Video { Height: 600, Size: 144000, Duration: 10.234, - URL: "https://storage.example.com/videos/" + id.Hex() + ".mp4", + URL: baseURL + ".mp4", Status: VideoStatusSuccess, Variants: map[string]string{ - "1080p": "https://storage.example.com/videos/" + id.Hex() + "-1080p.mp4", - "720p": "https://storage.example.com/videos/" + id.Hex() + "-720p.mp4", + "1080p": baseURL + "-1080p.mp4", + "720p": baseURL + "-720p.mp4", }, } } diff --git a/pkg/otelkit/prometheus.go b/pkg/otelkit/prometheus.go index 8b9df3b..65e4985 100644 --- a/pkg/otelkit/prometheus.go +++ b/pkg/otelkit/prometheus.go @@ -139,6 +139,7 @@ func newPrometheusServer(exporter *prometheus.Exporter, conf *PrometheusServiceM http.NotFound(w, r) } }), + ReadHeaderTimeout: 10 * time.Second, } go func() {