diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..ab4f819 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,23 @@ +name: golangci-lint +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.22' + - run: make ffi-deps + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 + args: --timeout=10m diff --git a/Makefile b/Makefile index 00e72fd..e07e660 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ unexport GOFLAGS +GOFLAGS=-ldflags="-s -w" GO_BUILD_IMAGE?=golang:1.22.3 VERSION?=$(shell git describe --always --tag --dirty) docker_sanitized_version=$(shell echo ${VERSION} | sed 's:/:-:g') diff --git a/README-CN.md b/README-CN.md index 3f99472..6487a49 100644 --- a/README-CN.md +++ b/README-CN.md @@ -46,10 +46,10 @@ OPTIONS: 使用Docker运行服务: ```shell docker run -d --name extend \ - -p 8000:8000 - -e FULLNODE_API_INFO="lotus api info" - -v /path/to/extend:/app - gh-efforts/extend:latest run --listen 0.0.0.0:8000 --db /app/extend.db + -p 8000:8000 \ + -e FULLNODE_API_INFO="lotus api info" \ + -v /path/to/extend:/app \ + ghcr.io/strahe/extend:latest run --listen 0.0.0.0:8000 --db /app/extend.db ``` ### 开启鉴权 (可选) diff --git a/README.md b/README.md index f725496..221d24b 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,10 @@ Get help Run the service using Docker: ```shell docker run -d --name extend \ - -p 8000:8000 - -e FULLNODE_API_INFO="lotus api info" - -v /path/to/extend:/app - gh-efforts/extend:latest run --listen 0.0.0.0:8000 --db /app/extend.db + -p 8000:8000 \ + -e FULLNODE_API_INFO="lotus api info" \ + -v /path/to/extend:/app \ + ghcr.io/strahe/extend:latest run --listen 0.0.0.0:8000 --db /app/extend.db ``` ### Enable authentication (optional) diff --git a/auth.go b/auth.go index 16a102c..e034eb9 100644 --- a/auth.go +++ b/auth.go @@ -77,10 +77,8 @@ func authMiddleware(secret []byte) mux.MiddlewareFunc { return authHandler } -const ( - userCtxKey = "auth_user" -) +type userCtxKey struct{} func WithAuthUser(ctx context.Context, user string) context.Context { - return context.WithValue(ctx, userCtxKey, user) + return context.WithValue(ctx, userCtxKey{}, user) } diff --git a/cmd.go b/cmd.go index c22826e..bf38dbf 100644 --- a/cmd.go +++ b/cmd.go @@ -51,7 +51,7 @@ var authCreateTokenCmd = &cli.Command{ var d time.Duration if cctx.IsSet("expiry") { expiry := cctx.Timestamp("expiry") - d = expiry.Sub(time.Now()) + d = time.Until(*expiry) } token, err := authNew([]byte(cctx.String("secret")), @@ -212,11 +212,8 @@ func MonitorShutdown(handlers ...node.ShutdownHandler) <-chan struct{} { out := make(chan struct{}) go func() { - select { - case sig := <-sigCh: - log.Warnw("received shutdown", "signal", sig) - } - + sig := <-sigCh + log.Warnw("received shutdown", "signal", sig) log.Warn("Shutting down...") // Call all the handlers, logging on failure and success. diff --git a/model.go b/model.go index a1c8e3e..6235bca 100644 --- a/model.go +++ b/model.go @@ -18,10 +18,10 @@ type RequestStatus string const ( RequestStatusCreated RequestStatus = "created" - RequestStatusPending = "pending" - RequestStatusFailed = "failed" - RequestStatusPartfailed = "partfailed" - RequestStatusSuccess = "success" + RequestStatusPending RequestStatus = "pending" + RequestStatusFailed RequestStatus = "failed" + RequestStatusPartfailed RequestStatus = "partfailed" + RequestStatusSuccess RequestStatus = "success" ) // Request represents a request in the system. diff --git a/service.go b/service.go index 72d34f8..3796ed4 100644 --- a/service.go +++ b/service.go @@ -610,7 +610,7 @@ loopParams: return result, nil } // join errors as one error - return result, fmt.Errorf(strings.Join(errMsgs, ";\n")) + return result, fmt.Errorf("%s", strings.Join(errMsgs, ";\n")) } type extendResult struct {