Merge pull request 'updates' (#207) from updates into v3
Reviewed-on: #207
This commit is contained in:
commit
bcc06054f1
18
.gitea/ISSUE_TEMPLATE/bug_report.md
Normal file
18
.gitea/ISSUE_TEMPLATE/bug_report.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: For reporting bugs in micro
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
|
||||
1. What are you trying to do?
|
||||
2. What did you expect to happen?
|
||||
3. What happens instead?
|
||||
|
||||
**How to reproduce the bug:**
|
||||
|
||||
If possible, please include a minimal code snippet here.
|
17
.gitea/ISSUE_TEMPLATE/feature-request---enhancement.md
Normal file
17
.gitea/ISSUE_TEMPLATE/feature-request---enhancement.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request / Enhancement
|
||||
about: If you have a need not served by micro
|
||||
title: "[FEATURE]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
8
.gitea/ISSUE_TEMPLATE/question.md
Normal file
8
.gitea/ISSUE_TEMPLATE/question.md
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
name: Question
|
||||
about: Ask a question about micro
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
28
.gitea/autoapprove.yml
Normal file
28
.gitea/autoapprove.yml
Normal file
@ -0,0 +1,28 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
run: [ "curl -o tea https://dl.gitea.com/tea/main/tea-main-linux-amd64",
|
||||
"chmod +x ./tea",
|
||||
"./tea login add --name unistack --token ${{ secrets.GITHUB_TOKEN }} --url https://git.unistack.org",
|
||||
"./tea pr --repo ${{ github.event.repository.name }}"
|
||||
]
|
||||
if: github.actor == 'vtolstov'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
24
.gitea/workflows/lint.yml
Normal file
24
.gitea/workflows/lint.yml
Normal file
@ -0,0 +1,24 @@
|
||||
name: lint
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup-go
|
||||
uses: https://gitea.com/actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.18
|
||||
- name: checkout
|
||||
uses: https://gitea.com/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
|
23
.gitea/workflows/pr.yml
Normal file
23
.gitea/workflows/pr.yml
Normal file
@ -0,0 +1,23 @@
|
||||
name: pr
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: https://gitea.com/actions/checkout@v3
|
||||
- name: setup-go
|
||||
uses: https://gitea.com/actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.18
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
9
.github.old/PULL_REQUEST_TEMPLATE.md
Normal file
9
.github.old/PULL_REQUEST_TEMPLATE.md
Normal file
@ -0,0 +1,9 @@
|
||||
## Pull Request template
|
||||
Please, go through these steps before clicking submit on this PR.
|
||||
|
||||
1. Give a descriptive title to your PR.
|
||||
2. Provide a description of your changes.
|
||||
3. Make sure you have some relevant tests.
|
||||
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).
|
||||
|
||||
**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**
|
@ -37,11 +37,4 @@ jobs:
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
||||
version: v1.30
|
5
go.mod
5
go.mod
@ -1,10 +1,9 @@
|
||||
module go.unistack.org/micro/v3
|
||||
|
||||
go 1.16
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/imdario/mergo v0.3.13
|
||||
github.com/imdario/mergo v0.3.14
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
5
go.sum
5
go.sum
@ -1,10 +1,9 @@
|
||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||
github.com/imdario/mergo v0.3.14 h1:fOqeC1+nCuuk6PKQdg9YmosXX7Y7mHX6R/0ZldI9iHo=
|
||||
github.com/imdario/mergo v0.3.14/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35 h1:4mohWoM/UGg1BvFFiqSPRl5uwJY3rVV0HQX0ETqauqQ=
|
||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@ -211,6 +211,7 @@ func Stores(s ...store.Store) Option {
|
||||
}
|
||||
|
||||
// Logger set the logger to use
|
||||
//
|
||||
//nolint:gocyclo
|
||||
func Logger(l logger.Logger, opts ...LoggerOption) Option {
|
||||
return func(o *Options) error {
|
||||
@ -329,6 +330,7 @@ func Meters(m ...meter.Meter) Option {
|
||||
|
||||
// Register sets the register for the service
|
||||
// and the underlying components
|
||||
//
|
||||
//nolint:gocyclo
|
||||
func Register(r register.Register, opts ...RegisterOption) Option {
|
||||
return func(o *Options) error {
|
||||
@ -403,6 +405,7 @@ func RegisterBroker(n string) RegisterOption {
|
||||
}
|
||||
|
||||
// Tracer sets the tracer
|
||||
//
|
||||
//nolint:gocyclo
|
||||
func Tracer(t tracer.Tracer, opts ...TracerOption) Option {
|
||||
return func(o *Options) error {
|
||||
|
31
options/hooks.go
Normal file
31
options/hooks.go
Normal file
@ -0,0 +1,31 @@
|
||||
package options // import "go.unistack.org/micro/v3/options"
|
||||
|
||||
// Hook func interface
|
||||
type Hook interface{}
|
||||
|
||||
// Hooks func slice
|
||||
type Hooks []Hook
|
||||
|
||||
// Append is used to add hooks
|
||||
func (hs *Hooks) Append(h ...Hook) {
|
||||
*hs = append(*hs, h...)
|
||||
}
|
||||
|
||||
// Replace is used to set hooks
|
||||
func (hs *Hooks) Replace(h ...Hook) {
|
||||
*hs = h
|
||||
}
|
||||
|
||||
// EachNext is used to itearate over hooks forward
|
||||
func (hs *Hooks) EachNext(fn func(Hook)) {
|
||||
for idx := 0; idx < len(*hs); idx++ {
|
||||
fn((*hs)[idx])
|
||||
}
|
||||
}
|
||||
|
||||
// EachPrev is used to iterate over hooks backward
|
||||
func (hs *Hooks) EachPrev(fn func(Hook)) {
|
||||
for idx := len(*hs) - 1; idx >= 0; idx-- {
|
||||
fn((*hs)[idx])
|
||||
}
|
||||
}
|
65
options/hooks_test.go
Normal file
65
options/hooks_test.go
Normal file
@ -0,0 +1,65 @@
|
||||
package options
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHooks_Append(t *testing.T) {
|
||||
fn1 := func() {}
|
||||
fn2 := func() {}
|
||||
hs := &Hooks{}
|
||||
hs.Append(fn1, fn2)
|
||||
if len(*hs) != 2 {
|
||||
t.Fatalf("unexpected Append error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHooks_Replace(t *testing.T) {
|
||||
fn1 := func() {}
|
||||
fn2 := func() {}
|
||||
hs := &Hooks{}
|
||||
hs.Append(fn1, fn2, fn1)
|
||||
if len(*hs) != 3 {
|
||||
t.Fatalf("unexpected Append error")
|
||||
}
|
||||
hs.Replace(fn1, fn2)
|
||||
if len(*hs) != 2 {
|
||||
t.Fatalf("unexpected Replace error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHooks_EachNext(t *testing.T) {
|
||||
n := 5
|
||||
fn1 := func() {
|
||||
n *= 2
|
||||
}
|
||||
fn2 := func() {
|
||||
n -= 10
|
||||
}
|
||||
hs := &Hooks{}
|
||||
hs.Append(fn1, fn2)
|
||||
|
||||
hs.EachNext(func(h Hook) {
|
||||
h.(func())()
|
||||
})
|
||||
if n != 0 {
|
||||
t.Fatalf("unexpected EachNext")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHooks_EachPrev(t *testing.T) {
|
||||
n := 5
|
||||
fn1 := func() {
|
||||
n *= 2
|
||||
}
|
||||
fn2 := func() {
|
||||
n -= 10
|
||||
}
|
||||
hs := &Hooks{}
|
||||
hs.Append(fn2, fn1)
|
||||
|
||||
hs.EachPrev(func(h Hook) {
|
||||
h.(func())()
|
||||
})
|
||||
if n != 0 {
|
||||
t.Fatalf("unexpected EachPrev")
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import (
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/options"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
@ -83,6 +84,8 @@ type Options struct {
|
||||
MaxConn int
|
||||
// DeregisterAttempts holds the number of deregister attempts before error
|
||||
DeregisterAttempts int
|
||||
// Hooks may contains SubscriberWrapper, HandlerWrapper or Server func wrapper
|
||||
Hooks options.Hooks
|
||||
}
|
||||
|
||||
// NewOptions returns new options struct with default or passed values
|
||||
|
Loading…
x
Reference in New Issue
Block a user