Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f5b19497c | |||
37d937d7ae | |||
7d68f2396e | |||
0854a7ea72 | |||
5eb0e56373 | |||
ada59119cc | |||
8abc913b28 | |||
3247d144a8 | |||
7b2e3cc8aa | |||
8688179acd | |||
3e40bac5f4 | |||
e3fee6f8a6 | |||
15c020fac5 | |||
3bc046e5d4 | |||
542f36cfa5 | |||
8237e6a08e | |||
ecb60e4dc5 | |||
a1999ff81c | |||
d0f2bc8346 | |||
|
dd29bf457e | ||
d062c248e3 | |||
875f66d36e | |||
818a0e6356 |
2
.github/workflows/dependabot-automerge.yml
vendored
2
.github/workflows/dependabot-automerge.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
|||||||
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
||||||
steps:
|
steps:
|
||||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
||||||
uses: actions/github-script@v4
|
uses: actions/github-script@v5
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
@@ -30,7 +30,7 @@ linters:
|
|||||||
- gofmt
|
- gofmt
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goimports
|
- goimports
|
||||||
- golint
|
- revive
|
||||||
- gosec
|
- gosec
|
||||||
- makezero
|
- makezero
|
||||||
- misspell
|
- 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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint: revive
|
||||||
// Api interface
|
// Api interface
|
||||||
type Api interface {
|
type Api interface {
|
||||||
// Initialise options
|
// Initialise options
|
||||||
@@ -125,14 +126,14 @@ func Validate(e *Endpoint) error {
|
|||||||
ps := p[0]
|
ps := p[0]
|
||||||
pe := p[len(p)-1]
|
pe := p[len(p)-1]
|
||||||
|
|
||||||
if ps == '^' && pe == '$' {
|
switch {
|
||||||
_, err := regexp.CompilePOSIX(p)
|
case ps == '^' && pe == '$':
|
||||||
if err != nil {
|
if _, err := regexp.CompilePOSIX(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if ps == '^' && pe != '$' {
|
case ps == '^' && pe != '$':
|
||||||
return errors.New("invalid path")
|
return errors.New("invalid path")
|
||||||
} else if ps != '^' && pe == '$' {
|
case ps != '^' && pe == '$':
|
||||||
return errors.New("invalid path")
|
return errors.New("invalid path")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package handler provides http handlers
|
// Package handler provides http handlers
|
||||||
package handler
|
package handler // import "go.unistack.org/micro/v3/api/handler"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/api/router"
|
"go.unistack.org/micro/v3/api/router"
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultMaxRecvSize specifies max recv size for handler
|
// 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 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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver struct
|
// Resolver struct
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
// Package host resolves using http host
|
// Package host resolves using http host
|
||||||
package host
|
package host // import "go.unistack.org/micro/v3/api/resolver/host"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type hostResolver struct {
|
type hostResolver struct {
|
||||||
|
@@ -3,7 +3,7 @@ package resolver
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options struct
|
// Options struct
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package path resolves using http path
|
// Package path resolves using http path
|
||||||
package path
|
package path // import "go.unistack.org/micro/v3/api/resolver/path"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver the path resolver
|
// Resolver the path resolver
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package resolver resolves a http request to an endpoint
|
// Package resolver resolves a http request to an endpoint
|
||||||
package resolver
|
package resolver // import "go.unistack.org/micro/v3/api/resolver"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
// Package subdomain is a resolver which uses the subdomain to determine the domain to route to. It
|
// 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.
|
// 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 (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"golang.org/x/net/publicsuffix"
|
"golang.org/x/net/publicsuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver/vpath"
|
"go.unistack.org/micro/v3/api/resolver/vpath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolve(t *testing.T) {
|
func TestResolve(t *testing.T) {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package vpath resolves using http path and recognised versioned urls
|
// Package vpath resolves using http path and recognised versioned urls
|
||||||
package vpath
|
package vpath // import "go.unistack.org/micro/v3/api/resolver/vpath"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewResolver creates new vpath api resolver
|
// NewResolver creates new vpath api resolver
|
||||||
|
@@ -3,10 +3,10 @@ package router
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api/resolver"
|
"go.unistack.org/micro/v3/api/resolver"
|
||||||
"github.com/unistack-org/micro/v3/api/resolver/vpath"
|
"go.unistack.org/micro/v3/api/resolver/vpath"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options holds the options for api router
|
// Options holds the options for api router
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
// Package router provides api service routing
|
// Package router provides api service routing
|
||||||
package router
|
package router // import "go.unistack.org/micro/v3/api/router"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/api"
|
"go.unistack.org/micro/v3/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultRouter contains default router implementation
|
// DefaultRouter contains default router implementation
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
// Package auth provides authentication and authorization capability
|
// Package auth provides authentication and authorization capability
|
||||||
package auth
|
package auth // import "go.unistack.org/micro/v3/auth"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
type noopAuth struct {
|
type noopAuth struct {
|
||||||
|
@@ -4,11 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"go.unistack.org/micro/v3/store"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewOptions creates Options struct from slice of options
|
// NewOptions creates Options struct from slice of options
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package broker is an interface used for asynchronous messaging
|
// Package broker is an interface used for asynchronous messaging
|
||||||
package broker
|
package broker // import "go.unistack.org/micro/v3/broker"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBroker default memory broker
|
// DefaultBroker default memory broker
|
||||||
|
176
broker/memory.go
176
broker/memory.go
@@ -4,12 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
maddr "github.com/unistack-org/micro/v3/util/addr"
|
maddr "go.unistack.org/micro/v3/util/addr"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
mnet "github.com/unistack-org/micro/v3/util/net"
|
mnet "go.unistack.org/micro/v3/util/net"
|
||||||
"github.com/unistack-org/micro/v3/util/rand"
|
"go.unistack.org/micro/v3/util/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
type memoryBroker struct {
|
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 {
|
func (m *memoryBroker) Publish(ctx context.Context, topic string, msg *Message, opts ...PublishOption) error {
|
||||||
m.RLock()
|
msg.Header.Set(metadata.HeaderTopic, topic)
|
||||||
if !m.connected {
|
return m.publish(ctx, []*Message{msg}, opts...)
|
||||||
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{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memoryBroker) BatchPublish(ctx context.Context, msgs []*Message, opts ...PublishOption) error {
|
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()
|
m.RLock()
|
||||||
if !m.connected {
|
if !m.connected {
|
||||||
m.RUnlock()
|
m.RUnlock()
|
||||||
@@ -126,88 +105,81 @@ func (m *memoryBroker) BatchPublish(ctx context.Context, msgs []*Message, opts .
|
|||||||
}
|
}
|
||||||
m.RUnlock()
|
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
|
var err error
|
||||||
|
|
||||||
msgTopicMap := make(map[string]Events)
|
select {
|
||||||
for _, v := range vs {
|
case <-ctx.Done():
|
||||||
p := &memoryEvent{
|
return ctx.Err()
|
||||||
topic: v.topic,
|
default:
|
||||||
message: v.body,
|
options := NewPublishOptions(opts...)
|
||||||
opts: m.opts,
|
|
||||||
}
|
|
||||||
msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p)
|
|
||||||
}
|
|
||||||
|
|
||||||
beh := m.opts.BatchErrorHandler
|
msgTopicMap := make(map[string]Events)
|
||||||
eh := m.opts.ErrorHandler
|
for _, v := range msgs {
|
||||||
|
p := &memoryEvent{opts: m.opts}
|
||||||
|
|
||||||
for t, ms := range msgTopicMap {
|
if m.opts.Codec == nil || options.BodyOnly {
|
||||||
m.RLock()
|
p.topic, _ = v.Header.Get(metadata.HeaderTopic)
|
||||||
subs, ok := m.subscribers[t]
|
p.message = v.Body
|
||||||
m.RUnlock()
|
} else {
|
||||||
if !ok {
|
p.topic, _ = v.Header.Get(metadata.HeaderTopic)
|
||||||
continue
|
p.message, err = m.opts.Codec.Marshal(v)
|
||||||
}
|
if err != nil {
|
||||||
|
return err
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// single processing
|
msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p)
|
||||||
if sub.handler != nil {
|
}
|
||||||
for _, p := range ms {
|
|
||||||
if err = sub.handler(p); err != nil {
|
beh := m.opts.BatchErrorHandler
|
||||||
p.SetError(err)
|
eh := m.opts.ErrorHandler
|
||||||
if sub.opts.ErrorHandler != nil {
|
|
||||||
eh = sub.opts.ErrorHandler
|
for t, ms := range msgTopicMap {
|
||||||
}
|
m.RLock()
|
||||||
if eh != nil {
|
subs, ok := m.subscribers[t]
|
||||||
eh(p)
|
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) {
|
} else if m.opts.Logger.V(logger.ErrorLevel) {
|
||||||
m.opts.Logger.Error(m.opts.Context, err.Error())
|
m.opts.Logger.Error(m.opts.Context, err.Error())
|
||||||
}
|
}
|
||||||
} else if sub.opts.AutoAck {
|
} 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)
|
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"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemoryBatchBroker(t *testing.T) {
|
func TestMemoryBatchBroker(t *testing.T) {
|
||||||
@@ -28,7 +28,7 @@ func TestMemoryBatchBroker(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected error subscribing %v", err)
|
t.Fatalf("Unexpected error subscribing %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs := make([]*Message, 0, 0)
|
msgs := make([]*Message, 0, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
message := &Message{
|
message := &Message{
|
||||||
Header: map[string]string{
|
Header: map[string]string{
|
||||||
@@ -53,6 +53,7 @@ func TestMemoryBatchBroker(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected connect error %v", err)
|
t.Fatalf("Unexpected connect error %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemoryBroker(t *testing.T) {
|
func TestMemoryBroker(t *testing.T) {
|
||||||
b := NewBroker()
|
b := NewBroker()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -73,7 +74,7 @@ func TestMemoryBroker(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected error subscribing %v", err)
|
t.Fatalf("Unexpected error subscribing %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs := make([]*Message, 0, 0)
|
msgs := make([]*Message, 0, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
message := &Message{
|
message := &Message{
|
||||||
Header: map[string]string{
|
Header: map[string]string{
|
||||||
|
@@ -5,11 +5,11 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options struct
|
// Options struct
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package build is for building source into a package
|
// 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
|
// Build is an interface for building packages
|
||||||
type Build interface {
|
type Build interface {
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/util/backoff"
|
"go.unistack.org/micro/v3/util/backoff"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BackoffFunc is the backoff call func
|
// BackoffFunc is the backoff call func
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
// Package client is an interface for an RPC client
|
// Package client is an interface for an RPC client
|
||||||
package client
|
package client // import "go.unistack.org/micro/v3/client"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LookupFunc is used to lookup routes for a service
|
// LookupFunc is used to lookup routes for a service
|
||||||
|
@@ -3,10 +3,10 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultCodecs will be used to encode/decode data
|
// DefaultCodecs will be used to encode/decode data
|
||||||
|
@@ -5,20 +5,22 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/selector"
|
"go.unistack.org/micro/v3/selector"
|
||||||
"github.com/unistack-org/micro/v3/selector/random"
|
"go.unistack.org/micro/v3/selector/random"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options holds client options
|
// Options holds client options
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
// Transport used for transfer messages
|
||||||
|
Transport transport.Transport
|
||||||
// Selector used to select needed address
|
// Selector used to select needed address
|
||||||
Selector selector.Selector
|
Selector selector.Selector
|
||||||
// Logger used to log messages
|
// Logger used to log messages
|
||||||
@@ -29,18 +31,16 @@ type Options struct {
|
|||||||
Broker broker.Broker
|
Broker broker.Broker
|
||||||
// Meter used for metrics
|
// Meter used for metrics
|
||||||
Meter meter.Meter
|
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 is used for external options
|
||||||
Context context.Context
|
Context context.Context
|
||||||
// Lookup func used to get destination addr
|
// Router used to get route
|
||||||
Lookup LookupFunc
|
Router router.Router
|
||||||
// Codecs map
|
|
||||||
Codecs map[string]codec.Codec
|
|
||||||
// TLSConfig specifies tls.Config for secure connection
|
// TLSConfig specifies tls.Config for secure connection
|
||||||
TLSConfig *tls.Config
|
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 is used for proxy requests
|
||||||
Proxy string
|
Proxy string
|
||||||
// ContentType is used to select codec
|
// ContentType is used to select codec
|
||||||
@@ -68,12 +68,12 @@ func NewCallOptions(opts ...CallOption) CallOptions {
|
|||||||
|
|
||||||
// CallOptions holds client call options
|
// CallOptions holds client call options
|
||||||
type CallOptions struct {
|
type CallOptions struct {
|
||||||
// Router used for route
|
|
||||||
Router router.Router
|
|
||||||
// Selector selects addr
|
// Selector selects addr
|
||||||
Selector selector.Selector
|
Selector selector.Selector
|
||||||
// Context used for deadline
|
// Context used for deadline
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
// Router used for route
|
||||||
|
Router router.Router
|
||||||
// Retry func used for retries
|
// Retry func used for retries
|
||||||
Retry RetryFunc
|
Retry RetryFunc
|
||||||
// Backoff func used for backoff when retry
|
// Backoff func used for backoff when retry
|
||||||
@@ -82,22 +82,22 @@ type CallOptions struct {
|
|||||||
Network string
|
Network string
|
||||||
// Content-Type
|
// Content-Type
|
||||||
ContentType string
|
ContentType string
|
||||||
// CallWrappers call wrappers
|
// AuthToken string
|
||||||
CallWrappers []CallWrapper
|
AuthToken string
|
||||||
// SelectOptions selector options
|
|
||||||
SelectOptions []selector.SelectOption
|
|
||||||
// Address specifies static addr list
|
// Address specifies static addr list
|
||||||
Address []string
|
Address []string
|
||||||
// Retries specifies retries num
|
// SelectOptions selector options
|
||||||
Retries int
|
SelectOptions []selector.SelectOption
|
||||||
|
// CallWrappers call wrappers
|
||||||
|
CallWrappers []CallWrapper
|
||||||
// StreamTimeout stream timeout
|
// StreamTimeout stream timeout
|
||||||
StreamTimeout time.Duration
|
StreamTimeout time.Duration
|
||||||
// RequestTimeout request timeout
|
// RequestTimeout request timeout
|
||||||
RequestTimeout time.Duration
|
RequestTimeout time.Duration
|
||||||
// DialTimeout dial timeout
|
// DialTimeout dial timeout
|
||||||
DialTimeout time.Duration
|
DialTimeout time.Duration
|
||||||
// AuthToken string
|
// Retries specifies retries num
|
||||||
AuthToken string
|
Retries int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context pass context to client
|
// Context pass context to client
|
||||||
@@ -118,12 +118,12 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions {
|
|||||||
|
|
||||||
// PublishOptions holds publish options
|
// PublishOptions holds publish options
|
||||||
type PublishOptions struct {
|
type PublishOptions struct {
|
||||||
// BodyOnly will publish only message body
|
|
||||||
BodyOnly bool
|
|
||||||
// Context used for external options
|
// Context used for external options
|
||||||
Context context.Context
|
Context context.Context
|
||||||
// Exchange topic exchange name
|
// Exchange topic exchange name
|
||||||
Exchange string
|
Exchange string
|
||||||
|
// BodyOnly will publish only message body
|
||||||
|
BodyOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMessageOptions creates message options struct
|
// NewMessageOptions creates message options struct
|
||||||
@@ -267,7 +267,7 @@ func Transport(t transport.Transport) Option {
|
|||||||
func Register(r register.Register) Option {
|
func Register(r register.Register) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
if o.Router != nil {
|
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.
|
// already set. Required for Init call below.
|
||||||
|
|
||||||
// set the transport tls
|
// set the transport tls
|
||||||
o.Transport.Init(
|
_ = o.Transport.Init(
|
||||||
transport.TLSConfig(t),
|
transport.TLSConfig(t),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"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
|
// RetryFunc that returning either false or a non-nil error will result in the call not being retried
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testRequest struct {
|
type testRequest struct {
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package codec is an interface for encoding messages
|
// Package codec is an interface for encoding messages
|
||||||
package codec
|
package codec // import "go.unistack.org/micro/v3/codec"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Message types
|
// Message types
|
||||||
@@ -25,7 +25,7 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultMaxMsgSize specifies how much data codec can handle
|
// 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 is the global default codec
|
||||||
DefaultCodec Codec = NewCodec()
|
DefaultCodec Codec = NewCodec()
|
||||||
// DefaultTagName specifies struct tag name to control codec Marshal/Unmarshal
|
// DefaultTagName specifies struct tag name to control codec Marshal/Unmarshal
|
||||||
@@ -58,7 +58,7 @@ type Message struct {
|
|||||||
Method string
|
Method string
|
||||||
Endpoint string
|
Endpoint string
|
||||||
Error string
|
Error string
|
||||||
Id string
|
ID string
|
||||||
Body []byte
|
Body []byte
|
||||||
Type MessageType
|
Type MessageType
|
||||||
}
|
}
|
||||||
@@ -67,3 +67,20 @@ type Message struct {
|
|||||||
func NewMessage(t MessageType) *Message {
|
func NewMessage(t MessageType) *Message {
|
||||||
return &Message{Type: t, Header: metadata.New(0)}
|
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
|
||||||
|
}
|
||||||
|
34
codec/context.go
Normal file
34
codec/context.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package codec
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type codecKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns codec from context
|
||||||
|
func FromContext(ctx context.Context) (Codec, bool) {
|
||||||
|
if ctx == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
c, ok := ctx.Value(codecKey{}).(Codec)
|
||||||
|
return c, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext put codec in context
|
||||||
|
func NewContext(ctx context.Context, c Codec) context.Context {
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = context.Background()
|
||||||
|
}
|
||||||
|
return context.WithValue(ctx, codecKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOption returns a function to setup a context with given value
|
||||||
|
func SetOption(k, v interface{}) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
if o.Context == nil {
|
||||||
|
o.Context = context.Background()
|
||||||
|
}
|
||||||
|
o.Context = context.WithValue(o.Context, k, v)
|
||||||
|
}
|
||||||
|
}
|
@@ -4,3 +4,31 @@ package codec
|
|||||||
type Frame struct {
|
type Frame struct {
|
||||||
Data []byte
|
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
|
||||||
|
}
|
||||||
|
@@ -3,9 +3,9 @@ package codec
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option func
|
// Option func
|
||||||
@@ -19,12 +19,12 @@ type Options struct {
|
|||||||
Logger logger.Logger
|
Logger logger.Logger
|
||||||
// Tracer used for tracing
|
// Tracer used for tracing
|
||||||
Tracer tracer.Tracer
|
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 stores additional codec options
|
||||||
Context context.Context
|
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
|
// MaxMsgSize sets the max message size
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package config is an interface for dynamic configuration.
|
// Package config is an interface for dynamic configuration.
|
||||||
package config
|
package config // import "go.unistack.org/micro/v3/config"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -13,7 +13,7 @@ var DefaultConfig Config = NewConfig()
|
|||||||
// DefaultWatcherMinInterval default min interval for poll changes
|
// DefaultWatcherMinInterval default min interval for poll changes
|
||||||
var DefaultWatcherMinInterval = 5 * time.Second
|
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 DefaultWatcherMaxInterval = 9 * time.Second
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -64,3 +64,53 @@ func Load(ctx context.Context, cs []Config, opts ...LoadOption) error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type defaultConfig struct {
|
type defaultConfig struct {
|
||||||
@@ -27,10 +27,8 @@ func (c *defaultConfig) Init(opts ...Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *defaultConfig) Load(ctx context.Context, opts ...LoadOption) error {
|
func (c *defaultConfig) Load(ctx context.Context, opts ...LoadOption) error {
|
||||||
for _, fn := range c.opts.BeforeLoad {
|
if err := DefaultBeforeLoad(ctx, c); err != nil {
|
||||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options := NewLoadOptions(opts...)
|
options := NewLoadOptions(opts...)
|
||||||
@@ -48,20 +46,26 @@ func (c *defaultConfig) Load(ctx context.Context, opts ...LoadOption) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
src, err := rutil.Zero(dst)
|
src, err := rutil.Zero(dst)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
if err = fillValues(reflect.ValueOf(src), c.opts.StructTag); err == nil {
|
if !c.opts.AllowFail {
|
||||||
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 {
|
|
||||||
return err
|
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
|
return nil
|
||||||
@@ -247,16 +251,12 @@ func fillValues(valueOf reflect.Value, tname string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *defaultConfig) Save(ctx context.Context, opts ...SaveOption) error {
|
func (c *defaultConfig) Save(ctx context.Context, opts ...SaveOption) error {
|
||||||
for _, fn := range c.opts.BeforeSave {
|
if err := DefaultBeforeSave(ctx, c); err != nil {
|
||||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fn := range c.opts.AfterSave {
|
if err := DefaultAfterSave(ctx, c); err != nil {
|
||||||
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/config"
|
"go.unistack.org/micro/v3/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cfg struct {
|
type Cfg struct {
|
||||||
@@ -48,5 +48,5 @@ func TestDefault(t *testing.T) {
|
|||||||
t.Fatal("AfterLoad option not working")
|
t.Fatal("AfterLoad option not working")
|
||||||
}
|
}
|
||||||
_ = conf
|
_ = conf
|
||||||
//t.Logf("%#+v\n", conf)
|
// t.Logf("%#+v\n", conf)
|
||||||
}
|
}
|
||||||
|
@@ -4,10 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options hold the config options
|
// Options hold the config options
|
||||||
@@ -209,14 +209,14 @@ func Name(n string) Option {
|
|||||||
type WatchOptions struct {
|
type WatchOptions struct {
|
||||||
// Context used by non default options
|
// Context used by non default options
|
||||||
Context context.Context
|
Context context.Context
|
||||||
// Coalesce multiple events to one
|
// Struct for filling
|
||||||
Coalesce bool
|
Struct interface{}
|
||||||
// MinInterval specifies the min time.Duration interval for poll changes
|
// MinInterval specifies the min time.Duration interval for poll changes
|
||||||
MinInterval time.Duration
|
MinInterval time.Duration
|
||||||
// MaxInterval specifies the max time.Duration interval for poll changes
|
// MaxInterval specifies the max time.Duration interval for poll changes
|
||||||
MaxInterval time.Duration
|
MaxInterval time.Duration
|
||||||
// Struct for filling
|
// Coalesce multiple events to one
|
||||||
Struct interface{}
|
Coalesce bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type WatchOption func(*WatchOptions)
|
type WatchOption func(*WatchOptions)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
// Package errors provides a way to return detailed information
|
// Package errors provides a way to return detailed information
|
||||||
// for an RPC request error. The error is normally JSON encoded.
|
// for an RPC request error. The error is normally JSON encoded.
|
||||||
package errors
|
package errors // import "go.unistack.org/micro/v3/errors"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -37,8 +37,8 @@ var (
|
|||||||
|
|
||||||
// Error type
|
// Error type
|
||||||
type Error struct {
|
type Error struct {
|
||||||
// Id holds error id or service, usually someting like my_service or id
|
// ID holds error id or service, usually someting like my_service or id
|
||||||
Id string
|
ID string
|
||||||
// Detail holds some useful details about error
|
// Detail holds some useful details about error
|
||||||
Detail string
|
Detail string
|
||||||
// Status usually holds text of http status
|
// Status usually holds text of http status
|
||||||
@@ -56,7 +56,7 @@ func (e *Error) Error() string {
|
|||||||
// New generates a custom error
|
// New generates a custom error
|
||||||
func New(id, detail string, code int32) error {
|
func New(id, detail string, code int32) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: code,
|
Code: code,
|
||||||
Detail: detail,
|
Detail: detail,
|
||||||
Status: http.StatusText(int(code)),
|
Status: http.StatusText(int(code)),
|
||||||
@@ -77,7 +77,7 @@ func Parse(err string) *Error {
|
|||||||
// BadRequest generates a 400 error.
|
// BadRequest generates a 400 error.
|
||||||
func BadRequest(id, format string, a ...interface{}) error {
|
func BadRequest(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 400,
|
Code: 400,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(400),
|
Status: http.StatusText(400),
|
||||||
@@ -87,7 +87,7 @@ func BadRequest(id, format string, a ...interface{}) error {
|
|||||||
// Unauthorized generates a 401 error.
|
// Unauthorized generates a 401 error.
|
||||||
func Unauthorized(id, format string, a ...interface{}) error {
|
func Unauthorized(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 401,
|
Code: 401,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(401),
|
Status: http.StatusText(401),
|
||||||
@@ -97,7 +97,7 @@ func Unauthorized(id, format string, a ...interface{}) error {
|
|||||||
// Forbidden generates a 403 error.
|
// Forbidden generates a 403 error.
|
||||||
func Forbidden(id, format string, a ...interface{}) error {
|
func Forbidden(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 403,
|
Code: 403,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(403),
|
Status: http.StatusText(403),
|
||||||
@@ -107,7 +107,7 @@ func Forbidden(id, format string, a ...interface{}) error {
|
|||||||
// NotFound generates a 404 error.
|
// NotFound generates a 404 error.
|
||||||
func NotFound(id, format string, a ...interface{}) error {
|
func NotFound(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 404,
|
Code: 404,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(404),
|
Status: http.StatusText(404),
|
||||||
@@ -117,7 +117,7 @@ func NotFound(id, format string, a ...interface{}) error {
|
|||||||
// MethodNotAllowed generates a 405 error.
|
// MethodNotAllowed generates a 405 error.
|
||||||
func MethodNotAllowed(id, format string, a ...interface{}) error {
|
func MethodNotAllowed(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 405,
|
Code: 405,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(405),
|
Status: http.StatusText(405),
|
||||||
@@ -127,7 +127,7 @@ func MethodNotAllowed(id, format string, a ...interface{}) error {
|
|||||||
// Timeout generates a 408 error.
|
// Timeout generates a 408 error.
|
||||||
func Timeout(id, format string, a ...interface{}) error {
|
func Timeout(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 408,
|
Code: 408,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(408),
|
Status: http.StatusText(408),
|
||||||
@@ -137,7 +137,7 @@ func Timeout(id, format string, a ...interface{}) error {
|
|||||||
// Conflict generates a 409 error.
|
// Conflict generates a 409 error.
|
||||||
func Conflict(id, format string, a ...interface{}) error {
|
func Conflict(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 409,
|
Code: 409,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(409),
|
Status: http.StatusText(409),
|
||||||
@@ -147,7 +147,7 @@ func Conflict(id, format string, a ...interface{}) error {
|
|||||||
// InternalServerError generates a 500 error.
|
// InternalServerError generates a 500 error.
|
||||||
func InternalServerError(id, format string, a ...interface{}) error {
|
func InternalServerError(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(500),
|
Status: http.StatusText(500),
|
||||||
@@ -157,7 +157,7 @@ func InternalServerError(id, format string, a ...interface{}) error {
|
|||||||
// NotImplemented generates a 501 error
|
// NotImplemented generates a 501 error
|
||||||
func NotImplemented(id, format string, a ...interface{}) error {
|
func NotImplemented(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 501,
|
Code: 501,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(501),
|
Status: http.StatusText(501),
|
||||||
@@ -167,7 +167,7 @@ func NotImplemented(id, format string, a ...interface{}) error {
|
|||||||
// BadGateway generates a 502 error
|
// BadGateway generates a 502 error
|
||||||
func BadGateway(id, format string, a ...interface{}) error {
|
func BadGateway(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 502,
|
Code: 502,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(502),
|
Status: http.StatusText(502),
|
||||||
@@ -177,7 +177,7 @@ func BadGateway(id, format string, a ...interface{}) error {
|
|||||||
// ServiceUnavailable generates a 503 error
|
// ServiceUnavailable generates a 503 error
|
||||||
func ServiceUnavailable(id, format string, a ...interface{}) error {
|
func ServiceUnavailable(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 503,
|
Code: 503,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(503),
|
Status: http.StatusText(503),
|
||||||
@@ -187,7 +187,7 @@ func ServiceUnavailable(id, format string, a ...interface{}) error {
|
|||||||
// GatewayTimeout generates a 504 error
|
// GatewayTimeout generates a 504 error
|
||||||
func GatewayTimeout(id, format string, a ...interface{}) error {
|
func GatewayTimeout(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
ID: id,
|
||||||
Code: 504,
|
Code: 504,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(504),
|
Status: http.StatusText(504),
|
||||||
|
@@ -9,12 +9,12 @@ import (
|
|||||||
func TestFromError(t *testing.T) {
|
func TestFromError(t *testing.T) {
|
||||||
err := NotFound("go.micro.test", "%s", "example")
|
err := NotFound("go.micro.test", "%s", "example")
|
||||||
merr := FromError(err)
|
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)
|
t.Fatalf("invalid conversation %v != %v", err, merr)
|
||||||
}
|
}
|
||||||
err = er.New(err.Error())
|
err = er.New(err.Error())
|
||||||
merr = FromError(err)
|
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)
|
t.Fatalf("invalid conversation %v != %v", err, merr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ func TestEqual(t *testing.T) {
|
|||||||
func TestErrors(t *testing.T) {
|
func TestErrors(t *testing.T) {
|
||||||
testData := []*Error{
|
testData := []*Error{
|
||||||
{
|
{
|
||||||
Id: "test",
|
ID: "test",
|
||||||
Code: 500,
|
Code: 500,
|
||||||
Detail: "Internal server error",
|
Detail: "Internal server error",
|
||||||
Status: http.StatusText(500),
|
Status: http.StatusText(500),
|
||||||
@@ -44,7 +44,7 @@ func TestErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range testData {
|
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() {
|
if e.Error() != ne.Error() {
|
||||||
t.Fatalf("Expected %s got %s", 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)
|
t.Fatalf("Expected error got nil %v", pe)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Id != e.Id {
|
if pe.ID != e.ID {
|
||||||
t.Fatalf("Expected %s got %s", e.Id, pe.Id)
|
t.Fatalf("Expected %s got %s", e.ID, pe.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Detail != e.Detail {
|
if pe.Detail != e.Detail {
|
||||||
|
2
event.go
2
event.go
@@ -3,7 +3,7 @@ package micro
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event is used to publish messages to a topic
|
// Event is used to publish messages to a topic
|
||||||
|
@@ -7,12 +7,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/silas/dag"
|
"github.com/silas/dag"
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"go.unistack.org/micro/v3/store"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
type microFlow struct {
|
type microFlow struct {
|
||||||
@@ -20,13 +20,13 @@ type microFlow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type microWorkflow struct {
|
type microWorkflow struct {
|
||||||
id string
|
|
||||||
g *dag.AcyclicGraph
|
|
||||||
init bool
|
|
||||||
sync.RWMutex
|
|
||||||
opts Options
|
opts Options
|
||||||
|
g *dag.AcyclicGraph
|
||||||
steps map[string]Step
|
steps map[string]Step
|
||||||
|
id string
|
||||||
status Status
|
status Status
|
||||||
|
sync.RWMutex
|
||||||
|
init bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *microWorkflow) ID() string {
|
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])
|
w.opts.Logger.Tracef(nctx, "will be executed %v", steps[idx][nidx])
|
||||||
}
|
}
|
||||||
cstep := steps[idx][nidx]
|
cstep := steps[idx][nidx]
|
||||||
|
// nolint: nestif
|
||||||
if len(cstep.Requires()) == 0 {
|
if len(cstep.Requires()) == 0 {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(step Step) {
|
go func(step Step) {
|
||||||
@@ -264,17 +265,16 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
|||||||
}
|
}
|
||||||
cherr <- serr
|
cherr <- serr
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "rsp"), rsp); werr != nil {
|
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "rsp"), rsp); werr != nil {
|
||||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||||
cherr <- werr
|
cherr <- werr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if werr := stepStore.Write(ctx, filepath.Join(step.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
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)
|
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||||
cherr <- werr
|
cherr <- werr
|
||||||
return
|
return
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}(cstep)
|
}(cstep)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -298,16 +298,15 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
|
|||||||
}
|
}
|
||||||
cherr <- serr
|
cherr <- serr
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "rsp"), rsp); werr != nil {
|
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "rsp"), rsp); werr != nil {
|
||||||
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
w.opts.Logger.Errorf(ctx, "store write error: %v", werr)
|
||||||
cherr <- werr
|
cherr <- werr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
if werr := stepStore.Write(ctx, filepath.Join(cstep.ID(), "status"), &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != nil {
|
||||||
cherr <- werr
|
cherr <- werr
|
||||||
return
|
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 {
|
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)
|
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||||
}
|
}
|
||||||
break
|
|
||||||
case err == nil:
|
case err == nil:
|
||||||
if werr := workflowStore.Write(w.opts.Context, "status", &codec.Frame{Data: []byte(StatusSuccess.String())}); werr != 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)
|
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||||
}
|
}
|
||||||
break
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
if werr := workflowStore.Write(w.opts.Context, "status", &codec.Frame{Data: []byte(StatusFailure.String())}); werr != 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)
|
w.opts.Logger.Errorf(w.opts.Context, "store error: %v", werr)
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return eid, err
|
return eid, err
|
||||||
@@ -429,11 +425,11 @@ func (f *microFlow) WorkflowLoad(ctx context.Context, id string) (Workflow, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
type microCallStep struct {
|
type microCallStep struct {
|
||||||
opts StepOptions
|
|
||||||
service string
|
|
||||||
method string
|
|
||||||
rsp *Message
|
rsp *Message
|
||||||
req *Message
|
req *Message
|
||||||
|
service string
|
||||||
|
method string
|
||||||
|
opts StepOptions
|
||||||
status Status
|
status Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,10 +495,12 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu
|
|||||||
rsp := &codec.Frame{}
|
rsp := &codec.Frame{}
|
||||||
copts := []client.CallOption{client.WithRetries(0)}
|
copts := []client.CallOption{client.WithRetries(0)}
|
||||||
if options.Timeout > 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)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -511,10 +509,10 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu
|
|||||||
}
|
}
|
||||||
|
|
||||||
type microPublishStep struct {
|
type microPublishStep struct {
|
||||||
opts StepOptions
|
|
||||||
topic string
|
|
||||||
req *Message
|
req *Message
|
||||||
rsp *Message
|
rsp *Message
|
||||||
|
topic string
|
||||||
|
opts StepOptions
|
||||||
status Status
|
status Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +551,7 @@ func (s *microPublishStep) String() string {
|
|||||||
if s.opts.ID != "" {
|
if s.opts.ID != "" {
|
||||||
return s.opts.ID
|
return s.opts.ID
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s", s.topic)
|
return s.topic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *microPublishStep) Name() string {
|
func (s *microPublishStep) Name() string {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package flow is an interface used for saga pattern microservice workflow
|
// Package flow is an interface used for saga pattern microservice workflow
|
||||||
package flow
|
package flow // import "go.unistack.org/micro/v3/flow"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -4,11 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"go.unistack.org/micro/v3/store"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option func
|
// Option func
|
||||||
@@ -96,8 +96,8 @@ type WorkflowOption func(*WorkflowOptions)
|
|||||||
|
|
||||||
// WorkflowOptions holds workflow options
|
// WorkflowOptions holds workflow options
|
||||||
type WorkflowOptions struct {
|
type WorkflowOptions struct {
|
||||||
ID string
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
ID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkflowID set workflow id
|
// WorkflowID set workflow id
|
||||||
@@ -120,10 +120,10 @@ type ExecuteOptions struct {
|
|||||||
Context context.Context
|
Context context.Context
|
||||||
// Start step
|
// Start step
|
||||||
Start string
|
Start string
|
||||||
// Reverse execution
|
|
||||||
Reverse bool
|
|
||||||
// Timeout for execution
|
// Timeout for execution
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
// Reverse execution
|
||||||
|
Reverse bool
|
||||||
// Async enables async execution
|
// Async enables async execution
|
||||||
Async bool
|
Async bool
|
||||||
}
|
}
|
||||||
@@ -193,10 +193,10 @@ func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StepOptions struct {
|
type StepOptions struct {
|
||||||
ID string
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Requires []string
|
|
||||||
Fallback string
|
Fallback string
|
||||||
|
ID string
|
||||||
|
Requires []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type StepOption func(*StepOptions)
|
type StepOption func(*StepOptions)
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Function is a one time executing Service
|
// Function is a one time executing Service
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFunction(t *testing.T) {
|
func TestFunction(t *testing.T) {
|
||||||
|
9
go.mod
9
go.mod
@@ -1,13 +1,14 @@
|
|||||||
module github.com/unistack-org/micro/v3
|
module go.unistack.org/micro/v3
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ef-ds/deque v1.0.4
|
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/imdario/mergo v0.3.12
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34
|
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4
|
||||||
github.com/unistack-org/micro-proto v0.0.9
|
github.com/unistack-org/micro-proto v0.0.9
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed
|
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
)
|
)
|
||||||
|
13
go.sum
13
go.sum
@@ -2,6 +2,8 @@ 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/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 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.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/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 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
@@ -11,17 +13,22 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
|
|||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
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 h1:vBfVmA5mZhsQa2jr1FOL9nfA37N/jnbBmi5XUfviVTI=
|
||||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||||
|
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=
|
||||||
github.com/unistack-org/micro-proto v0.0.9 h1:KrWLS4FUX7UAWNAilQf70uad6ZPf/0EudeddCXllRVc=
|
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=
|
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-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
|
||||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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/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/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/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-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.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 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
|
@@ -12,11 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type defaultLogger struct {
|
type defaultLogger struct {
|
||||||
enc *json.Encoder
|
enc *json.Encoder
|
||||||
opts Options
|
|
||||||
sync.RWMutex
|
|
||||||
logFunc LogFunc
|
logFunc LogFunc
|
||||||
logfFunc LogfFunc
|
logfFunc LogfFunc
|
||||||
|
opts Options
|
||||||
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init(opts...) should only overwrite provided options
|
// Init(opts...) should only overwrite provided options
|
||||||
@@ -81,7 +81,7 @@ func (l *defaultLogger) Fields(fields ...interface{}) Logger {
|
|||||||
} else if len(fields)%2 != 0 {
|
} else if len(fields)%2 != 0 {
|
||||||
fields = fields[:len(fields)-1]
|
fields = fields[:len(fields)-1]
|
||||||
}
|
}
|
||||||
nl.opts.Fields = append(l.opts.Fields, fields...)
|
nl.opts.Fields = append(nl.opts.Fields, fields...)
|
||||||
return nl
|
return nl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package logger provides a log interface
|
// Package logger provides a log interface
|
||||||
package logger
|
package logger // import "go.unistack.org/micro/v3/logger"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@@ -19,12 +19,12 @@ type Options struct {
|
|||||||
Fields []interface{}
|
Fields []interface{}
|
||||||
// Name holds the logger name
|
// Name holds the logger name
|
||||||
Name string
|
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 logger wrapper that called before actual Log/Logf function
|
||||||
Wrappers []Wrapper
|
Wrappers []Wrapper
|
||||||
|
// The logging level the logger should log
|
||||||
|
Level Level
|
||||||
|
// CallerSkipCount number of frmaes to skip
|
||||||
|
CallerSkipCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOptions creates new options struct
|
// NewOptions creates new options struct
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
package logger
|
package logger // import "go.unistack.org/micro/v3/logger/wrapper"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogFunc function used for Log method
|
// LogFunc function used for Log method
|
||||||
@@ -125,23 +125,29 @@ func getArgs(args []interface{}) []interface{} {
|
|||||||
var err error
|
var err error
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
val := reflect.ValueOf(arg)
|
val := reflect.ValueOf(arg)
|
||||||
switch val.Kind() {
|
if val.Kind() == reflect.Ptr {
|
||||||
case reflect.Ptr:
|
|
||||||
val = val.Elem()
|
val = val.Elem()
|
||||||
}
|
}
|
||||||
narg := arg
|
narg := arg
|
||||||
if val.Kind() == reflect.Struct {
|
if val.Kind() != reflect.Struct {
|
||||||
if narg, err = rutil.Zero(arg); err == nil {
|
nargs = append(nargs, narg)
|
||||||
rutil.CopyDefaults(narg, arg)
|
continue
|
||||||
if flds, ferr := rutil.StructFields(narg); ferr == nil {
|
}
|
||||||
for _, fld := range flds {
|
|
||||||
if tv, ok := fld.Field.Tag.Lookup("logger"); ok && tv == "omit" {
|
if narg, err = rutil.Zero(arg); err != nil {
|
||||||
fld.Value.Set(reflect.Zero(fld.Value.Type()))
|
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)
|
nargs = append(nargs, narg)
|
||||||
}
|
}
|
||||||
return nargs
|
return nargs
|
||||||
|
@@ -5,9 +5,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package metadata is a way of defining message headers
|
// Package metadata is a way of defining message headers
|
||||||
package metadata
|
package metadata // import "go.unistack.org/micro/v3/metadata"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
@@ -107,13 +107,16 @@ func New(size int) Metadata {
|
|||||||
|
|
||||||
// Merge merges metadata to existing metadata, overwriting if specified
|
// Merge merges metadata to existing metadata, overwriting if specified
|
||||||
func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata {
|
func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata {
|
||||||
|
var ok bool
|
||||||
nmd := Copy(omd)
|
nmd := Copy(omd)
|
||||||
for key, val := range mmd {
|
for key, val := range mmd {
|
||||||
if _, ok := nmd[key]; ok && !overwrite {
|
_, ok = nmd[key]
|
||||||
// skip
|
switch {
|
||||||
} else if val != "" {
|
case ok && !overwrite:
|
||||||
|
continue
|
||||||
|
case val != "":
|
||||||
nmd.Set(key, val)
|
nmd.Set(key, val)
|
||||||
} else {
|
case ok && val == "":
|
||||||
nmd.Del(key)
|
nmd.Del(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,10 @@ 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 github.com/unistack-org/micro-proto) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./handler handler/handler.proto"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
|
// import required packages
|
||||||
_ "github.com/unistack-org/micro-proto/api"
|
_ "github.com/unistack-org/micro-proto/api"
|
||||||
|
|
||||||
|
// import required packages
|
||||||
_ "github.com/unistack-org/micro-proto/openapiv2"
|
_ "github.com/unistack-org/micro-proto/openapiv2"
|
||||||
)
|
)
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
package handler
|
package handler // import "go.unistack.org/micro/v3/meter/handler"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// guard to fail early
|
// guard to fail early
|
||||||
|
@@ -6,8 +6,9 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
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 (
|
var (
|
||||||
|
@@ -6,9 +6,10 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
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"
|
||||||
server "github.com/unistack-org/micro/v3/server"
|
codec "go.unistack.org/micro/v3/codec"
|
||||||
|
server "go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
type meterServer struct {
|
type meterServer struct {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package meter is for instrumentation
|
// Package meter is for instrumentation
|
||||||
package meter
|
package meter // import "go.unistack.org/micro/v3/meter"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@@ -28,17 +28,31 @@ var (
|
|||||||
|
|
||||||
// Meter is an interface for collecting and instrumenting metrics
|
// Meter is an interface for collecting and instrumenting metrics
|
||||||
type Meter interface {
|
type Meter interface {
|
||||||
|
// Name returns meter name
|
||||||
Name() string
|
Name() string
|
||||||
|
// Init initialize meter
|
||||||
Init(opts ...Option) error
|
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
|
Counter(name string, labels ...string) Counter
|
||||||
|
// FloatCounter get or create float counter
|
||||||
FloatCounter(name string, labels ...string) FloatCounter
|
FloatCounter(name string, labels ...string) FloatCounter
|
||||||
|
// Gauge get or create gauge
|
||||||
Gauge(name string, fn func() float64, labels ...string) Gauge
|
Gauge(name string, fn func() float64, labels ...string) Gauge
|
||||||
|
// Set create new meter metrics set
|
||||||
Set(opts ...Option) Meter
|
Set(opts ...Option) Meter
|
||||||
|
// Histogram get or create histogram
|
||||||
Histogram(name string, labels ...string) Histogram
|
Histogram(name string, labels ...string) Histogram
|
||||||
|
// Summary get or create summary
|
||||||
Summary(name string, labels ...string) 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
|
SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) Summary
|
||||||
|
// Write writes metrics to io.Writer
|
||||||
Write(w io.Writer, opts ...Option) error
|
Write(w io.Writer, opts ...Option) error
|
||||||
|
// Options returns meter options
|
||||||
Options() Options
|
Options() Options
|
||||||
|
// String return meter type
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ func TestBuildLabels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := []testData{
|
data := []testData{
|
||||||
testData{
|
{
|
||||||
src: []string{"zerolabel", "value3", "firstlabel", "value2"},
|
src: []string{"zerolabel", "value3", "firstlabel", "value2"},
|
||||||
dst: []string{"firstlabel", "value2", "zerolabel", "value3"},
|
dst: []string{"firstlabel", "value2", "zerolabel", "value3"},
|
||||||
},
|
},
|
||||||
@@ -48,15 +48,15 @@ func TestBuildLabels(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildName(t *testing.T) {
|
func TestBuildName(t *testing.T) {
|
||||||
data := map[string][]string{
|
data := map[string][]string{
|
||||||
`my_metric{firstlabel="value2",zerolabel="value3"}`: []string{
|
`my_metric{firstlabel="value2",zerolabel="value3"}`: {
|
||||||
"my_metric",
|
"my_metric",
|
||||||
"zerolabel", "value3", "firstlabel", "value2",
|
"zerolabel", "value3", "firstlabel", "value2",
|
||||||
},
|
},
|
||||||
`my_metric{broker="broker2",register="mdns",server="tcp"}`: []string{
|
`my_metric{broker="broker2",register="mdns",server="tcp"}`: {
|
||||||
"my_metric",
|
"my_metric",
|
||||||
"broker", "broker1", "broker", "broker2", "server", "http", "server", "tcp", "register", "mdns",
|
"broker", "broker1", "broker", "broker2", "server", "http", "server", "tcp", "register", "mdns",
|
||||||
},
|
},
|
||||||
`my_metric{aaa="aaa"}`: []string{
|
`my_metric{aaa="aaa"}`: {
|
||||||
"my_metric",
|
"my_metric",
|
||||||
"aaa", "aaa",
|
"aaa", "aaa",
|
||||||
},
|
},
|
||||||
|
@@ -15,6 +15,15 @@ func NewMeter(opts ...Option) Meter {
|
|||||||
return &noopMeter{opts: NewOptions(opts...)}
|
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 {
|
func (r *noopMeter) Name() string {
|
||||||
return r.opts.Name
|
return r.opts.Name
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ package meter
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option powers the configuration for metrics implementations:
|
// Option powers the configuration for metrics implementations:
|
||||||
@@ -51,6 +51,20 @@ func NewOptions(opt ...Option) Options {
|
|||||||
return opts
|
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
|
// Context sets the metrics context
|
||||||
func Context(ctx context.Context) Option {
|
func Context(ctx context.Context) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
package wrapper
|
package wrapper // import "go.unistack.org/micro/v3/meter/wrapper"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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 is for creating internetworks
|
||||||
package network
|
package network // import "go.unistack.org/micro/v3/network"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error is network node errors
|
// Error is network node errors
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
"go.unistack.org/micro/v3/network/tunnel"
|
||||||
"github.com/unistack-org/micro/v3/proxy"
|
"go.unistack.org/micro/v3/proxy"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option func
|
// Option func
|
||||||
@@ -27,8 +27,8 @@ type Options struct {
|
|||||||
Tracer tracer.Tracer
|
Tracer tracer.Tracer
|
||||||
// Tunnel used for transfer data
|
// Tunnel used for transfer data
|
||||||
Tunnel tunnel.Tunnel
|
Tunnel tunnel.Tunnel
|
||||||
// Id of the node
|
// ID of the node
|
||||||
Id string
|
ID string
|
||||||
// Name of the network
|
// Name of the network
|
||||||
Name string
|
Name string
|
||||||
// Address to bind to
|
// Address to bind to
|
||||||
@@ -39,10 +39,10 @@ type Options struct {
|
|||||||
Nodes []string
|
Nodes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id sets the id of the network node
|
// ID sets the id of the network node
|
||||||
func Id(id string) Option {
|
func ID(id string) Option {
|
||||||
return func(o *Options) {
|
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
|
// NewOptions returns network default options
|
||||||
func NewOptions(opts ...Option) Options {
|
func NewOptions(opts ...Option) Options {
|
||||||
options := Options{
|
options := Options{
|
||||||
Id: id.Must(),
|
ID: id.Must(),
|
||||||
Name: "go.micro",
|
Name: "go.micro",
|
||||||
Address: ":0",
|
Address: ":0",
|
||||||
Logger: logger.DefaultLogger,
|
Logger: logger.DefaultLogger,
|
||||||
|
@@ -8,9 +8,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
maddr "github.com/unistack-org/micro/v3/util/addr"
|
maddr "go.unistack.org/micro/v3/util/addr"
|
||||||
mnet "github.com/unistack-org/micro/v3/util/net"
|
mnet "go.unistack.org/micro/v3/util/net"
|
||||||
"github.com/unistack-org/micro/v3/util/rand"
|
"go.unistack.org/micro/v3/util/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
type memorySocket struct {
|
type memorySocket struct {
|
||||||
|
@@ -16,12 +16,14 @@ func TestMemoryTransport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
|
cherr := make(chan error, 1)
|
||||||
// accept
|
// accept
|
||||||
go func() {
|
go func() {
|
||||||
if err := l.Accept(func(sock Socket) {
|
if nerr := l.Accept(func(sock Socket) {
|
||||||
for {
|
for {
|
||||||
var m Message
|
var m Message
|
||||||
if err := sock.Recv(&m); err != nil {
|
if rerr := sock.Recv(&m); rerr != nil {
|
||||||
|
cherr <- rerr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
||||||
@@ -30,11 +32,12 @@ func TestMemoryTransport(t *testing.T) {
|
|||||||
if cerr := sock.Send(&Message{
|
if cerr := sock.Send(&Message{
|
||||||
Body: []byte(`pong`),
|
Body: []byte(`pong`),
|
||||||
}); cerr != nil {
|
}); cerr != nil {
|
||||||
|
cherr <- cerr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}); err != nil {
|
}); nerr != nil {
|
||||||
t.Fatalf("Unexpected error accepting %v", err)
|
cherr <- err
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -45,19 +48,24 @@ func TestMemoryTransport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
// send <=> receive
|
select {
|
||||||
for i := 0; i < 3; i++ {
|
case err := <-cherr:
|
||||||
if err := c.Send(&Message{
|
t.Fatal(err)
|
||||||
Body: []byte(`ping`),
|
default:
|
||||||
}); err != nil {
|
// send <=> receive
|
||||||
return
|
for i := 0; i < 3; i++ {
|
||||||
}
|
if err := c.Send(&Message{
|
||||||
var m Message
|
Body: []byte(`ping`),
|
||||||
if err := c.Recv(&m); err != nil {
|
}); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
var m Message
|
||||||
t.Logf("Client Received %s", string(m.Body))
|
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"
|
"crypto/tls"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options struct holds the transport options
|
// Options struct holds the transport options
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package transport is an interface for synchronous connection based communication
|
// Package transport is an interface for synchronous connection based communication
|
||||||
package transport
|
package transport // import "go.unistack.org/micro/v3/network/transport"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
// Package broker is a tunnel broker
|
// Package broker is a tunnel broker
|
||||||
package broker
|
package broker // import "go.unistack.org/micro/v3/network/tunnel/broker"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
"go.unistack.org/micro/v3/network/tunnel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tunBroker struct {
|
type tunBroker struct {
|
||||||
@@ -34,9 +34,9 @@ type tunBatchSubscriber struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type tunEvent struct {
|
type tunEvent struct {
|
||||||
|
err error
|
||||||
message *broker.Message
|
message *broker.Message
|
||||||
topic string
|
topic string
|
||||||
err error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to access tunnel from options context
|
// 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)
|
topic, _ := msg.Header.Get(metadata.HeaderTopic)
|
||||||
c, ok := topicMap[topic]
|
c, ok := topicMap[topic]
|
||||||
if !ok {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,9 @@ func (t *tunBatchSubscriber) run() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
// handle the message
|
// handle the message
|
||||||
go t.handler(evts)
|
go func() {
|
||||||
|
_ = t.handler(evts)
|
||||||
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,13 +237,15 @@ func (t *tunSubscriber) run() {
|
|||||||
c.Close()
|
c.Close()
|
||||||
|
|
||||||
// handle the message
|
// handle the message
|
||||||
go t.handler(&tunEvent{
|
go func() {
|
||||||
topic: t.topic,
|
_ = t.handler(&tunEvent{
|
||||||
message: &broker.Message{
|
topic: t.topic,
|
||||||
Header: m.Header,
|
message: &broker.Message{
|
||||||
Body: m.Body,
|
Header: m.Header,
|
||||||
},
|
Body: m.Body,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,11 +3,11 @@ package tunnel
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package transport
|
package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
"go.unistack.org/micro/v3/network/tunnel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tunListener struct {
|
type tunListener struct {
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
// Package transport provides a tunnel transport
|
// Package transport provides a tunnel transport
|
||||||
package transport
|
package transport // import "go.unistack.org/micro/v3/network/tunnel/transport"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
"github.com/unistack-org/micro/v3/network/tunnel"
|
"go.unistack.org/micro/v3/network/tunnel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tunTransport struct {
|
type tunTransport struct {
|
||||||
@@ -37,7 +37,7 @@ func (t *tunTransport) Init(opts ...transport.Option) error {
|
|||||||
// get the transport
|
// get the transport
|
||||||
tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport)
|
tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport)
|
||||||
if ok {
|
if ok {
|
||||||
tun.Init(tunnel.Transport(tr))
|
_ = tun.Init(tunnel.Transport(tr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the tunnel
|
// set the tunnel
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
// Package tunnel provides gre network tunnelling
|
// Package tunnel provides gre network tunnelling
|
||||||
package tunnel
|
package tunnel // import "go.unistack.org/micro/v3/network/transport/tunnel"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/network/transport"
|
"go.unistack.org/micro/v3/network/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultTunnel contains default tunnel implementation
|
// DefaultTunnel contains default tunnel implementation
|
||||||
|
24
options.go
24
options.go
@@ -5,18 +5,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/auth"
|
"go.unistack.org/micro/v3/auth"
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/config"
|
"go.unistack.org/micro/v3/config"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"go.unistack.org/micro/v3/store"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options for micro service
|
// Options for micro service
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package http enables the http profiler
|
// Package http enables the http profiler
|
||||||
package http
|
package http // import "go.unistack.org/micro/v3/profiler/http"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
profile "github.com/unistack-org/micro/v3/profiler"
|
profile "go.unistack.org/micro/v3/profiler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpProfile struct {
|
type httpProfile struct {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package pprof provides a pprof profiler which writes output to /tmp/[name].{cpu,mem}.pprof
|
// 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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
profile "github.com/unistack-org/micro/v3/profiler"
|
profile "go.unistack.org/micro/v3/profiler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type profiler struct {
|
type profiler struct {
|
||||||
@@ -31,7 +31,7 @@ func (p *profiler) writeHeap(f *os.File) {
|
|||||||
select {
|
select {
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
pprof.WriteHeapProfile(f)
|
_ = pprof.WriteHeapProfile(f)
|
||||||
case <-p.exit:
|
case <-p.exit:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package profiler is for profilers
|
// Package profiler is for profilers
|
||||||
package profiler
|
package profiler // import "go.unistack.org/micro/v3/profiler"
|
||||||
|
|
||||||
// Profiler interface
|
// Profiler interface
|
||||||
type Profiler interface {
|
type Profiler interface {
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options for proxy
|
// Options for proxy
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
// Package proxy is a transparent proxy built on the micro/server
|
// Package proxy is a transparent proxy built on the micro/server
|
||||||
package proxy
|
package proxy // import "go.unistack.org/micro/v3/proxy"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultEndpoint holds default proxy address
|
// DefaultEndpoint holds default proxy address
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExtractValue from reflect.Type from specified depth
|
// ExtractValue from reflect.Type from specified depth
|
||||||
|
@@ -6,8 +6,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -5,9 +5,9 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options holds options for register
|
// Options holds options for register
|
||||||
@@ -44,7 +44,7 @@ func NewOptions(opts ...Option) Options {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: golint
|
// nolint: golint,revive
|
||||||
// RegisterOptions holds options for register method
|
// RegisterOptions holds options for register method
|
||||||
type RegisterOptions struct {
|
type RegisterOptions struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
@@ -197,7 +197,7 @@ func TLSConfig(t *tls.Config) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: golint
|
// nolint: golint,revive
|
||||||
// RegisterAttempts specifies register atempts count
|
// RegisterAttempts specifies register atempts count
|
||||||
func RegisterAttempts(t int) RegisterOption {
|
func RegisterAttempts(t int) RegisterOption {
|
||||||
return func(o *RegisterOptions) {
|
return func(o *RegisterOptions) {
|
||||||
@@ -205,7 +205,7 @@ func RegisterAttempts(t int) RegisterOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: golint
|
// nolint: golint,revive
|
||||||
// RegisterTTL specifies register ttl
|
// RegisterTTL specifies register ttl
|
||||||
func RegisterTTL(t time.Duration) RegisterOption {
|
func RegisterTTL(t time.Duration) RegisterOption {
|
||||||
return func(o *RegisterOptions) {
|
return func(o *RegisterOptions) {
|
||||||
@@ -213,7 +213,7 @@ func RegisterTTL(t time.Duration) RegisterOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: golint
|
// nolint: golint,revive
|
||||||
// RegisterContext sets the register context
|
// RegisterContext sets the register context
|
||||||
func RegisterContext(ctx context.Context) RegisterOption {
|
func RegisterContext(ctx context.Context) RegisterOption {
|
||||||
return func(o *RegisterOptions) {
|
return func(o *RegisterOptions) {
|
||||||
@@ -221,7 +221,7 @@ func RegisterContext(ctx context.Context) RegisterOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: golint
|
// nolint: golint,revive
|
||||||
// RegisterDomain secifies register domain
|
// RegisterDomain secifies register domain
|
||||||
func RegisterDomain(d string) RegisterOption {
|
func RegisterDomain(d string) RegisterOption {
|
||||||
return func(o *RegisterOptions) {
|
return func(o *RegisterOptions) {
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package register is an interface for service discovery
|
// Package register is an interface for service discovery
|
||||||
package register
|
package register // import "go.unistack.org/micro/v3/register"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -68,8 +68,8 @@ type Endpoint struct {
|
|||||||
// Option func signature
|
// Option func signature
|
||||||
type Option func(*Options)
|
type Option func(*Options)
|
||||||
|
|
||||||
|
// nolint: golint,revive
|
||||||
// RegisterOption option is used to register service
|
// RegisterOption option is used to register service
|
||||||
// nolint: golint
|
|
||||||
type RegisterOption func(*RegisterOptions)
|
type RegisterOption func(*RegisterOptions)
|
||||||
|
|
||||||
// WatchOption option is used to watch service changes
|
// WatchOption option is used to watch service changes
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package dns resolves names to dns records
|
// Package dns resolves names to dns records
|
||||||
package dns
|
package dns // import "go.unistack.org/micro/v3/resolver/dns"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/resolver"
|
"go.unistack.org/micro/v3/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver is a DNS network resolve
|
// Resolver is a DNS network resolve
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package dnssrv resolves names to dns srv records
|
// Package dnssrv resolves names to dns srv records
|
||||||
package dnssrv
|
package dnssrv // import "go.unistack.org/micro/v3/resolver/dnssrv"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/resolver"
|
"go.unistack.org/micro/v3/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver is a DNS network resolve
|
// Resolver is a DNS network resolve
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package http resolves names to network addresses using a http request
|
// Package http resolves names to network addresses using a http request
|
||||||
package http
|
package http // import "go.unistack.org/micro/v3/resolver/http"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -8,9 +8,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/resolver"
|
"go.unistack.org/micro/v3/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint: golint,revive
|
||||||
// HTTPResolver is a HTTP network resolver
|
// HTTPResolver is a HTTP network resolver
|
||||||
type HTTPResolver struct {
|
type HTTPResolver struct {
|
||||||
// Proto if not set, defaults to http
|
// Proto if not set, defaults to http
|
||||||
@@ -53,6 +54,7 @@ func (r *HTTPResolver) Resolve(name string) ([]*resolver.Record, error) {
|
|||||||
q.Set("name", name)
|
q.Set("name", name)
|
||||||
uri.RawQuery = q.Encode()
|
uri.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
// nolint: noctx
|
||||||
rsp, err := http.Get(uri.String())
|
rsp, err := http.Get(uri.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
// Package noop is a noop resolver
|
// Package noop is a noop resolver
|
||||||
package noop
|
package noop // import "go.unistack.org/micro/v3/resolver/noop"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/resolver"
|
"go.unistack.org/micro/v3/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver contains noop resolver
|
// Resolver contains noop resolver
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
// Package register resolves names using the micro register
|
// Package register resolves names using the micro register
|
||||||
package register
|
package register // import "go.unistack.org/micro/v3/resolver/registry"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/resolver"
|
"go.unistack.org/micro/v3/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Resolver is a register network resolver
|
// Resolver is a register network resolver
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package resolver resolves network names to addresses
|
// 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
|
// Resolver is network resolver. It's used to find network nodes
|
||||||
// via the name to connect to. This is done based on Network.Name().
|
// 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 is a static resolver
|
||||||
package static
|
package static // import "go.unistack.org/micro/v3/resolver/static"
|
||||||
|
|
||||||
import (
|
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
|
// 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
|
// 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)
|
host, port, err := net.SplitHostPort(options.Service)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
var ips []string
|
||||||
// lookup the service using A records
|
// lookup the service using A records
|
||||||
ips, err := net.LookupHost(host)
|
ips, err = net.LookupHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,9 @@ package router
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
"github.com/unistack-org/micro/v3/util/id"
|
"go.unistack.org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options are router options
|
// Options are router options
|
||||||
@@ -16,15 +16,15 @@ type Options struct {
|
|||||||
Name string
|
Name string
|
||||||
Gateway string
|
Gateway string
|
||||||
Network string
|
Network string
|
||||||
Id string
|
ID string
|
||||||
Address string
|
Address string
|
||||||
Precache bool
|
Precache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id sets Router Id
|
// ID sets Router Id
|
||||||
func Id(id string) Option {
|
func ID(id string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Id = id
|
o.ID = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ func Name(n string) Option {
|
|||||||
// NewOptions returns router default options
|
// NewOptions returns router default options
|
||||||
func NewOptions(opts ...Option) Options {
|
func NewOptions(opts ...Option) Options {
|
||||||
options := Options{
|
options := Options{
|
||||||
Id: id.Must(),
|
ID: id.Must(),
|
||||||
Network: DefaultNetwork,
|
Network: DefaultNetwork,
|
||||||
Register: register.DefaultRegister,
|
Register: register.DefaultRegister,
|
||||||
Logger: logger.DefaultLogger,
|
Logger: logger.DefaultLogger,
|
||||||
|
@@ -3,7 +3,7 @@ package router
|
|||||||
import (
|
import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// Package router provides a network routing control plane
|
// Package router provides a network routing control plane
|
||||||
package router
|
package router // import "go.unistack.org/micro/v3/router"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@@ -38,8 +38,8 @@ func (t EventType) String() string {
|
|||||||
type Event struct {
|
type Event struct {
|
||||||
// Timestamp is event timestamp
|
// Timestamp is event timestamp
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
// Id of the event
|
// ID of the event
|
||||||
Id string
|
ID string
|
||||||
// Route is table route
|
// Route is table route
|
||||||
Route Route
|
Route Route
|
||||||
// Type defines type of event
|
// Type defines type of event
|
||||||
|
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options configure runtime
|
// Options configure runtime
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user