Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

many lint fixes #71

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Doc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/unistack-org/micro/v3?tab=overview) [![Status](https://github.com/unistack-org/micro/workflows/build/badge.svg?branch=master)](https://github.com/unistack-org/micro/actions?query=workflow%3Abuild+branch%3Amaster+event%3Apush) [![Lint](https://goreportcard.com/badge/github.com/unistack-org/micro)](https://goreportcard.com/report/github.com/unistack-org/micro) [![Slack](https://img.shields.io/static/v1?label=micro&message=slack&color=blueviolet)](https://unistack-org.slack.com/messages/default)
# Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Doc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/unistack-org/micro/v3?tab=overview) [![Status](https://github.com/unistack-org/micro/workflows/build/badge.svg?branch=master)](https://github.com/unistack-org/micro/actions?query=workflow%3Abuild+branch%3Amaster+event%3Apush) [![Lint](https://goreportcard.com/report/go.unistack.org/micro/v3)](https://goreportcard.com/report/go.unistack.org/micro/v3) [![Slack](https://img.shields.io/static/v1?label=micro&message=slack&color=blueviolet)](https://unistack-org.slack.com/messages/default)

Micro is a standard library for microservices.

Expand Down
6 changes: 6 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ type Stream interface {
Send(msg interface{}) error
// Recv will decode and read a response
Recv(msg interface{}) error
// SendMsg will encode and send a request
SendMsg(msg interface{}) error
// RecvMsg will decode and read a response
RecvMsg(msg interface{}) error
// Error returns the stream error
Error() error
// Close closes the stream
Close() error
// CloseSend closes the send direction of the stream
CloseSend() error
}

// Option used by the Client
Expand Down
12 changes: 12 additions & 0 deletions client/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ func (n *noopStream) Recv(interface{}) error {
return nil
}

func (n *noopStream) SendMsg(interface{}) error {
return nil
}

func (n *noopStream) RecvMsg(interface{}) error {
return nil
}

func (n *noopStream) Error() error {
return nil
}
Expand All @@ -127,6 +135,10 @@ func (n *noopStream) Close() error {
return nil
}

func (n *noopStream) CloseSend() error {
return nil
}

func (n *noopMessage) Topic() string {
return n.topic
}
Expand Down
3 changes: 3 additions & 0 deletions flow/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu
return eid, err
}

// NewFlow create new flow
func NewFlow(opts ...Option) Flow {
options := NewOptions(opts...)
return &microFlow{opts: options}
Expand Down Expand Up @@ -574,11 +575,13 @@ func (s *microPublishStep) Execute(ctx context.Context, req *Message, opts ...Ex
return nil, nil
}

// NewCallStep create new step with client.Call
func NewCallStep(service string, name string, method string, opts ...StepOption) Step {
options := NewStepOptions(opts...)
return &microCallStep{service: service, method: name + "." + method, opts: options}
}

// NewPublishStep create new step with client.Publish
func NewPublishStep(topic string, opts ...StepOption) Step {
options := NewStepOptions(opts...)
return &microPublishStep{topic: topic, opts: options}
Expand Down
21 changes: 19 additions & 2 deletions flow/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Client(c client.Client) Option {

// Context specifies a context for the service.
// Can be used to signal shutdown of the flow
// Can be used for extra option values.
// or can be used for extra option values.
func Context(ctx context.Context) Option {
return func(o *Options) {
o.Context = ctx
Expand All @@ -91,7 +91,7 @@ func Store(s store.Store) Option {
}
}

// WorflowOption signature
// WorflowOption func signature
type WorkflowOption func(*WorkflowOptions)

// WorkflowOptions holds workflow options
Expand All @@ -107,6 +107,7 @@ func WorkflowID(id string) WorkflowOption {
}
}

// ExecuteOptions holds execute options
type ExecuteOptions struct {
// Client holds the client.Client
Client client.Client
Expand All @@ -128,56 +129,66 @@ type ExecuteOptions struct {
Async bool
}

// ExecuteOption func signature
type ExecuteOption func(*ExecuteOptions)

// ExecuteClient pass client.Client to ExecuteOption
func ExecuteClient(c client.Client) ExecuteOption {
return func(o *ExecuteOptions) {
o.Client = c
}
}

// ExecuteTracer pass tracer.Tracer to ExecuteOption
func ExecuteTracer(t tracer.Tracer) ExecuteOption {
return func(o *ExecuteOptions) {
o.Tracer = t
}
}

// ExecuteLogger pass logger.Logger to ExecuteOption
func ExecuteLogger(l logger.Logger) ExecuteOption {
return func(o *ExecuteOptions) {
o.Logger = l
}
}

// ExecuteMeter pass meter.Meter to ExecuteOption
func ExecuteMeter(m meter.Meter) ExecuteOption {
return func(o *ExecuteOptions) {
o.Meter = m
}
}

// ExecuteContext pass context.Context ot ExecuteOption
func ExecuteContext(ctx context.Context) ExecuteOption {
return func(o *ExecuteOptions) {
o.Context = ctx
}
}

// ExecuteReverse says that dag must be run in reverse order
func ExecuteReverse(b bool) ExecuteOption {
return func(o *ExecuteOptions) {
o.Reverse = b
}
}

// ExecuteTimeout pass timeout time.Duration for execution
func ExecuteTimeout(td time.Duration) ExecuteOption {
return func(o *ExecuteOptions) {
o.Timeout = td
}
}

// ExecuteAsync says that caller does not wait for execution complete
func ExecuteAsync(b bool) ExecuteOption {
return func(o *ExecuteOptions) {
o.Async = b
}
}

// NewExecuteOptions create new ExecuteOptions struct
func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions {
options := ExecuteOptions{
Client: client.DefaultClient,
Expand All @@ -192,15 +203,18 @@ func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions {
return options
}

// StepOptions holds step options
type StepOptions struct {
Context context.Context
Fallback string
ID string
Requires []string
}

// StepOption func signature
type StepOption func(*StepOptions)

// NewStepOptions create new StepOptions struct
func NewStepOptions(opts ...StepOption) StepOptions {
options := StepOptions{
Context: context.Background(),
Expand All @@ -211,18 +225,21 @@ func NewStepOptions(opts ...StepOption) StepOptions {
return options
}

// StepID sets the step id for dag
func StepID(id string) StepOption {
return func(o *StepOptions) {
o.ID = id
}
}

// StepRequires specifies required steps
func StepRequires(steps ...string) StepOption {
return func(o *StepOptions) {
o.Requires = steps
}
}

// StepFallback set the step to run on error
func StepFallback(step string) StepOption {
return func(o *StepOptions) {
o.Fallback = step
Expand Down
1 change: 1 addition & 0 deletions function.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package micro
Expand Down
1 change: 1 addition & 0 deletions function_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package micro
Expand Down
2 changes: 2 additions & 0 deletions logger/stdlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type stdLogger struct {
level Level
}

// NewStdLogger returns new *log.Logger baked by logger.Logger implementation
func NewStdLogger(l Logger, level Level) *log.Logger {
return log.New(&stdLogger{l: l, level: level}, "" /* prefix */, 0 /* flags */)
}
Expand All @@ -20,6 +21,7 @@ func (sl *stdLogger) Write(p []byte) (int, error) {
return len(p), nil
}

// RedirectStdLogger replace *log.Logger with logger.Logger implementation
func RedirectStdLogger(l Logger, level Level) func() {
flags := log.Flags()
prefix := log.Prefix()
Expand Down
56 changes: 28 additions & 28 deletions logger/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,104 +20,104 @@ type Wrapper interface {
Logf(LogfFunc) LogfFunc
}

var _ Logger = &OmitLogger{}
var _ Logger = &omitLogger{}

type OmitLogger struct {
type omitLogger struct {
l Logger
}

func NewOmitLogger(l Logger) Logger {
return &OmitLogger{l: l}
return &omitLogger{l: l}
}

func (w *OmitLogger) Init(opts ...Option) error {
func (w *omitLogger) Init(opts ...Option) error {
return w.l.Init(append(opts, WrapLogger(NewOmitWrapper()))...)
}

func (w *OmitLogger) V(level Level) bool {
func (w *omitLogger) V(level Level) bool {
return w.l.V(level)
}

func (w *OmitLogger) Level(level Level) {
func (w *omitLogger) Level(level Level) {
w.l.Level(level)
}

func (w *OmitLogger) Clone(opts ...Option) Logger {
func (w *omitLogger) Clone(opts ...Option) Logger {
return w.l.Clone(opts...)
}

func (w *OmitLogger) Options() Options {
func (w *omitLogger) Options() Options {
return w.l.Options()
}

func (w *OmitLogger) Fields(fields ...interface{}) Logger {
func (w *omitLogger) Fields(fields ...interface{}) Logger {
return w.l.Fields(fields...)
}

func (w *OmitLogger) Info(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Info(ctx context.Context, args ...interface{}) {
w.l.Info(ctx, args...)
}

func (w *OmitLogger) Trace(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Trace(ctx context.Context, args ...interface{}) {
w.l.Trace(ctx, args...)
}

func (w *OmitLogger) Debug(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Debug(ctx context.Context, args ...interface{}) {
w.l.Debug(ctx, args...)
}

func (w *OmitLogger) Warn(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Warn(ctx context.Context, args ...interface{}) {
w.l.Warn(ctx, args...)
}

func (w *OmitLogger) Error(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Error(ctx context.Context, args ...interface{}) {
w.l.Error(ctx, args...)
}

func (w *OmitLogger) Fatal(ctx context.Context, args ...interface{}) {
func (w *omitLogger) Fatal(ctx context.Context, args ...interface{}) {
w.l.Fatal(ctx, args...)
}

func (w *OmitLogger) Infof(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Infof(ctx context.Context, msg string, args ...interface{}) {
w.l.Infof(ctx, msg, args...)
}

func (w *OmitLogger) Tracef(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Tracef(ctx context.Context, msg string, args ...interface{}) {
w.l.Tracef(ctx, msg, args...)
}

func (w *OmitLogger) Debugf(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Debugf(ctx context.Context, msg string, args ...interface{}) {
w.l.Debugf(ctx, msg, args...)
}

func (w *OmitLogger) Warnf(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Warnf(ctx context.Context, msg string, args ...interface{}) {
w.l.Warnf(ctx, msg, args...)
}

func (w *OmitLogger) Errorf(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Errorf(ctx context.Context, msg string, args ...interface{}) {
w.l.Errorf(ctx, msg, args...)
}

func (w *OmitLogger) Fatalf(ctx context.Context, msg string, args ...interface{}) {
func (w *omitLogger) Fatalf(ctx context.Context, msg string, args ...interface{}) {
w.l.Fatalf(ctx, msg, args...)
}

func (w *OmitLogger) Log(ctx context.Context, level Level, args ...interface{}) {
func (w *omitLogger) Log(ctx context.Context, level Level, args ...interface{}) {
w.l.Log(ctx, level, args...)
}

func (w *OmitLogger) Logf(ctx context.Context, level Level, msg string, args ...interface{}) {
func (w *omitLogger) Logf(ctx context.Context, level Level, msg string, args ...interface{}) {
w.l.Logf(ctx, level, msg, args...)
}

func (w *OmitLogger) String() string {
func (w *omitLogger) String() string {
return w.l.String()
}

type OmitWrapper struct{}
type omitWrapper struct{}

func NewOmitWrapper() Wrapper {
return &OmitWrapper{}
return &omitWrapper{}
}

func getArgs(args []interface{}) []interface{} {
Expand Down Expand Up @@ -153,13 +153,13 @@ func getArgs(args []interface{}) []interface{} {
return nargs
}

func (w *OmitWrapper) Log(fn LogFunc) LogFunc {
func (w *omitWrapper) Log(fn LogFunc) LogFunc {
return func(ctx context.Context, level Level, args ...interface{}) {
fn(ctx, level, getArgs(args)...)
}
}

func (w *OmitWrapper) Logf(fn LogfFunc) LogfFunc {
func (w *omitWrapper) Logf(fn LogfFunc) LogfFunc {
return func(ctx context.Context, level Level, msg string, args ...interface{}) {
fn(ctx, level, msg, getArgs(args)...)
}
Expand Down
2 changes: 1 addition & 1 deletion meter/handler/handler_micro.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion meter/handler/handler_micro_http.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading