Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
734f751055 | |||
55d8a9ee20 | |||
07c93042ba | |||
b9bbfdf159 | |||
fbad257acc | |||
1829febb6e | |||
7838fa62a8 | |||
332803d8de | |||
11c868d476 | |||
38d6e482d7 | |||
07d4085201 | |||
45f30c0be3 | |||
bcaea675a7 | |||
3087ba1d73 | |||
3f5b19497c | |||
37d937d7ae | |||
7d68f2396e | |||
0854a7ea72 | |||
5eb0e56373 | |||
6af837fd25 | |||
ada59119cc | |||
8abc913b28 | |||
3247d144a8 | |||
7b2e3cc8aa | |||
8688179acd | |||
3e40bac5f4 | |||
e3fee6f8a6 | |||
15c020fac5 | |||
3bc046e5d4 | |||
542f36cfa5 | |||
8237e6a08e | |||
ecb60e4dc5 | |||
a1999ff81c | |||
d0f2bc8346 | |||
|
dd29bf457e | ||
d062c248e3 | |||
875f66d36e |
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@@ -3,6 +3,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
|
21
.github/workflows/codeql-analysis.yml
vendored
21
.github/workflows/codeql-analysis.yml
vendored
@@ -9,7 +9,7 @@
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
@@ -17,16 +17,16 @@ on:
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
@@ -42,11 +42,14 @@ jobs:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
@@ -57,7 +60,7 @@ jobs:
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
@@ -71,5 +74,5 @@ jobs:
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
75
.github/workflows/dependabot-automerge.yml
vendored
75
.github/workflows/dependabot-automerge.yml
vendored
@@ -1,66 +1,31 @@
|
||||
name: "prautomerge"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
Dependabot-Automerge:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR
|
||||
# The the github.event.workflow_run.event value is 'push' and not 'pull_request'
|
||||
# dont work with multiple workflows when last returns success
|
||||
if: >-
|
||||
github.event.workflow_run.conclusion == 'success'
|
||||
&& github.actor == 'dependabot[bot]'
|
||||
&& github.event.sender.login == 'dependabot[bot]'
|
||||
&& github.event.sender.type == 'Bot'
|
||||
&& (github.event.workflow_run.event == 'pull_request'
|
||||
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
||||
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||
steps:
|
||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
||||
uses: actions/github-script@v4
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.1.1
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
console.log(context.payload.workflow_run);
|
||||
|
||||
var labelNames = await github.paginate(
|
||||
github.issues.listLabelsOnIssue,
|
||||
{
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
issue_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
},
|
||||
(response) => response.data.map(
|
||||
(label) => label.name
|
||||
)
|
||||
);
|
||||
|
||||
console.log(labelNames);
|
||||
|
||||
if (labelNames.includes('dependencies')) {
|
||||
console.log('Found label');
|
||||
|
||||
await github.pulls.createReview({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
event: 'APPROVE'
|
||||
});
|
||||
console.log('Approved PR');
|
||||
|
||||
await github.pulls.merge({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
});
|
||||
|
||||
console.log('Merged PR');
|
||||
}
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: approve
|
||||
run: gh pr review --approve "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
- name: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
|
1
.github/workflows/pr.yml
vendored
1
.github/workflows/pr.yml
vendored
@@ -3,6 +3,7 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
|
@@ -30,7 +30,7 @@ linters:
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- golint
|
||||
- revive
|
||||
- gosec
|
||||
- makezero
|
||||
- misspell
|
||||
|
19
api/api.go
19
api/api.go
@@ -1,15 +1,16 @@
|
||||
package api
|
||||
package api // import "go.unistack.org/micro/v3/api"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
// nolint: revive
|
||||
// Api interface
|
||||
type Api interface {
|
||||
// Initialise options
|
||||
@@ -125,14 +126,14 @@ func Validate(e *Endpoint) error {
|
||||
ps := p[0]
|
||||
pe := p[len(p)-1]
|
||||
|
||||
if ps == '^' && pe == '$' {
|
||||
_, err := regexp.CompilePOSIX(p)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ps == '^' && pe == '$':
|
||||
if _, err := regexp.CompilePOSIX(p); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if ps == '^' && pe != '$' {
|
||||
case ps == '^' && pe != '$':
|
||||
return errors.New("invalid path")
|
||||
} else if ps != '^' && pe == '$' {
|
||||
case ps != '^' && pe == '$':
|
||||
return errors.New("invalid path")
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package handler provides http handlers
|
||||
package handler
|
||||
package handler // import "go.unistack.org/micro/v3/api/handler"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/api/router"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/api/router"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
// DefaultMaxRecvSize specifies max recv size for handler
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
|
||||
package grpc
|
||||
package grpc // import "go.unistack.org/micro/v3/api/resolver/grpc"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
)
|
||||
|
||||
// Resolver struct
|
||||
|
@@ -1,10 +1,10 @@
|
||||
// Package host resolves using http host
|
||||
package host
|
||||
package host // import "go.unistack.org/micro/v3/api/resolver/host"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
)
|
||||
|
||||
type hostResolver struct {
|
||||
|
@@ -3,7 +3,7 @@ package resolver
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
)
|
||||
|
||||
// Options struct
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package path resolves using http path
|
||||
package path
|
||||
package path // import "go.unistack.org/micro/v3/api/resolver/path"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
)
|
||||
|
||||
// Resolver the path resolver
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package resolver resolves a http request to an endpoint
|
||||
package resolver
|
||||
package resolver // import "go.unistack.org/micro/v3/api/resolver"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@@ -1,14 +1,14 @@
|
||||
// Package subdomain is a resolver which uses the subdomain to determine the domain to route to. It
|
||||
// offloads the endpoint resolution to a child resolver which is provided in New.
|
||||
package subdomain
|
||||
package subdomain // import "go.unistack.org/micro/v3/api/resolver/subdomain"
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver/vpath"
|
||||
"go.unistack.org/micro/v3/api/resolver/vpath"
|
||||
)
|
||||
|
||||
func TestResolve(t *testing.T) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package vpath resolves using http path and recognised versioned urls
|
||||
package vpath
|
||||
package vpath // import "go.unistack.org/micro/v3/api/resolver/vpath"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
)
|
||||
|
||||
// NewResolver creates new vpath api resolver
|
||||
|
@@ -3,10 +3,10 @@ package router
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api/resolver"
|
||||
"github.com/unistack-org/micro/v3/api/resolver/vpath"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/api/resolver"
|
||||
"go.unistack.org/micro/v3/api/resolver/vpath"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
)
|
||||
|
||||
// Options holds the options for api router
|
||||
|
@@ -1,10 +1,10 @@
|
||||
// Package router provides api service routing
|
||||
package router
|
||||
package router // import "go.unistack.org/micro/v3/api/router"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/unistack-org/micro/v3/api"
|
||||
"go.unistack.org/micro/v3/api"
|
||||
)
|
||||
|
||||
// DefaultRouter contains default router implementation
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Package auth provides authentication and authorization capability
|
||||
package auth
|
||||
package auth // import "go.unistack.org/micro/v3/auth"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
type noopAuth struct {
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// NewOptions creates Options struct from slice of options
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package broker is an interface used for asynchronous messaging
|
||||
package broker
|
||||
package broker // import "go.unistack.org/micro/v3/broker"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// DefaultBroker default memory broker
|
||||
|
176
broker/memory.go
176
broker/memory.go
@@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
maddr "github.com/unistack-org/micro/v3/util/addr"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
mnet "github.com/unistack-org/micro/v3/util/net"
|
||||
"github.com/unistack-org/micro/v3/util/rand"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
maddr "go.unistack.org/micro/v3/util/addr"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
mnet "go.unistack.org/micro/v3/util/net"
|
||||
"go.unistack.org/micro/v3/util/rand"
|
||||
)
|
||||
|
||||
type memoryBroker struct {
|
||||
@@ -89,36 +89,15 @@ func (m *memoryBroker) Init(opts ...Option) error {
|
||||
}
|
||||
|
||||
func (m *memoryBroker) Publish(ctx context.Context, topic string, msg *Message, opts ...PublishOption) error {
|
||||
m.RLock()
|
||||
if !m.connected {
|
||||
m.RUnlock()
|
||||
return ErrNotConnected
|
||||
}
|
||||
m.RUnlock()
|
||||
|
||||
options := NewPublishOptions(opts...)
|
||||
vs := make([]msgWrapper, 0, 1)
|
||||
if m.opts.Codec == nil || options.BodyOnly {
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
vs = append(vs, msgWrapper{topic: topic, body: msg})
|
||||
} else {
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
buf, err := m.opts.Codec.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vs = append(vs, msgWrapper{topic: topic, body: buf})
|
||||
}
|
||||
|
||||
return m.publish(ctx, vs, opts...)
|
||||
}
|
||||
|
||||
type msgWrapper struct {
|
||||
topic string
|
||||
body interface{}
|
||||
msg.Header.Set(metadata.HeaderTopic, topic)
|
||||
return m.publish(ctx, []*Message{msg}, opts...)
|
||||
}
|
||||
|
||||
func (m *memoryBroker) BatchPublish(ctx context.Context, msgs []*Message, opts ...PublishOption) error {
|
||||
return m.publish(ctx, msgs, opts...)
|
||||
}
|
||||
|
||||
func (m *memoryBroker) publish(ctx context.Context, msgs []*Message, opts ...PublishOption) error {
|
||||
m.RLock()
|
||||
if !m.connected {
|
||||
m.RUnlock()
|
||||
@@ -126,88 +105,81 @@ func (m *memoryBroker) BatchPublish(ctx context.Context, msgs []*Message, opts .
|
||||
}
|
||||
m.RUnlock()
|
||||
|
||||
options := NewPublishOptions(opts...)
|
||||
vs := make([]msgWrapper, 0, len(msgs))
|
||||
if m.opts.Codec == nil || options.BodyOnly {
|
||||
for _, msg := range msgs {
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
vs = append(vs, msgWrapper{topic: topic, body: msg})
|
||||
}
|
||||
} else {
|
||||
for _, msg := range msgs {
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
buf, err := m.opts.Codec.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vs = append(vs, msgWrapper{topic: topic, body: buf})
|
||||
}
|
||||
}
|
||||
|
||||
return m.publish(ctx, vs, opts...)
|
||||
}
|
||||
|
||||
func (m *memoryBroker) publish(ctx context.Context, vs []msgWrapper, opts ...PublishOption) error {
|
||||
var err error
|
||||
|
||||
msgTopicMap := make(map[string]Events)
|
||||
for _, v := range vs {
|
||||
p := &memoryEvent{
|
||||
topic: v.topic,
|
||||
message: v.body,
|
||||
opts: m.opts,
|
||||
}
|
||||
msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
options := NewPublishOptions(opts...)
|
||||
|
||||
beh := m.opts.BatchErrorHandler
|
||||
eh := m.opts.ErrorHandler
|
||||
msgTopicMap := make(map[string]Events)
|
||||
for _, v := range msgs {
|
||||
p := &memoryEvent{opts: m.opts}
|
||||
|
||||
for t, ms := range msgTopicMap {
|
||||
m.RLock()
|
||||
subs, ok := m.subscribers[t]
|
||||
m.RUnlock()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, sub := range subs {
|
||||
// batch processing
|
||||
if sub.batchhandler != nil {
|
||||
if err = sub.batchhandler(ms); err != nil {
|
||||
ms.SetError(err)
|
||||
if sub.opts.BatchErrorHandler != nil {
|
||||
beh = sub.opts.BatchErrorHandler
|
||||
}
|
||||
if beh != nil {
|
||||
beh(ms)
|
||||
} else if m.opts.Logger.V(logger.ErrorLevel) {
|
||||
m.opts.Logger.Error(m.opts.Context, err.Error())
|
||||
}
|
||||
} else if sub.opts.AutoAck {
|
||||
if err = ms.Ack(); err != nil {
|
||||
m.opts.Logger.Errorf(m.opts.Context, "ack failed: %v", err)
|
||||
}
|
||||
if m.opts.Codec == nil || options.BodyOnly {
|
||||
p.topic, _ = v.Header.Get(metadata.HeaderTopic)
|
||||
p.message = v.Body
|
||||
} else {
|
||||
p.topic, _ = v.Header.Get(metadata.HeaderTopic)
|
||||
p.message, err = m.opts.Codec.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// single processing
|
||||
if sub.handler != nil {
|
||||
for _, p := range ms {
|
||||
if err = sub.handler(p); err != nil {
|
||||
p.SetError(err)
|
||||
if sub.opts.ErrorHandler != nil {
|
||||
eh = sub.opts.ErrorHandler
|
||||
}
|
||||
if eh != nil {
|
||||
eh(p)
|
||||
msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p)
|
||||
}
|
||||
|
||||
beh := m.opts.BatchErrorHandler
|
||||
eh := m.opts.ErrorHandler
|
||||
|
||||
for t, ms := range msgTopicMap {
|
||||
m.RLock()
|
||||
subs, ok := m.subscribers[t]
|
||||
m.RUnlock()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, sub := range subs {
|
||||
if sub.opts.BatchErrorHandler != nil {
|
||||
beh = sub.opts.BatchErrorHandler
|
||||
}
|
||||
if sub.opts.ErrorHandler != nil {
|
||||
eh = sub.opts.ErrorHandler
|
||||
}
|
||||
|
||||
switch {
|
||||
// batch processing
|
||||
case sub.batchhandler != nil:
|
||||
if err = sub.batchhandler(ms); err != nil {
|
||||
ms.SetError(err)
|
||||
if beh != nil {
|
||||
_ = beh(ms)
|
||||
} else if m.opts.Logger.V(logger.ErrorLevel) {
|
||||
m.opts.Logger.Error(m.opts.Context, err.Error())
|
||||
}
|
||||
} else if sub.opts.AutoAck {
|
||||
if err = p.Ack(); err != nil {
|
||||
if err = ms.Ack(); err != nil {
|
||||
m.opts.Logger.Errorf(m.opts.Context, "ack failed: %v", err)
|
||||
}
|
||||
}
|
||||
// single processing
|
||||
case sub.handler != nil:
|
||||
for _, p := range ms {
|
||||
if err = sub.handler(p); err != nil {
|
||||
p.SetError(err)
|
||||
if eh != nil {
|
||||
_ = eh(p)
|
||||
} else if m.opts.Logger.V(logger.ErrorLevel) {
|
||||
m.opts.Logger.Error(m.opts.Context, err.Error())
|
||||
}
|
||||
} else if sub.opts.AutoAck {
|
||||
if err = p.Ack(); err != nil {
|
||||
m.opts.Logger.Errorf(m.opts.Context, "ack failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
func TestMemoryBatchBroker(t *testing.T) {
|
||||
@@ -28,7 +28,7 @@ func TestMemoryBatchBroker(t *testing.T) {
|
||||
t.Fatalf("Unexpected error subscribing %v", err)
|
||||
}
|
||||
|
||||
msgs := make([]*Message, 0, 0)
|
||||
msgs := make([]*Message, 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
message := &Message{
|
||||
Header: map[string]string{
|
||||
@@ -53,6 +53,7 @@ func TestMemoryBatchBroker(t *testing.T) {
|
||||
t.Fatalf("Unexpected connect error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryBroker(t *testing.T) {
|
||||
b := NewBroker()
|
||||
ctx := context.Background()
|
||||
@@ -73,7 +74,7 @@ func TestMemoryBroker(t *testing.T) {
|
||||
t.Fatalf("Unexpected error subscribing %v", err)
|
||||
}
|
||||
|
||||
msgs := make([]*Message, 0, 0)
|
||||
msgs := make([]*Message, 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
message := &Message{
|
||||
Header: map[string]string{
|
||||
|
@@ -5,11 +5,11 @@ import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options struct
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package build is for building source into a package
|
||||
package build
|
||||
package build // import "go.unistack.org/micro/v3/build"
|
||||
|
||||
// Build is an interface for building packages
|
||||
type Build interface {
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/util/backoff"
|
||||
"go.unistack.org/micro/v3/util/backoff"
|
||||
)
|
||||
|
||||
// BackoffFunc is the backoff call func
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Package client is an interface for an RPC client
|
||||
package client
|
||||
package client // import "go.unistack.org/micro/v3/client"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
)
|
||||
|
||||
// LookupFunc is used to lookup routes for a service
|
||||
|
@@ -3,10 +3,10 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// DefaultCodecs will be used to encode/decode data
|
||||
|
@@ -5,20 +5,22 @@ import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/selector"
|
||||
"github.com/unistack-org/micro/v3/selector/random"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/selector"
|
||||
"go.unistack.org/micro/v3/selector/random"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options holds client options
|
||||
type Options struct {
|
||||
// Transport used for transfer messages
|
||||
Transport transport.Transport
|
||||
// Selector used to select needed address
|
||||
Selector selector.Selector
|
||||
// Logger used to log messages
|
||||
@@ -29,18 +31,16 @@ type Options struct {
|
||||
Broker broker.Broker
|
||||
// Meter used for metrics
|
||||
Meter meter.Meter
|
||||
// Router used to get route
|
||||
Router router.Router
|
||||
// Transport used for transfer messages
|
||||
Transport transport.Transport
|
||||
// Context is used for external options
|
||||
Context context.Context
|
||||
// Lookup func used to get destination addr
|
||||
Lookup LookupFunc
|
||||
// Codecs map
|
||||
Codecs map[string]codec.Codec
|
||||
// Router used to get route
|
||||
Router router.Router
|
||||
// TLSConfig specifies tls.Config for secure connection
|
||||
TLSConfig *tls.Config
|
||||
// Codecs map
|
||||
Codecs map[string]codec.Codec
|
||||
// Lookup func used to get destination addr
|
||||
Lookup LookupFunc
|
||||
// Proxy is used for proxy requests
|
||||
Proxy string
|
||||
// ContentType is used to select codec
|
||||
@@ -68,12 +68,12 @@ func NewCallOptions(opts ...CallOption) CallOptions {
|
||||
|
||||
// CallOptions holds client call options
|
||||
type CallOptions struct {
|
||||
// Router used for route
|
||||
Router router.Router
|
||||
// Selector selects addr
|
||||
Selector selector.Selector
|
||||
// Context used for deadline
|
||||
Context context.Context
|
||||
// Router used for route
|
||||
Router router.Router
|
||||
// Retry func used for retries
|
||||
Retry RetryFunc
|
||||
// Backoff func used for backoff when retry
|
||||
@@ -82,22 +82,22 @@ type CallOptions struct {
|
||||
Network string
|
||||
// Content-Type
|
||||
ContentType string
|
||||
// CallWrappers call wrappers
|
||||
CallWrappers []CallWrapper
|
||||
// SelectOptions selector options
|
||||
SelectOptions []selector.SelectOption
|
||||
// AuthToken string
|
||||
AuthToken string
|
||||
// Address specifies static addr list
|
||||
Address []string
|
||||
// Retries specifies retries num
|
||||
Retries int
|
||||
// SelectOptions selector options
|
||||
SelectOptions []selector.SelectOption
|
||||
// CallWrappers call wrappers
|
||||
CallWrappers []CallWrapper
|
||||
// StreamTimeout stream timeout
|
||||
StreamTimeout time.Duration
|
||||
// RequestTimeout request timeout
|
||||
RequestTimeout time.Duration
|
||||
// DialTimeout dial timeout
|
||||
DialTimeout time.Duration
|
||||
// AuthToken string
|
||||
AuthToken string
|
||||
// Retries specifies retries num
|
||||
Retries int
|
||||
}
|
||||
|
||||
// Context pass context to client
|
||||
@@ -118,12 +118,12 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions {
|
||||
|
||||
// PublishOptions holds publish options
|
||||
type PublishOptions struct {
|
||||
// BodyOnly will publish only message body
|
||||
BodyOnly bool
|
||||
// Context used for external options
|
||||
Context context.Context
|
||||
// Exchange topic exchange name
|
||||
Exchange string
|
||||
// BodyOnly will publish only message body
|
||||
BodyOnly bool
|
||||
}
|
||||
|
||||
// NewMessageOptions creates message options struct
|
||||
@@ -267,7 +267,7 @@ func Transport(t transport.Transport) Option {
|
||||
func Register(r register.Register) Option {
|
||||
return func(o *Options) {
|
||||
if o.Router != nil {
|
||||
o.Router.Init(router.Register(r))
|
||||
_ = o.Router.Init(router.Register(r))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func TLSConfig(t *tls.Config) Option {
|
||||
// already set. Required for Init call below.
|
||||
|
||||
// set the transport tls
|
||||
o.Transport.Init(
|
||||
_ = o.Transport.Init(
|
||||
transport.TLSConfig(t),
|
||||
)
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
)
|
||||
|
||||
// RetryFunc that returning either false or a non-nil error will result in the call not being retried
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
)
|
||||
|
||||
type testRequest struct {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package codec is an interface for encoding messages
|
||||
package codec
|
||||
package codec // import "go.unistack.org/micro/v3/codec"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// Message types
|
||||
@@ -25,7 +25,7 @@ var (
|
||||
|
||||
var (
|
||||
// DefaultMaxMsgSize specifies how much data codec can handle
|
||||
DefaultMaxMsgSize int = 1024 * 1024 * 4 // 4Mb
|
||||
DefaultMaxMsgSize = 1024 * 1024 * 4 // 4Mb
|
||||
// DefaultCodec is the global default codec
|
||||
DefaultCodec Codec = NewCodec()
|
||||
// DefaultTagName specifies struct tag name to control codec Marshal/Unmarshal
|
||||
@@ -58,7 +58,7 @@ type Message struct {
|
||||
Method string
|
||||
Endpoint string
|
||||
Error string
|
||||
Id string
|
||||
ID string
|
||||
Body []byte
|
||||
Type MessageType
|
||||
}
|
||||
@@ -67,3 +67,20 @@ type Message struct {
|
||||
func NewMessage(t MessageType) *Message {
|
||||
return &Message{Type: t, Header: metadata.New(0)}
|
||||
}
|
||||
|
||||
// MarshalAppend calls codec.Marshal(v) and returns the data appended to buf.
|
||||
// If codec implements MarshalAppend, that is called instead.
|
||||
func MarshalAppend(buf []byte, c Codec, v interface{}, opts ...Option) ([]byte, error) {
|
||||
if nc, ok := c.(interface {
|
||||
MarshalAppend([]byte, interface{}, ...Option) ([]byte, error)
|
||||
}); ok {
|
||||
return nc.MarshalAppend(buf, v, opts...)
|
||||
}
|
||||
|
||||
mbuf, err := c.Marshal(v, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return append(buf, mbuf...), nil
|
||||
}
|
||||
|
@@ -4,3 +4,31 @@ package codec
|
||||
type Frame struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func (m *Frame) MarshalJSON() ([]byte, error) {
|
||||
return m.Data, nil
|
||||
}
|
||||
|
||||
func (m *Frame) UnmarshalJSON(data []byte) error {
|
||||
m.Data = data
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Frame) ProtoMessage() {}
|
||||
|
||||
func (m *Frame) Reset() {
|
||||
*m = Frame{}
|
||||
}
|
||||
|
||||
func (m *Frame) String() string {
|
||||
return string(m.Data)
|
||||
}
|
||||
|
||||
func (m *Frame) Marshal() ([]byte, error) {
|
||||
return m.Data, nil
|
||||
}
|
||||
|
||||
func (m *Frame) Unmarshal(data []byte) error {
|
||||
m.Data = data
|
||||
return nil
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ syntax = "proto3";
|
||||
package micro.codec;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option go_package = "github.com/unistack-org/micro/v3/codec;codec";
|
||||
option go_package = "go.unistack.org/micro/v3/codec;codec";
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "MicroCodec";
|
||||
option java_package = "micro.codec";
|
||||
|
@@ -3,9 +3,9 @@ package codec
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Option func
|
||||
@@ -19,12 +19,12 @@ type Options struct {
|
||||
Logger logger.Logger
|
||||
// Tracer used for tracing
|
||||
Tracer tracer.Tracer
|
||||
// MaxMsgSize specifies max messages size that reads by codec
|
||||
MaxMsgSize int
|
||||
// TagName specifies tag name in struct to control codec
|
||||
TagName string
|
||||
// Context stores additional codec options
|
||||
Context context.Context
|
||||
// TagName specifies tag name in struct to control codec
|
||||
TagName string
|
||||
// MaxMsgSize specifies max messages size that reads by codec
|
||||
MaxMsgSize int
|
||||
}
|
||||
|
||||
// MaxMsgSize sets the max message size
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package config is an interface for dynamic configuration.
|
||||
package config
|
||||
package config // import "go.unistack.org/micro/v3/config"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -13,7 +13,7 @@ var DefaultConfig Config = NewConfig()
|
||||
// DefaultWatcherMinInterval default min interval for poll changes
|
||||
var DefaultWatcherMinInterval = 5 * time.Second
|
||||
|
||||
// DefaultWatcherMinInterval default max interval for poll changes
|
||||
// DefaultWatcherMaxInterval default max interval for poll changes
|
||||
var DefaultWatcherMaxInterval = 9 * time.Second
|
||||
|
||||
var (
|
||||
@@ -64,3 +64,53 @@ func Load(ctx context.Context, cs []Config, opts ...LoadOption) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultAfterLoad = func(ctx context.Context, c Config) error {
|
||||
for _, fn := range c.Options().AfterLoad {
|
||||
if err := fn(ctx, c); err != nil {
|
||||
c.Options().Logger.Errorf(ctx, "%s AfterLoad err: %v", c.String(), err)
|
||||
if !c.Options().AllowFail {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
DefaultAfterSave = func(ctx context.Context, c Config) error {
|
||||
for _, fn := range c.Options().AfterSave {
|
||||
if err := fn(ctx, c); err != nil {
|
||||
c.Options().Logger.Errorf(ctx, "%s AfterSave err: %v", c.String(), err)
|
||||
if !c.Options().AllowFail {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
DefaultBeforeLoad = func(ctx context.Context, c Config) error {
|
||||
for _, fn := range c.Options().BeforeLoad {
|
||||
if err := fn(ctx, c); err != nil {
|
||||
c.Options().Logger.Errorf(ctx, "%s BeforeLoad err: %v", c.String(), err)
|
||||
if !c.Options().AllowFail {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
DefaultBeforeSave = func(ctx context.Context, c Config) error {
|
||||
for _, fn := range c.Options().BeforeSave {
|
||||
if err := fn(ctx, c); err != nil {
|
||||
c.Options().Logger.Errorf(ctx, "%s BeforeSavec err: %v", c.String(), err)
|
||||
if !c.Options().AllowFail {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
)
|
||||
|
@@ -32,3 +32,33 @@ func SetOption(k, v interface{}) Option {
|
||||
o.Context = context.WithValue(o.Context, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// SetSaveOption returns a function to setup a context with given value
|
||||
func SetSaveOption(k, v interface{}) SaveOption {
|
||||
return func(o *SaveOptions) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// SetLoadOption returns a function to setup a context with given value
|
||||
func SetLoadOption(k, v interface{}) LoadOption {
|
||||
return func(o *LoadOptions) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// SetWatchOption returns a function to setup a context with given value
|
||||
func SetWatchOption(k, v interface{}) WatchOption {
|
||||
return func(o *WatchOptions) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, k, v)
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||
)
|
||||
|
||||
type defaultConfig struct {
|
||||
@@ -27,10 +27,8 @@ func (c *defaultConfig) Init(opts ...Option) error {
|
||||
}
|
||||
|
||||
func (c *defaultConfig) Load(ctx context.Context, opts ...LoadOption) error {
|
||||
for _, fn := range c.opts.BeforeLoad {
|
||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
if err := DefaultBeforeLoad(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := NewLoadOptions(opts...)
|
||||
@@ -48,20 +46,26 @@ func (c *defaultConfig) Load(ctx context.Context, opts ...LoadOption) error {
|
||||
}
|
||||
|
||||
src, err := rutil.Zero(dst)
|
||||
if err == nil {
|
||||
if err = fillValues(reflect.ValueOf(src), c.opts.StructTag); err == nil {
|
||||
err = mergo.Merge(dst, src, mopts...)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fn := range c.opts.AfterLoad {
|
||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
if err != nil {
|
||||
if !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
return DefaultAfterLoad(ctx, c)
|
||||
}
|
||||
|
||||
if err = fillValues(reflect.ValueOf(src), c.opts.StructTag); err == nil {
|
||||
err = mergo.Merge(dst, src, mopts...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.opts.Logger.Errorf(ctx, "default load error: %v", err)
|
||||
if !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := DefaultAfterLoad(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -247,16 +251,12 @@ func fillValues(valueOf reflect.Value, tname string) error {
|
||||
}
|
||||
|
||||
func (c *defaultConfig) Save(ctx context.Context, opts ...SaveOption) error {
|
||||
for _, fn := range c.opts.BeforeSave {
|
||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
if err := DefaultBeforeSave(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fn := range c.opts.AfterSave {
|
||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
if err := DefaultAfterSave(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/unistack-org/micro/v3/config"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
@@ -48,5 +48,5 @@ func TestDefault(t *testing.T) {
|
||||
t.Fatal("AfterLoad option not working")
|
||||
}
|
||||
_ = conf
|
||||
//t.Logf("%#+v\n", conf)
|
||||
// t.Logf("%#+v\n", conf)
|
||||
}
|
||||
|
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options hold the config options
|
||||
@@ -66,6 +66,7 @@ type LoadOptions struct {
|
||||
Struct interface{}
|
||||
Override bool
|
||||
Append bool
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
func NewLoadOptions(opts ...LoadOption) LoadOptions {
|
||||
@@ -102,7 +103,8 @@ type SaveOption func(o *SaveOptions)
|
||||
|
||||
// SaveOptions struct
|
||||
type SaveOptions struct {
|
||||
Struct interface{}
|
||||
Struct interface{}
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// SaveStruct override struct for save to config
|
||||
@@ -209,14 +211,14 @@ func Name(n string) Option {
|
||||
type WatchOptions struct {
|
||||
// Context used by non default options
|
||||
Context context.Context
|
||||
// Coalesce multiple events to one
|
||||
Coalesce bool
|
||||
// Struct for filling
|
||||
Struct interface{}
|
||||
// MinInterval specifies the min time.Duration interval for poll changes
|
||||
MinInterval time.Duration
|
||||
// MaxInterval specifies the max time.Duration interval for poll changes
|
||||
MaxInterval time.Duration
|
||||
// Struct for filling
|
||||
Struct interface{}
|
||||
// Coalesce multiple events to one
|
||||
Coalesce bool
|
||||
}
|
||||
|
||||
type WatchOption func(*WatchOptions)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// Package errors provides a way to return detailed information
|
||||
// for an RPC request error. The error is normally JSON encoded.
|
||||
package errors
|
||||
package errors // import "go.unistack.org/micro/v3/errors"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -37,8 +37,8 @@ var (
|
||||
|
||||
// Error type
|
||||
type Error struct {
|
||||
// Id holds error id or service, usually someting like my_service or id
|
||||
Id string
|
||||
// ID holds error id or service, usually someting like my_service or id
|
||||
ID string
|
||||
// Detail holds some useful details about error
|
||||
Detail string
|
||||
// Status usually holds text of http status
|
||||
@@ -56,7 +56,7 @@ func (e *Error) Error() string {
|
||||
// New generates a custom error
|
||||
func New(id, detail string, code int32) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: code,
|
||||
Detail: detail,
|
||||
Status: http.StatusText(int(code)),
|
||||
@@ -77,7 +77,7 @@ func Parse(err string) *Error {
|
||||
// BadRequest generates a 400 error.
|
||||
func BadRequest(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 400,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(400),
|
||||
@@ -87,7 +87,7 @@ func BadRequest(id, format string, a ...interface{}) error {
|
||||
// Unauthorized generates a 401 error.
|
||||
func Unauthorized(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 401,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(401),
|
||||
@@ -97,7 +97,7 @@ func Unauthorized(id, format string, a ...interface{}) error {
|
||||
// Forbidden generates a 403 error.
|
||||
func Forbidden(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 403,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(403),
|
||||
@@ -107,7 +107,7 @@ func Forbidden(id, format string, a ...interface{}) error {
|
||||
// NotFound generates a 404 error.
|
||||
func NotFound(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 404,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(404),
|
||||
@@ -117,7 +117,7 @@ func NotFound(id, format string, a ...interface{}) error {
|
||||
// MethodNotAllowed generates a 405 error.
|
||||
func MethodNotAllowed(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 405,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(405),
|
||||
@@ -127,7 +127,7 @@ func MethodNotAllowed(id, format string, a ...interface{}) error {
|
||||
// Timeout generates a 408 error.
|
||||
func Timeout(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 408,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(408),
|
||||
@@ -137,7 +137,7 @@ func Timeout(id, format string, a ...interface{}) error {
|
||||
// Conflict generates a 409 error.
|
||||
func Conflict(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 409,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(409),
|
||||
@@ -147,7 +147,7 @@ func Conflict(id, format string, a ...interface{}) error {
|
||||
// InternalServerError generates a 500 error.
|
||||
func InternalServerError(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 500,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(500),
|
||||
@@ -157,7 +157,7 @@ func InternalServerError(id, format string, a ...interface{}) error {
|
||||
// NotImplemented generates a 501 error
|
||||
func NotImplemented(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 501,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(501),
|
||||
@@ -167,7 +167,7 @@ func NotImplemented(id, format string, a ...interface{}) error {
|
||||
// BadGateway generates a 502 error
|
||||
func BadGateway(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 502,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(502),
|
||||
@@ -177,7 +177,7 @@ func BadGateway(id, format string, a ...interface{}) error {
|
||||
// ServiceUnavailable generates a 503 error
|
||||
func ServiceUnavailable(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 503,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(503),
|
||||
@@ -187,7 +187,7 @@ func ServiceUnavailable(id, format string, a ...interface{}) error {
|
||||
// GatewayTimeout generates a 504 error
|
||||
func GatewayTimeout(id, format string, a ...interface{}) error {
|
||||
return &Error{
|
||||
Id: id,
|
||||
ID: id,
|
||||
Code: 504,
|
||||
Detail: fmt.Sprintf(format, a...),
|
||||
Status: http.StatusText(504),
|
||||
|
@@ -9,12 +9,12 @@ import (
|
||||
func TestFromError(t *testing.T) {
|
||||
err := NotFound("go.micro.test", "%s", "example")
|
||||
merr := FromError(err)
|
||||
if merr.Id != "go.micro.test" || merr.Code != 404 {
|
||||
if merr.ID != "go.micro.test" || merr.Code != 404 {
|
||||
t.Fatalf("invalid conversation %v != %v", err, merr)
|
||||
}
|
||||
err = er.New(err.Error())
|
||||
merr = FromError(err)
|
||||
if merr.Id != "go.micro.test" || merr.Code != 404 {
|
||||
if merr.ID != "go.micro.test" || merr.Code != 404 {
|
||||
t.Fatalf("invalid conversation %v != %v", err, merr)
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func TestEqual(t *testing.T) {
|
||||
func TestErrors(t *testing.T) {
|
||||
testData := []*Error{
|
||||
{
|
||||
Id: "test",
|
||||
ID: "test",
|
||||
Code: 500,
|
||||
Detail: "Internal server error",
|
||||
Status: http.StatusText(500),
|
||||
@@ -44,7 +44,7 @@ func TestErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, e := range testData {
|
||||
ne := New(e.Id, e.Detail, e.Code)
|
||||
ne := New(e.ID, e.Detail, e.Code)
|
||||
|
||||
if e.Error() != ne.Error() {
|
||||
t.Fatalf("Expected %s got %s", e.Error(), ne.Error())
|
||||
@@ -56,8 +56,8 @@ func TestErrors(t *testing.T) {
|
||||
t.Fatalf("Expected error got nil %v", pe)
|
||||
}
|
||||
|
||||
if pe.Id != e.Id {
|
||||
t.Fatalf("Expected %s got %s", e.Id, pe.Id)
|
||||
if pe.ID != e.ID {
|
||||
t.Fatalf("Expected %s got %s", e.ID, pe.ID)
|
||||
}
|
||||
|
||||
if pe.Detail != e.Detail {
|
||||
|
2
event.go
2
event.go
@@ -3,7 +3,7 @@ package micro
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
)
|
||||
|
||||
// Event is used to publish messages to a topic
|
||||
|
@@ -7,12 +7,12 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/silas/dag"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
type microFlow struct {
|
||||
@@ -20,13 +20,13 @@ type microFlow struct {
|
||||
}
|
||||
|
||||
type microWorkflow struct {
|
||||
id string
|
||||
g *dag.AcyclicGraph
|
||||
init bool
|
||||
sync.RWMutex
|
||||
opts Options
|
||||
g *dag.AcyclicGraph
|
||||
steps map[string]Step
|
||||
id string
|
||||
status Status
|
||||
sync.RWMutex
|
||||
init bool
|
||||
}
|
||||
|
||||
func (w *microWorkflow) ID() string {
|
||||
@@ -241,6 +241,7 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
w.opts.Logger.Tracef(nctx, "will be executed %v", steps[idx][nidx])
|
||||
}
|
||||
cstep := steps[idx][nidx]
|
||||
// nolint: nestif
|
||||
if len(cstep.Requires()) == 0 {
|
||||
wg.Add(1)
|
||||
go func(step Step) {
|
||||
@@ -264,17 +265,16 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
}
|
||||
cherr <- serr
|
||||
return
|
||||
} else {
|
||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "rsp"), rsp); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "rsp"), rsp); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
}(cstep)
|
||||
wg.Wait()
|
||||
@@ -298,16 +298,15 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
}
|
||||
cherr <- serr
|
||||
return
|
||||
} else {
|
||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "rsp"), rsp); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "rsp"), rsp); werr != nil {
|
||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||
cherr <- werr
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,17 +336,14 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
if werr := workflowStore.Write(w.opts.Context, "status", &codec.Frame{Data: []byte(StatusAborted.String())}); werr != nil {
|
||||
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||
}
|
||||
break
|
||||
case err == nil:
|
||||
if werr := workflowStore.Write(w.opts.Context, "status", &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||
}
|
||||
break
|
||||
case err != nil:
|
||||
if werr := workflowStore.Write(w.opts.Context, "status", &codec.Frame{Data: []byte(StatusFailure.String())}); werr != nil {
|
||||
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return eid, err
|
||||
@@ -429,11 +425,11 @@ func (f *microFlow) WorkflowLoad(ctx context.Context, id string) (Workflow, erro
|
||||
}
|
||||
|
||||
type microCallStep struct {
|
||||
opts StepOptions
|
||||
service string
|
||||
method string
|
||||
rsp *Message
|
||||
req *Message
|
||||
service string
|
||||
method string
|
||||
opts StepOptions
|
||||
status Status
|
||||
}
|
||||
|
||||
@@ -499,10 +495,12 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
rsp := &codec.Frame{}
|
||||
copts := []client.CallOption{client.WithRetries(0)}
|
||||
if options.Timeout > 0 {
|
||||
copts = append(copts, client.WithRequestTimeout(options.Timeout), client.WithDialTimeout(options.Timeout))
|
||||
copts = append(copts,
|
||||
client.WithRequestTimeout(options.Timeout),
|
||||
client.WithDialTimeout(options.Timeout))
|
||||
}
|
||||
nctx := metadata.NewOutgoingContext(ctx, req.Header)
|
||||
err := options.Client.Call(nctx, options.Client.NewRequest(s.service, s.method, &codec.Frame{Data: req.Body}), rsp)
|
||||
err := options.Client.Call(nctx, options.Client.NewRequest(s.service, s.method, &codec.Frame{Data: req.Body}), rsp, copts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -511,10 +509,10 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu
|
||||
}
|
||||
|
||||
type microPublishStep struct {
|
||||
opts StepOptions
|
||||
topic string
|
||||
req *Message
|
||||
rsp *Message
|
||||
topic string
|
||||
opts StepOptions
|
||||
status Status
|
||||
}
|
||||
|
||||
@@ -553,7 +551,7 @@ func (s *microPublishStep) String() string {
|
||||
if s.opts.ID != "" {
|
||||
return s.opts.ID
|
||||
}
|
||||
return fmt.Sprintf("%s", s.topic)
|
||||
return s.topic
|
||||
}
|
||||
|
||||
func (s *microPublishStep) Name() string {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package flow is an interface used for saga pattern microservice workflow
|
||||
package flow
|
||||
package flow // import "go.unistack.org/micro/v3/flow"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Option func
|
||||
@@ -96,8 +96,8 @@ type WorkflowOption func(*WorkflowOptions)
|
||||
|
||||
// WorkflowOptions holds workflow options
|
||||
type WorkflowOptions struct {
|
||||
ID string
|
||||
Context context.Context
|
||||
ID string
|
||||
}
|
||||
|
||||
// WorkflowID set workflow id
|
||||
@@ -120,10 +120,10 @@ type ExecuteOptions struct {
|
||||
Context context.Context
|
||||
// Start step
|
||||
Start string
|
||||
// Reverse execution
|
||||
Reverse bool
|
||||
// Timeout for execution
|
||||
Timeout time.Duration
|
||||
// Reverse execution
|
||||
Reverse bool
|
||||
// Async enables async execution
|
||||
Async bool
|
||||
}
|
||||
@@ -193,10 +193,10 @@ func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions {
|
||||
}
|
||||
|
||||
type StepOptions struct {
|
||||
ID string
|
||||
Context context.Context
|
||||
Requires []string
|
||||
Fallback string
|
||||
ID string
|
||||
Requires []string
|
||||
}
|
||||
|
||||
type StepOption func(*StepOptions)
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
// Function is a one time executing Service
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
)
|
||||
|
||||
func TestFunction(t *testing.T) {
|
||||
|
11
go.mod
11
go.mod
@@ -1,13 +1,14 @@
|
||||
module github.com/unistack-org/micro/v3
|
||||
module go.unistack.org/micro/v3
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/ef-ds/deque v1.0.4
|
||||
github.com/golang-jwt/jwt/v4 v4.0.0
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0
|
||||
github.com/imdario/mergo v0.3.12
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34
|
||||
github.com/unistack-org/micro-proto v0.0.9
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed
|
||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4
|
||||
go.unistack.org/micro-proto/v3 v3.1.0
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
)
|
||||
|
19
go.sum
19
go.sum
@@ -1,7 +1,7 @@
|
||||
github.com/ef-ds/deque v1.0.4 h1:iFAZNmveMT9WERAkqLJ+oaABF9AcVQ5AjXem/hroniI=
|
||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
|
||||
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
@@ -9,19 +9,20 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
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-20210121180416-41cf55125c34 h1:vBfVmA5mZhsQa2jr1FOL9nfA37N/jnbBmi5XUfviVTI=
|
||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
github.com/unistack-org/micro-proto v0.0.9 h1:KrWLS4FUX7UAWNAilQf70uad6ZPf/0EudeddCXllRVc=
|
||||
github.com/unistack-org/micro-proto v0.0.9/go.mod h1:Cckwmzd89gvS7ThxzZp9kQR/EOdksFQcsTAtDDyKwrg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4 h1:fOH64AB0C3ixGf9emky61STvPJL3smxJg+1Zwx1oCdg=
|
||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA=
|
||||
go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8=
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b h1:eB48h3HiRycXNy8E0Gf5e0hv7YT6Kt14L/D73G1fuwo=
|
||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
|
@@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type defaultLogger struct {
|
||||
enc *json.Encoder
|
||||
opts Options
|
||||
sync.RWMutex
|
||||
enc *json.Encoder
|
||||
logFunc LogFunc
|
||||
logfFunc LogfFunc
|
||||
opts Options
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// Init(opts...) should only overwrite provided options
|
||||
@@ -81,7 +81,7 @@ func (l *defaultLogger) Fields(fields ...interface{}) Logger {
|
||||
} else if len(fields)%2 != 0 {
|
||||
fields = fields[:len(fields)-1]
|
||||
}
|
||||
nl.opts.Fields = append(l.opts.Fields, fields...)
|
||||
nl.opts.Fields = append(nl.opts.Fields, fields...)
|
||||
return nl
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package logger provides a log interface
|
||||
package logger
|
||||
package logger // import "go.unistack.org/micro/v3/logger"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@@ -19,12 +19,12 @@ type Options struct {
|
||||
Fields []interface{}
|
||||
// Name holds the logger name
|
||||
Name string
|
||||
// CallerSkipCount number of frmaes to skip
|
||||
CallerSkipCount int
|
||||
// The logging level the logger should log
|
||||
Level Level
|
||||
// Wrappers logger wrapper that called before actual Log/Logf function
|
||||
Wrappers []Wrapper
|
||||
// The logging level the logger should log
|
||||
Level Level
|
||||
// CallerSkipCount number of frmaes to skip
|
||||
CallerSkipCount int
|
||||
}
|
||||
|
||||
// NewOptions creates new options struct
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package logger
|
||||
package logger // import "go.unistack.org/micro/v3/logger/wrapper"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||
)
|
||||
|
||||
// LogFunc function used for Log method
|
||||
@@ -125,23 +125,29 @@ func getArgs(args []interface{}) []interface{} {
|
||||
var err error
|
||||
for _, arg := range args {
|
||||
val := reflect.ValueOf(arg)
|
||||
switch val.Kind() {
|
||||
case reflect.Ptr:
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val = val.Elem()
|
||||
}
|
||||
narg := arg
|
||||
if val.Kind() == reflect.Struct {
|
||||
if narg, err = rutil.Zero(arg); err == nil {
|
||||
rutil.CopyDefaults(narg, arg)
|
||||
if flds, ferr := rutil.StructFields(narg); ferr == nil {
|
||||
for _, fld := range flds {
|
||||
if tv, ok := fld.Field.Tag.Lookup("logger"); ok && tv == "omit" {
|
||||
fld.Value.Set(reflect.Zero(fld.Value.Type()))
|
||||
}
|
||||
}
|
||||
if val.Kind() != reflect.Struct {
|
||||
nargs = append(nargs, narg)
|
||||
continue
|
||||
}
|
||||
|
||||
if narg, err = rutil.Zero(arg); err != nil {
|
||||
nargs = append(nargs, narg)
|
||||
continue
|
||||
}
|
||||
|
||||
rutil.CopyDefaults(narg, arg)
|
||||
if flds, ferr := rutil.StructFields(narg); ferr == nil {
|
||||
for _, fld := range flds {
|
||||
if tv, ok := fld.Field.Tag.Lookup("logger"); ok && tv == "omit" {
|
||||
fld.Value.Set(reflect.Zero(fld.Value.Type()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nargs = append(nargs, narg)
|
||||
}
|
||||
return nargs
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package metadata is a way of defining message headers
|
||||
package metadata
|
||||
package metadata // import "go.unistack.org/micro/v3/metadata"
|
||||
|
||||
import (
|
||||
"net/textproto"
|
||||
@@ -107,13 +107,16 @@ func New(size int) Metadata {
|
||||
|
||||
// Merge merges metadata to existing metadata, overwriting if specified
|
||||
func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata {
|
||||
var ok bool
|
||||
nmd := Copy(omd)
|
||||
for key, val := range mmd {
|
||||
if _, ok := nmd[key]; ok && !overwrite {
|
||||
// skip
|
||||
} else if val != "" {
|
||||
_, ok = nmd[key]
|
||||
switch {
|
||||
case ok && !overwrite:
|
||||
continue
|
||||
case val != "":
|
||||
nmd.Set(key, val)
|
||||
} else {
|
||||
case ok && val == "":
|
||||
nmd.Del(key)
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,12 @@
|
||||
package meter
|
||||
|
||||
//go:generate sh -c "protoc -I./handler -I../ -I$(go list -f '{{ .Dir }}' -m github.com/unistack-org/micro-proto) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./handler handler/handler.proto"
|
||||
//go:generate sh -c "protoc -I./handler -I../ -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./handler handler/handler.proto"
|
||||
|
||||
import (
|
||||
_ "github.com/unistack-org/micro-proto/api"
|
||||
_ "github.com/unistack-org/micro-proto/openapiv2"
|
||||
|
||||
// import required packages
|
||||
_ "go.unistack.org/micro-proto/v3/api"
|
||||
|
||||
// import required packages
|
||||
_ "go.unistack.org/micro-proto/v3/openapiv3"
|
||||
)
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package handler
|
||||
package handler // import "go.unistack.org/micro/v3/meter/handler"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/errors"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
)
|
||||
|
||||
// guard to fail early
|
||||
|
@@ -1,24 +1,20 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package micro.meter.handler;
|
||||
option go_package = "github.com/unistack-org/micro/v3/meter/handler;handler";
|
||||
option go_package = "go.unistack.org/micro/v3/meter/handler;handler";
|
||||
|
||||
import "api/annotations.proto";
|
||||
import "openapiv2/annotations.proto";
|
||||
import "openapiv3/annotations.proto";
|
||||
import "codec/frame.proto";
|
||||
|
||||
service Meter {
|
||||
rpc Metrics(micro.codec.Frame) returns (micro.codec.Frame) {
|
||||
option (micro.openapiv2.openapiv2_operation) = {
|
||||
option (micro.openapiv3.openapiv3_operation) = {
|
||||
operation_id: "Metrics";
|
||||
responses: {
|
||||
response_code: {
|
||||
name: "default";
|
||||
value: {
|
||||
json_reference: {
|
||||
description: "Error response";
|
||||
_ref: "micro.codec.Frame";
|
||||
};
|
||||
default: {
|
||||
reference: {
|
||||
_ref: "micro.codec.Frame";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@@ -1,13 +1,13 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.4.2
|
||||
// protoc-gen-go-micro version: v3.5.2
|
||||
// source: handler.proto
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
codec "github.com/unistack-org/micro/v3/codec"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
codec "go.unistack.org/micro/v3/codec"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,14 +1,14 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.4.2
|
||||
// protoc-gen-go-micro version: v3.5.2
|
||||
// source: handler.proto
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
codec "github.com/unistack-org/micro/v3/codec"
|
||||
server "github.com/unistack-org/micro/v3/server"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
codec "go.unistack.org/micro/v3/codec"
|
||||
server "go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type meterServer struct {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package meter is for instrumentation
|
||||
package meter
|
||||
package meter // import "go.unistack.org/micro/v3/meter"
|
||||
|
||||
import (
|
||||
"io"
|
||||
@@ -28,17 +28,31 @@ var (
|
||||
|
||||
// Meter is an interface for collecting and instrumenting metrics
|
||||
type Meter interface {
|
||||
// Name returns meter name
|
||||
Name() string
|
||||
// Init initialize meter
|
||||
Init(opts ...Option) error
|
||||
// Clone create meter copy with new options
|
||||
Clone(opts ...Option) Meter
|
||||
// Counter get or create counter
|
||||
Counter(name string, labels ...string) Counter
|
||||
// FloatCounter get or create float counter
|
||||
FloatCounter(name string, labels ...string) FloatCounter
|
||||
// Gauge get or create gauge
|
||||
Gauge(name string, fn func() float64, labels ...string) Gauge
|
||||
// Set create new meter metrics set
|
||||
Set(opts ...Option) Meter
|
||||
// Histogram get or create histogram
|
||||
Histogram(name string, labels ...string) Histogram
|
||||
// Summary get or create summary
|
||||
Summary(name string, labels ...string) Summary
|
||||
// SummaryExt get or create summary with spcified quantiles and window time
|
||||
SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary
|
||||
// Write writes metrics to io.Writer
|
||||
Write(w io.Writer, opts ...Option) error
|
||||
// Options returns meter options
|
||||
Options() Options
|
||||
// String return meter type
|
||||
String() string
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ func TestBuildLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
data := []testData{
|
||||
testData{
|
||||
{
|
||||
src: []string{"zerolabel", "value3", "firstlabel", "value2"},
|
||||
dst: []string{"firstlabel", "value2", "zerolabel", "value3"},
|
||||
},
|
||||
@@ -48,15 +48,15 @@ func TestBuildLabels(t *testing.T) {
|
||||
|
||||
func TestBuildName(t *testing.T) {
|
||||
data := map[string][]string{
|
||||
`my_metric{firstlabel="value2",zerolabel="value3"}`: []string{
|
||||
`my_metric{firstlabel="value2",zerolabel="value3"}`: {
|
||||
"my_metric",
|
||||
"zerolabel", "value3", "firstlabel", "value2",
|
||||
},
|
||||
`my_metric{broker="broker2",register="mdns",server="tcp"}`: []string{
|
||||
`my_metric{broker="broker2",register="mdns",server="tcp"}`: {
|
||||
"my_metric",
|
||||
"broker", "broker1", "broker", "broker2", "server", "http", "server", "tcp", "register", "mdns",
|
||||
},
|
||||
`my_metric{aaa="aaa"}`: []string{
|
||||
`my_metric{aaa="aaa"}`: {
|
||||
"my_metric",
|
||||
"aaa", "aaa",
|
||||
},
|
||||
|
@@ -15,6 +15,15 @@ func NewMeter(opts ...Option) Meter {
|
||||
return &noopMeter{opts: NewOptions(opts...)}
|
||||
}
|
||||
|
||||
// Clone return old meter with new options
|
||||
func (r *noopMeter) Clone(opts ...Option) Meter {
|
||||
options := r.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
return &noopMeter{opts: options}
|
||||
}
|
||||
|
||||
func (r *noopMeter) Name() string {
|
||||
return r.opts.Name
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package meter
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
// Option powers the configuration for metrics implementations:
|
||||
@@ -51,6 +51,20 @@ func NewOptions(opt ...Option) Options {
|
||||
return opts
|
||||
}
|
||||
|
||||
// LabelPrefix sets the labels prefix
|
||||
func LabelPrefix(pref string) Option {
|
||||
return func(o *Options) {
|
||||
o.LabelPrefix = pref
|
||||
}
|
||||
}
|
||||
|
||||
// MetricPrefix sets the metric prefix
|
||||
func MetricPrefix(pref string) Option {
|
||||
return func(o *Options) {
|
||||
o.MetricPrefix = pref
|
||||
}
|
||||
}
|
||||
|
||||
// Context sets the metrics context
|
||||
func Context(ctx context.Context) Option {
|
||||
return func(o *Options) {
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package wrapper
|
||||
package wrapper // import "go.unistack.org/micro/v3/meter/wrapper"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,35 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
// Package model is an interface for data modelling
|
||||
package model
|
||||
|
||||
// Model provides an interface for data modelling
|
||||
type Model interface {
|
||||
// Initialise options
|
||||
Init(...Option) error
|
||||
// NewEntity creates a new entity to store or access
|
||||
NewEntity(name string, value interface{}) Entity
|
||||
// Create a value
|
||||
Create(Entity) error
|
||||
// Read values
|
||||
Read(...ReadOption) ([]Entity, error)
|
||||
// Update the value
|
||||
Update(Entity) error
|
||||
// Delete an entity
|
||||
Delete(...DeleteOption) error
|
||||
// Implementation of the model
|
||||
String() string
|
||||
}
|
||||
|
||||
type Entity interface {
|
||||
// Unique id of the entity
|
||||
Id() string
|
||||
// Name of the entity
|
||||
Name() string
|
||||
// The value associated with the entity
|
||||
Value() interface{}
|
||||
// Attributes of the entity
|
||||
Attributes() map[string]interface{}
|
||||
// Read a value as a concrete type
|
||||
Read(v interface{}) error
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
// Package model is an interface for data modelling
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/sync"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
// Database to write to
|
||||
Database string
|
||||
// for serialising
|
||||
Codec codec.Codec
|
||||
// for locking
|
||||
Sync sync.Sync
|
||||
// for storage
|
||||
Store store.Store
|
||||
// for logger
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type Option func(o *Options)
|
||||
|
||||
// Logger sets the logger
|
||||
func Logger(l logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = l
|
||||
}
|
||||
}
|
||||
|
||||
type ReadOptions struct{}
|
||||
|
||||
type ReadOption func(o *ReadOptions)
|
||||
|
||||
type DeleteOptions struct{}
|
||||
|
||||
type DeleteOption func(o *DeleteOptions)
|
@@ -1,9 +1,9 @@
|
||||
// Package network is for creating internetworks
|
||||
package network
|
||||
package network // import "go.unistack.org/micro/v3/network"
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
// Error is network node errors
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
||||
"github.com/unistack-org/micro/v3/proxy"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/network/tunnel"
|
||||
"go.unistack.org/micro/v3/proxy"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
// Option func
|
||||
@@ -27,8 +27,8 @@ type Options struct {
|
||||
Tracer tracer.Tracer
|
||||
// Tunnel used for transfer data
|
||||
Tunnel tunnel.Tunnel
|
||||
// Id of the node
|
||||
Id string
|
||||
// ID of the node
|
||||
ID string
|
||||
// Name of the network
|
||||
Name string
|
||||
// Address to bind to
|
||||
@@ -39,10 +39,10 @@ type Options struct {
|
||||
Nodes []string
|
||||
}
|
||||
|
||||
// Id sets the id of the network node
|
||||
func Id(id string) Option {
|
||||
// ID sets the id of the network node
|
||||
func ID(id string) Option {
|
||||
return func(o *Options) {
|
||||
o.Id = id
|
||||
o.ID = id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func Tracer(t tracer.Tracer) Option {
|
||||
// NewOptions returns network default options
|
||||
func NewOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Id: id.Must(),
|
||||
ID: id.Must(),
|
||||
Name: "go.micro",
|
||||
Address: ":0",
|
||||
Logger: logger.DefaultLogger,
|
||||
|
@@ -8,9 +8,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
maddr "github.com/unistack-org/micro/v3/util/addr"
|
||||
mnet "github.com/unistack-org/micro/v3/util/net"
|
||||
"github.com/unistack-org/micro/v3/util/rand"
|
||||
maddr "go.unistack.org/micro/v3/util/addr"
|
||||
mnet "go.unistack.org/micro/v3/util/net"
|
||||
"go.unistack.org/micro/v3/util/rand"
|
||||
)
|
||||
|
||||
type memorySocket struct {
|
||||
|
@@ -16,12 +16,14 @@ func TestMemoryTransport(t *testing.T) {
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
cherr := make(chan error, 1)
|
||||
// accept
|
||||
go func() {
|
||||
if err := l.Accept(func(sock Socket) {
|
||||
if nerr := l.Accept(func(sock Socket) {
|
||||
for {
|
||||
var m Message
|
||||
if err := sock.Recv(&m); err != nil {
|
||||
if rerr := sock.Recv(&m); rerr != nil {
|
||||
cherr <- rerr
|
||||
return
|
||||
}
|
||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
||||
@@ -30,11 +32,12 @@ func TestMemoryTransport(t *testing.T) {
|
||||
if cerr := sock.Send(&Message{
|
||||
Body: []byte(`pong`),
|
||||
}); cerr != nil {
|
||||
cherr <- cerr
|
||||
return
|
||||
}
|
||||
}
|
||||
}); err != nil {
|
||||
t.Fatalf("Unexpected error accepting %v", err)
|
||||
}); nerr != nil {
|
||||
cherr <- err
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -45,19 +48,24 @@ func TestMemoryTransport(t *testing.T) {
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
// send <=> receive
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := c.Send(&Message{
|
||||
Body: []byte(`ping`),
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
var m Message
|
||||
if err := c.Recv(&m); err != nil {
|
||||
return
|
||||
}
|
||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
||||
t.Logf("Client Received %s", string(m.Body))
|
||||
select {
|
||||
case err := <-cherr:
|
||||
t.Fatal(err)
|
||||
default:
|
||||
// send <=> receive
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := c.Send(&Message{
|
||||
Body: []byte(`ping`),
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
var m Message
|
||||
if err := c.Recv(&m); err != nil {
|
||||
return
|
||||
}
|
||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
||||
t.Logf("Client Received %s", string(m.Body))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,10 @@ import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options struct holds the transport options
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package transport is an interface for synchronous connection based communication
|
||||
package transport
|
||||
package transport // import "go.unistack.org/micro/v3/network/transport"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,15 +1,15 @@
|
||||
// Package broker is a tunnel broker
|
||||
package broker
|
||||
package broker // import "go.unistack.org/micro/v3/network/tunnel/broker"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/network/tunnel"
|
||||
)
|
||||
|
||||
type tunBroker struct {
|
||||
@@ -34,9 +34,9 @@ type tunBatchSubscriber struct {
|
||||
}
|
||||
|
||||
type tunEvent struct {
|
||||
err error
|
||||
message *broker.Message
|
||||
topic string
|
||||
err error
|
||||
}
|
||||
|
||||
// used to access tunnel from options context
|
||||
@@ -82,7 +82,7 @@ func (t *tunBroker) BatchPublish(ctx context.Context, msgs []*broker.Message, op
|
||||
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||
c, ok := topicMap[topic]
|
||||
if !ok {
|
||||
c, err := t.tunnel.Dial(ctx, topic, tunnel.DialMode(tunnel.Multicast))
|
||||
c, err = t.tunnel.Dial(ctx, topic, tunnel.DialMode(tunnel.Multicast))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -199,7 +199,9 @@ func (t *tunBatchSubscriber) run() {
|
||||
},
|
||||
}}
|
||||
// handle the message
|
||||
go t.handler(evts)
|
||||
go func() {
|
||||
_ = t.handler(evts)
|
||||
}()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -235,13 +237,15 @@ func (t *tunSubscriber) run() {
|
||||
c.Close()
|
||||
|
||||
// handle the message
|
||||
go t.handler(&tunEvent{
|
||||
topic: t.topic,
|
||||
message: &broker.Message{
|
||||
Header: m.Header,
|
||||
Body: m.Body,
|
||||
},
|
||||
})
|
||||
go func() {
|
||||
_ = t.handler(&tunEvent{
|
||||
topic: t.topic,
|
||||
message: &broker.Message{
|
||||
Header: m.Header,
|
||||
Body: m.Body,
|
||||
},
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,11 +3,11 @@ package tunnel
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/network/tunnel"
|
||||
)
|
||||
|
||||
type tunListener struct {
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Package transport provides a tunnel transport
|
||||
package transport
|
||||
package transport // import "go.unistack.org/micro/v3/network/tunnel/transport"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/network/tunnel"
|
||||
)
|
||||
|
||||
type tunTransport struct {
|
||||
@@ -37,7 +37,7 @@ func (t *tunTransport) Init(opts ...transport.Option) error {
|
||||
// get the transport
|
||||
tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport)
|
||||
if ok {
|
||||
tun.Init(tunnel.Transport(tr))
|
||||
_ = tun.Init(tunnel.Transport(tr))
|
||||
}
|
||||
|
||||
// set the tunnel
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Package tunnel provides gre network tunnelling
|
||||
package tunnel
|
||||
package tunnel // import "go.unistack.org/micro/v3/network/transport/tunnel"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"go.unistack.org/micro/v3/network/transport"
|
||||
)
|
||||
|
||||
// DefaultTunnel contains default tunnel implementation
|
||||
|
24
options.go
24
options.go
@@ -5,18 +5,18 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/auth"
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/config"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/auth"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options for micro service
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package http enables the http profiler
|
||||
package http
|
||||
package http // import "go.unistack.org/micro/v3/profiler/http"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"net/http/pprof"
|
||||
"sync"
|
||||
|
||||
profile "github.com/unistack-org/micro/v3/profiler"
|
||||
profile "go.unistack.org/micro/v3/profiler"
|
||||
)
|
||||
|
||||
type httpProfile struct {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package pprof provides a pprof profiler which writes output to /tmp/[name].{cpu,mem}.pprof
|
||||
package pprof
|
||||
package pprof // import "go.unistack.org/micro/v3/profiler/pprof"
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
profile "github.com/unistack-org/micro/v3/profiler"
|
||||
profile "go.unistack.org/micro/v3/profiler"
|
||||
)
|
||||
|
||||
type profiler struct {
|
||||
@@ -31,7 +31,7 @@ func (p *profiler) writeHeap(f *os.File) {
|
||||
select {
|
||||
case <-t.C:
|
||||
runtime.GC()
|
||||
pprof.WriteHeapProfile(f)
|
||||
_ = pprof.WriteHeapProfile(f)
|
||||
case <-p.exit:
|
||||
return
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package profiler is for profilers
|
||||
package profiler
|
||||
package profiler // import "go.unistack.org/micro/v3/profiler"
|
||||
|
||||
// Profiler interface
|
||||
type Profiler interface {
|
||||
|
@@ -2,11 +2,11 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options for proxy
|
||||
|
@@ -1,10 +1,10 @@
|
||||
// Package proxy is a transparent proxy built on the micro/server
|
||||
package proxy
|
||||
package proxy // import "go.unistack.org/micro/v3/proxy"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
// DefaultEndpoint holds default proxy address
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// ExtractValue from reflect.Type from specified depth
|
||||
|
@@ -6,8 +6,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"go.unistack.org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
// Options holds options for register
|
||||
@@ -44,7 +44,7 @@ func NewOptions(opts ...Option) Options {
|
||||
return options
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
// nolint: golint,revive
|
||||
// RegisterOptions holds options for register method
|
||||
type RegisterOptions struct {
|
||||
Context context.Context
|
||||
@@ -197,7 +197,7 @@ func TLSConfig(t *tls.Config) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
// nolint: golint,revive
|
||||
// RegisterAttempts specifies register atempts count
|
||||
func RegisterAttempts(t int) RegisterOption {
|
||||
return func(o *RegisterOptions) {
|
||||
@@ -205,7 +205,7 @@ func RegisterAttempts(t int) RegisterOption {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
// nolint: golint,revive
|
||||
// RegisterTTL specifies register ttl
|
||||
func RegisterTTL(t time.Duration) RegisterOption {
|
||||
return func(o *RegisterOptions) {
|
||||
@@ -213,7 +213,7 @@ func RegisterTTL(t time.Duration) RegisterOption {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
// nolint: golint,revive
|
||||
// RegisterContext sets the register context
|
||||
func RegisterContext(ctx context.Context) RegisterOption {
|
||||
return func(o *RegisterOptions) {
|
||||
@@ -221,7 +221,7 @@ func RegisterContext(ctx context.Context) RegisterOption {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: golint
|
||||
// nolint: golint,revive
|
||||
// RegisterDomain secifies register domain
|
||||
func RegisterDomain(d string) RegisterOption {
|
||||
return func(o *RegisterOptions) {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package register is an interface for service discovery
|
||||
package register
|
||||
package register // import "go.unistack.org/micro/v3/register"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -68,8 +68,8 @@ type Endpoint struct {
|
||||
// Option func signature
|
||||
type Option func(*Options)
|
||||
|
||||
// nolint: golint,revive
|
||||
// RegisterOption option is used to register service
|
||||
// nolint: golint
|
||||
type RegisterOption func(*RegisterOptions)
|
||||
|
||||
// WatchOption option is used to watch service changes
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package dns resolves names to dns records
|
||||
package dns
|
||||
package dns // import "go.unistack.org/micro/v3/resolver/dns"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// Resolver is a DNS network resolve
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package dnssrv resolves names to dns srv records
|
||||
package dnssrv
|
||||
package dnssrv // import "go.unistack.org/micro/v3/resolver/dnssrv"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// Resolver is a DNS network resolve
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package http resolves names to network addresses using a http request
|
||||
package http
|
||||
package http // import "go.unistack.org/micro/v3/resolver/http"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// nolint: golint,revive
|
||||
// HTTPResolver is a HTTP network resolver
|
||||
type HTTPResolver struct {
|
||||
// Proto if not set, defaults to http
|
||||
@@ -53,6 +54,7 @@ func (r *HTTPResolver) Resolve(name string) ([]*resolver.Record, error) {
|
||||
q.Set("name", name)
|
||||
uri.RawQuery = q.Encode()
|
||||
|
||||
// nolint: noctx
|
||||
rsp, err := http.Get(uri.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -1,8 +1,8 @@
|
||||
// Package noop is a noop resolver
|
||||
package noop
|
||||
package noop // import "go.unistack.org/micro/v3/resolver/noop"
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// Resolver contains noop resolver
|
||||
|
@@ -1,11 +1,11 @@
|
||||
// Package register resolves names using the micro register
|
||||
package register
|
||||
package register // import "go.unistack.org/micro/v3/resolver/registry"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/register"
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// Resolver is a register network resolver
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// Package resolver resolves network names to addresses
|
||||
package resolver
|
||||
package resolver // import "go.unistack.org/micro/v3/resolver"
|
||||
|
||||
// Resolver is network resolver. It's used to find network nodes
|
||||
// via the name to connect to. This is done based on Network.Name().
|
||||
|
@@ -1,8 +1,8 @@
|
||||
// Package static is a static resolver
|
||||
package static
|
||||
package static // import "go.unistack.org/micro/v3/resolver/static"
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/resolver"
|
||||
"go.unistack.org/micro/v3/resolver"
|
||||
)
|
||||
|
||||
// Resolver returns a static list of nodes. In the event the node list
|
||||
|
@@ -40,8 +40,9 @@ func (d *dns) Lookup(opts ...QueryOption) ([]Route, error) {
|
||||
// check to see if we have the port provided in the service, e.g. go-micro-srv-foo:8000
|
||||
host, port, err := net.SplitHostPort(options.Service)
|
||||
if err == nil {
|
||||
var ips []string
|
||||
// lookup the service using A records
|
||||
ips, err := net.LookupHost(host)
|
||||
ips, err = net.LookupHost(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user