add multi user config field, fixup request-id generation
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -7,46 +7,53 @@ import (
|
||||
mtime "go.unistack.org/micro/v3/util/time"
|
||||
)
|
||||
|
||||
type Meter struct {
|
||||
type AppConfig struct {
|
||||
MultiUser bool `json:"multi_user,omitempty" yaml:"multi_user,omitempty"`
|
||||
}
|
||||
|
||||
type MeterConfig struct {
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Meter *Meter `json:"meter,omitempty" yaml:"meter,omitempty"`
|
||||
Checks []*Check `json:"checks,omitempty" yaml:"checks,omitempty"`
|
||||
Meter *MeterConfig `json:"meter,omitempty" yaml:"meter,omitempty"`
|
||||
Checks []*CheckConfig `json:"checks,omitempty" yaml:"checks,omitempty"`
|
||||
}
|
||||
|
||||
type Check struct {
|
||||
type CheckConfig struct {
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Tasks []*Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`
|
||||
Tasks []*TaskConfig `json:"tasks,omitempty" yaml:"tasks,omitempty"`
|
||||
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
||||
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
||||
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
|
||||
Method string `json:"method,omitempty" yaml:"method,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
|
||||
Method string `json:"method,omitempty" yaml:"method,omitempty"`
|
||||
}
|
||||
|
||||
type GRPCConfig struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Protoset string `json:"protoset,omitempty" yaml:"protoset,omitempty"`
|
||||
}
|
||||
|
||||
type GraphQLConfig struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
Data string `json:"data,omitempty" yaml:"data,omitempty"`
|
||||
Addr string `json:"addr,omitempty" yaml:"addr,omitempty"`
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
type TaskConfig struct {
|
||||
HTTP *HTTPConfig `json:"http,omitempty" yaml:"http,omitempty"`
|
||||
GRPC *GRPCConfig `json:"grpc,omitempty" yaml:"grpc,omitempty"`
|
||||
GraphQL *GraphQLConfig `json:"graphql,omitempty" yaml:"graphql"`
|
||||
|
@@ -5,18 +5,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
func Call(ctx context.Context, rquid string, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
var err error
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to generate x-request-id", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Call(ctx, req, rsp,
|
||||
client.WithAddress(addr),
|
||||
@@ -24,7 +18,7 @@ func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td
|
||||
// client.WithContentType("application/json"),
|
||||
)
|
||||
if err != nil {
|
||||
l.Error(ctx, "call failed", "x-request-id", uid.String(), err)
|
||||
l.Error(ctx, "call failed", "x-request-id", rquid, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@@ -4,18 +4,12 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
func Call(ctx context.Context, rquid string, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
var err error
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to generate x-request-id", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Call(ctx, req, rsp,
|
||||
client.WithAddress(addr),
|
||||
@@ -23,7 +17,8 @@ func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td
|
||||
// client.WithContentType("application/json"),
|
||||
)
|
||||
if err != nil {
|
||||
l.Error(ctx, "call failed", "x-request-id", uid.String(), err)
|
||||
// httpcli.GetError(err)
|
||||
l.Error(ctx, "call failed", "x-request-id", rquid, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user