diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 8da88945..1cc293dc 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -10,15 +10,15 @@ jobs: runs-on: ubuntu-latest steps: - name: setup-go - uses: https://gitea.com/actions/setup-go@v3 + uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.21 - name: checkout - uses: https://gitea.com/actions/checkout@v3 + uses: actions/checkout@v3 - name: deps run: go get -v -d ./... - name: lint uses: https://github.com/golangci/golangci-lint-action@v3.4.0 continue-on-error: true with: - version: v1.52 \ No newline at end of file + version: v1.52 diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index ba947f0c..b3e67b06 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -10,14 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout - uses: https://gitea.com/actions/checkout@v3 + uses: actions/checkout@v3 - name: setup-go - uses: https://gitea.com/actions/setup-go@v3 + uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.21 - name: deps run: go get -v -t -d ./... - name: test env: INTEGRATION_TESTS: yes - run: go test -mod readonly -v ./... \ No newline at end of file + run: go test -mod readonly -v ./... diff --git a/go.mod b/go.mod index 65e6a1f5..a16001cb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.unistack.org/micro/v3 -go 1.19 +go 1.20 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 diff --git a/server/options.go b/server/options.go index 8ab8c0d2..e6754992 100644 --- a/server/options.go +++ b/server/options.go @@ -86,6 +86,8 @@ type Options struct { DeregisterAttempts int // Hooks may contains SubscriberWrapper, HandlerWrapper or Server func wrapper Hooks options.Hooks + // GracefulTimeout timeout for graceful stop server + GracefulTimeout time.Duration } // NewOptions returns new options struct with default or passed values @@ -108,6 +110,7 @@ func NewOptions(opts ...Option) Options { Version: DefaultVersion, ID: id.Must(), Namespace: DefaultNamespace, + GracefulTimeout: DefaultGracefulTimeout, } for _, o := range opts { @@ -321,6 +324,14 @@ func Listener(l net.Listener) Option { // HandlerOption func type HandlerOption func(*HandlerOptions) +// GracefulTimeout duration +func GracefulTimeout(td time.Duration) Option { + return func(o *Options) { + o.GracefulTimeout = td + } +} + + // HandlerOptions struct type HandlerOptions struct { // Context holds external options diff --git a/server/server.go b/server/server.go index ef710d79..e38d06e8 100644 --- a/server/server.go +++ b/server/server.go @@ -34,6 +34,8 @@ var ( DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb // DefaultMaxMsgSendSize holds default max send size DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb + // DefaultGracefulTimeout default time for graceful stop + DefaultGracefulTimeout = 5 * time.Second ) // Server is a simple micro server abstraction