service

package
v1.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServiceOverload          = errors.Unavailable("fns: service is overload").WithMeta("fns", "overload")
	ErrTooEarly                 = errors.New(http.StatusTooEarly, "***TOO EARLY***", "fns: service is not ready, try later again")
	ErrUnavailable              = errors.Unavailable("fns: service is closed")
	ErrDeviceId                 = errors.Warning("fns: device id was required")
	ErrNotFound                 = errors.NotFound("fns: no handlers accept request")
	ErrTooMayRequest            = errors.New(http.StatusTooManyRequests, "***TOO MANY REQUEST***", "fns: too may request, try again later.")
	ErrSignatureLost            = errors.New(488, "***SIGNATURE LOST***", "X-Fns-Signature was required")
	ErrSignatureUnverified      = errors.New(458, "***SIGNATURE INVALID***", "X-Fns-Signature was invalid")
	ErrSharedSecretKeyNotAgreed = errors.New(448, "***SHARED SECRET NOT AGREED***", "shared secret key was not agreed")
	ErrSharedSecretKeyOutOfDate = errors.New(468, "***SHARED SECRET KEY OUT OF DATE***", "need to recreate shared secret key")
)

Functions

func Abort added in v1.0.10

func Abort()

func CacheControl added in v1.0.23

func CacheControl(ctx context.Context, result interface{}, ttl time.Duration)

CacheControl use `@cache {ttl}` in service function

func CanAccessInternal

func CanAccessInternal(ctx context.Context) (ok bool)

func DataPlate added in v1.0.10

func DataPlate(ctx context.Context) (appId string, appName string, appVersion versions.Version)

func DefaultConfigRetrieverOption added in v0.14.0

func DefaultConfigRetrieverOption() (option configures.RetrieverOption)

func FetchCacheControl added in v1.0.23

func FetchCacheControl(ctx context.Context, service string, fn string, arg Argument) (etag string, status int, contentType string, contentLength string, deadline time.Time, body []byte, has bool)

func Fork

func Fork(ctx context.Context, task Task)

func GetLog

func GetLog(ctx context.Context) (log logs.Logger)

func GetSigner added in v0.14.0

func GetSigner(ctx context.Context) (signer *secret.Signer)

func NewFuture added in v0.14.0

func NewFuture() (p Promise, f Future)

func RegisterClusterBuilder added in v0.14.0

func RegisterClusterBuilder(name string, builder ClusterBuilder)

func RemoveCacheControl added in v1.0.23

func RemoveCacheControl(ctx context.Context, service string, fn string, arg Argument)

func Running added in v1.0.10

func Running(ctx context.Context) (signal <-chan struct{})

func SharedCache added in v1.0.26

func SharedCache(ctx context.Context) (store shareds.Caches)

func SharedLock added in v0.14.0

func SharedLock(ctx context.Context, key []byte, ttl time.Duration) (locker shareds.Locker, err errors.CodeError)

func SharedStore added in v0.14.0

func SharedStore(ctx context.Context) (store shareds.Store)

func TransportResponseWriter added in v1.0.22

func TransportResponseWriter(ctx context.Context) (w transports.ResponseWriter, has bool)

func TryFork

func TryFork(ctx context.Context, task Task) (ok bool)

Types

type Abstract

type Abstract struct {
	// contains filtered or unexported fields
}

func NewAbstract

func NewAbstract(name string, internal bool, components ...Component) Abstract

func (*Abstract) AppId added in v0.14.0

func (svc *Abstract) AppId() (id string)

func (*Abstract) AppName added in v0.14.0

func (svc *Abstract) AppName() (name string)

func (*Abstract) AppVersion added in v0.14.0

func (svc *Abstract) AppVersion() (version versions.Version)

func (*Abstract) Barrier added in v0.14.0

func (svc *Abstract) Barrier(ctx context.Context, name string, arg Argument, fn func() (result interface{}, err errors.CodeError)) (result interface{}, err errors.CodeError)

func (*Abstract) Build

func (svc *Abstract) Build(options Options) (err error)

func (*Abstract) Close

func (svc *Abstract) Close()

func (*Abstract) Components

func (svc *Abstract) Components() (components map[string]Component)

func (*Abstract) Document added in v1.0.6

func (svc *Abstract) Document() (doc *documents.Document)

func (*Abstract) Internal

func (svc *Abstract) Internal() (internal bool)

func (*Abstract) Log

func (svc *Abstract) Log() (log logs.Logger)

func (*Abstract) Name

func (svc *Abstract) Name() (name string)

type Argument

type Argument interface {
	json.Marshaler
	json.Unmarshaler
	As(v interface{}) (err errors.CodeError)
	HashCode() (code uint64)
}

func EmptyArgument

func EmptyArgument() (arg Argument)

func NewArgument

func NewArgument(v interface{}) (arg Argument)

type AutoMaxProcsConfig added in v0.14.0

type AutoMaxProcsConfig struct {
	Min int `json:"min" yaml:"min,omitempty"`
	Max int `json:"max" yaml:"max,omitempty"`
}

type Barrier

type Barrier interface {
	Do(ctx context.Context, key string, fn func() (result interface{}, err errors.CodeError)) (result interface{}, err errors.CodeError)
	Forget(ctx context.Context, key string)
}

func GetBarrier added in v0.14.0

func GetBarrier(ctx context.Context) (barrier Barrier)

type Certificate added in v1.0.26

type Certificate interface {
	Id() string
	Kind() string
	Key() []byte
	SecretKey() []byte
	Password() []byte
	ExpireAT() time.Time
}

type Certificates added in v1.0.21

type Certificates interface {
	Get(ctx context.Context, id string) (certificate Certificate, err errors.CodeError)
}

type Cluster added in v0.14.0

type Cluster interface {
	Join(ctx context.Context) (err error)
	Leave(ctx context.Context) (err error)
	Nodes(ctx context.Context) (nodes Nodes, err error)
	Shared() (shared Shared)
}

type ClusterBuilder added in v0.14.0

type ClusterBuilder func(options ClusterBuilderOptions) (cluster Cluster, err error)

type ClusterBuilderOptions added in v0.14.0

type ClusterBuilderOptions struct {
	Config     configures.Config
	Log        logs.Logger
	AppId      string
	AppName    string
	AppVersion versions.Version
	Port       int
}

type ClusterConfig added in v0.14.0

type ClusterConfig struct {
	Kind                 string          `json:"kind" yaml:"kind,omitempty"`
	FetchMembersInterval string          `json:"fetchMembersInterval" yaml:"fetchMembersInterval,omitempty"`
	Shared               *SharedConfig   `json:"shared" yaml:"shared,omitempty"`
	Options              json.RawMessage `json:"options" yaml:"options,omitempty"`
}

type Component

type Component interface {
	Name() (name string)
	Build(options ComponentOptions) (err error)
	Close()
}

func GetComponent

func GetComponent(ctx context.Context, key string) (v Component, has bool)

type ComponentOptions

type ComponentOptions struct {
	AppId      string
	AppName    string
	AppVersion versions.Version
	Log        logs.Logger
	Config     configures.Config
}

type Config added in v0.14.0

type Config struct {
	Runtime   *RuntimeConfig   `json:"runtime" yaml:"runtime,omitempty"`
	Log       *LogConfig       `json:"log" yaml:"log,omitempty"`
	Transport *TransportConfig `json:"transport" yaml:"transport,omitempty"`
	Cluster   *ClusterConfig   `json:"cluster" yaml:"cluster,omitempty"`
	Proxy     *ProxyConfig     `json:"proxy" yaml:"proxy,omitempty"`
	Services  json.RawMessage  `json:"services" yaml:"services,omitempty"`
}

func (*Config) Service added in v1.0.10

func (config *Config) Service(name string) (conf configures.Config, err error)

type ETags added in v1.0.21

type ETags struct {
	// contains filtered or unexported fields
}

type Empty

type Empty struct{}

Empty @name Empty @description Empty object

type Endpoint

type Endpoint interface {
	Name() (name string)
	Internal() (ok bool)
	Document() (document *documents.Document)
	Request(ctx context.Context, r Request) (future Future)
	RequestSync(ctx context.Context, r Request) (result FutureResult, err errors.CodeError)
}

func GetEndpoint

func GetEndpoint(ctx context.Context, name string, options ...EndpointDiscoveryGetOption) (v Endpoint, has bool)

type EndpointDiscovery

type EndpointDiscovery interface {
	Get(ctx context.Context, service string, options ...EndpointDiscoveryGetOption) (endpoint Endpoint, has bool)
}

type EndpointDiscoveryGetOption added in v0.14.0

type EndpointDiscoveryGetOption func(options *EndpointDiscoveryGetOptions)

func Exact added in v0.14.0

func Native added in v0.14.0

func Versions added in v1.0.10

func Versions(requestVersions RequestVersions) EndpointDiscoveryGetOption

type EndpointDiscoveryGetOptions added in v0.14.0

type EndpointDiscoveryGetOptions struct {
	// contains filtered or unexported fields
}

type Endpoints

type Endpoints struct {
	// contains filtered or unexported fields
}

func NewEndpoints

func NewEndpoints(options EndpointsOptions) (v *Endpoints, err error)

func (*Endpoints) Close

func (e *Endpoints) Close(ctx context.Context)

func (*Endpoints) Deploy added in v0.14.0

func (e *Endpoints) Deploy(svc Service) (err error)

func (*Endpoints) Get added in v0.14.0

func (e *Endpoints) Get(ctx context.Context, service string, options ...EndpointDiscoveryGetOption) (v Endpoint, has bool)

func (*Endpoints) Listen added in v0.14.0

func (e *Endpoints) Listen(ctx context.Context) (err error)

func (*Endpoints) Log added in v0.14.0

func (e *Endpoints) Log() (log logs.Logger)

func (*Endpoints) Running added in v0.14.0

func (e *Endpoints) Running() (ok bool)

func (*Endpoints) Runtime added in v1.0.10

func (e *Endpoints) Runtime() (rt *Runtime)

type EndpointsOptions

type EndpointsOptions struct {
	AppId      string
	AppName    string
	AppVersion versions.Version
	Transport  *TransportOptions
	Proxy      *TransportOptions
	Config     configures.Config
}

type Future added in v0.14.0

type Future interface {
	Get(ctx context.Context) (result FutureResult, err errors.CodeError)
}

type FutureResult

type FutureResult interface {
	json.Marshaler
	Exist() (ok bool)
	Scan(v interface{}) (err errors.CodeError)
}

type Listenable

type Listenable interface {
	Service
	Listen(ctx context.Context) (err error)
}

type LogConfig added in v0.14.0

type LogConfig struct {
	Level     string `json:"level" yaml:"level,omitempty"`
	Formatter string `json:"formatter" yaml:"formatter,omitempty"`
	Color     bool   `json:"color" yaml:"color,omitempty"`
}

type Metric

type Metric struct {
	Service   string        `json:"service"`
	Fn        string        `json:"fn"`
	Succeed   bool          `json:"succeed"`
	ErrorCode int           `json:"errorCode"`
	ErrorName string        `json:"errorName"`
	Latency   time.Duration `json:"latency"`
}

type Node added in v0.14.0

type Node struct {
	Id       string           `json:"id"`
	Name     string           `json:"name"`
	Version  versions.Version `json:"version"`
	Address  string           `json:"address"`
	Services []string         `json:"services"`
}

type Nodes added in v0.14.0

type Nodes []*Node

func (Nodes) Len added in v0.14.0

func (nodes Nodes) Len() int

func (Nodes) Less added in v0.14.0

func (nodes Nodes) Less(i, j int) bool

func (Nodes) Swap added in v0.14.0

func (nodes Nodes) Swap(i, j int)

type Options

type Options struct {
	AppId      string
	AppName    string
	AppVersion versions.Version
	Log        logs.Logger
	Config     configures.Config
}

type Promise added in v0.14.0

type Promise interface {
	Succeed(v interface{})
	Failed(err errors.CodeError)
	Close()
}

type ProxyConfig added in v1.0.5

type ProxyConfig struct {
	TransportConfig
	EnableDevMode bool `json:"enableDevMode" yaml:"enableDevMode,omitempty"`
}

type RateLimitCounter added in v1.0.10

type RateLimitCounter interface {
	Name() (name string)
	Build(options RateLimitCounterOptions) (err error)
	Incr(ctx context.Context, key []byte) (ok bool, err error)
	Decr(ctx context.Context, key []byte) (err error)
	Close()
}

type RateLimitCounterOptions added in v1.0.10

type RateLimitCounterOptions struct {
	AppId      string
	AppName    string
	AppVersion versions.Version
	AppStatus  *Status
	Log        logs.Logger
	Config     configures.Config
	Discovery  EndpointDiscovery
	Shared     Shared
}

type Registration added in v0.14.0

type Registration struct {
	// contains filtered or unexported fields
}

func (*Registration) Document added in v0.14.0

func (registration *Registration) Document() (document *documents.Document)

func (*Registration) Internal added in v0.14.0

func (registration *Registration) Internal() (ok bool)

func (*Registration) Key added in v0.14.0

func (registration *Registration) Key() (key string)

func (*Registration) Name added in v0.14.0

func (registration *Registration) Name() (name string)

func (*Registration) Request added in v0.14.0

func (registration *Registration) Request(ctx context.Context, r Request) (future Future)

func (*Registration) RequestSync added in v0.14.0

func (registration *Registration) RequestSync(ctx context.Context, r Request) (result FutureResult, err errors.CodeError)

type RegistrationList added in v1.0.5

type RegistrationList []*Registration

func (RegistrationList) Len added in v1.0.5

func (list RegistrationList) Len() int

func (RegistrationList) Less added in v1.0.5

func (list RegistrationList) Less(i, j int) bool

func (RegistrationList) MaxVersion added in v1.0.5

func (list RegistrationList) MaxVersion() (r *Registration)

func (RegistrationList) MinVersion added in v1.0.5

func (list RegistrationList) MinVersion() (r *Registration)

func (RegistrationList) Swap added in v1.0.5

func (list RegistrationList) Swap(i, j int)

type Registrations added in v0.14.0

type Registrations struct {
	// contains filtered or unexported fields
}

func (*Registrations) Add added in v0.14.0

func (r *Registrations) Add(registration *Registration)

func (*Registrations) AddNode added in v0.14.0

func (r *Registrations) AddNode(node *Node) (err error)

func (*Registrations) Close added in v0.14.0

func (r *Registrations) Close()

func (*Registrations) FetchDocuments added in v1.0.10

func (r *Registrations) FetchDocuments(ctx context.Context) (v documents.Documents, err error)

func (*Registrations) FetchNodeDocuments added in v1.0.10

func (r *Registrations) FetchNodeDocuments(ctx context.Context, node *Node) (v documents.Documents, err error)

func (*Registrations) Get added in v0.14.0

func (r *Registrations) Get(name string, rvs RequestVersions) (registration *Registration, has bool)

func (*Registrations) GetExact added in v0.14.0

func (r *Registrations) GetExact(name string, id string) (registration *Registration, has bool)

func (*Registrations) GetNodeServices added in v1.0.10

func (r *Registrations) GetNodeServices(ctx context.Context, node *Node) (names []string, err error)

func (*Registrations) List added in v1.0.5

func (r *Registrations) List() (values map[string]RegistrationList)

func (*Registrations) ListMembers added in v1.0.10

func (r *Registrations) ListMembers(ctx context.Context) (members Nodes, err error)

func (*Registrations) MergeNodes added in v1.0.4

func (r *Registrations) MergeNodes(nodes Nodes) (err error)

func (*Registrations) Refresh added in v1.0.10

func (r *Registrations) Refresh(ctx context.Context)

func (*Registrations) Remove added in v0.14.0

func (r *Registrations) Remove(id string)

type Request

type Request interface {
	Id() (id string)
	Header() (header RequestHeader)
	AcceptedVersions() (acceptedVersions RequestVersions)
	Fn() (service string, fn string)
	Argument() (argument Argument)
	Internal() (ok bool)
	User() (user RequestUser)
	Trunk() (trunk RequestTrunk)
	Hash() (p []byte)
}

func GetRequest

func GetRequest(ctx context.Context) (r Request, has bool)

func NewRequest

func NewRequest(ctx context.Context, service string, fn string, arg Argument, options ...RequestOption) (v Request)

type RequestHeader

type RequestHeader http.Header

func (RequestHeader) Add added in v0.14.0

func (header RequestHeader) Add(key, value string)

func (RequestHeader) Authorization added in v0.14.0

func (header RequestHeader) Authorization() (authorization string, has bool)

func (RequestHeader) CacheControlDisabled added in v1.0.21

func (header RequestHeader) CacheControlDisabled() (ok bool)

func (RequestHeader) Clone added in v1.0.10

func (header RequestHeader) Clone() RequestHeader

func (RequestHeader) Contains

func (header RequestHeader) Contains(key string) (ok bool)

func (RequestHeader) Del added in v1.0.10

func (header RequestHeader) Del(key string)

func (RequestHeader) DeviceId added in v0.14.0

func (header RequestHeader) DeviceId() (id string)

func (RequestHeader) DeviceIp added in v0.14.0

func (header RequestHeader) DeviceIp() (id string)

func (RequestHeader) DisableCacheControl added in v1.0.21

func (header RequestHeader) DisableCacheControl()

func (RequestHeader) Empty added in v1.0.10

func (header RequestHeader) Empty() bool

func (RequestHeader) EnableCacheControl added in v1.0.21

func (header RequestHeader) EnableCacheControl(etag []byte)

func (RequestHeader) ForEach added in v0.14.0

func (header RequestHeader) ForEach(fn func(key string, values []string) (next bool))

func (RequestHeader) Get

func (header RequestHeader) Get(key string) string

func (RequestHeader) Set added in v0.14.0

func (header RequestHeader) Set(key, value string)

func (RequestHeader) SetAcceptVersions added in v1.0.10

func (header RequestHeader) SetAcceptVersions(rvs RequestVersions)

func (RequestHeader) SetDeviceId added in v1.0.10

func (header RequestHeader) SetDeviceId(id string)

func (RequestHeader) SetDeviceIp added in v1.0.10

func (header RequestHeader) SetDeviceIp(ip string)

func (RequestHeader) Values

func (header RequestHeader) Values(key string) []string

type RequestOption added in v0.14.0

type RequestOption func(*RequestOptions)

func DisableRequestCacheControl added in v1.0.21

func DisableRequestCacheControl() RequestOption

func WithDeviceId added in v0.14.0

func WithDeviceId(id string) RequestOption

func WithDeviceIp added in v0.14.0

func WithDeviceIp(ip string) RequestOption

func WithInternalRequest added in v0.14.0

func WithInternalRequest() RequestOption

func WithRequestHeader added in v1.0.10

func WithRequestHeader(header transports.Header) RequestOption

func WithRequestId added in v0.14.0

func WithRequestId(id string) RequestOption

func WithRequestTrunk added in v0.14.0

func WithRequestTrunk(trunk RequestTrunk) RequestOption

func WithRequestUser added in v0.14.0

func WithRequestUser(id RequestUserId, attributes *json.Object) RequestOption

func WithRequestVersions added in v1.0.10

func WithRequestVersions(acceptedVersions RequestVersions) RequestOption

type RequestOptions added in v0.14.0

type RequestOptions struct {
	// contains filtered or unexported fields
}

type RequestTrunk added in v0.14.0

type RequestTrunk interface {
	json.Marshaler
	json.Unmarshaler
	Get(key string) (value []byte, has bool)
	Put(key string, value []byte)
	ForEach(fn func(key string, value []byte) (next bool))
	ReadFrom(o RequestTrunk)
	Remove(key string)
}

type RequestUser

type RequestUser interface {
	json.Marshaler
	json.Unmarshaler
	Authenticated() (ok bool)
	Id() (id RequestUserId)
	SetId(id RequestUserId)
	Attributes() (attributes *json.Object)
	SetAttributes(attributes *json.Object)
}

func GetRequestUser added in v0.13.7

func GetRequestUser(ctx context.Context) (user RequestUser, authenticated bool)

func NewRequestUser

func NewRequestUser(id RequestUserId, attributes *json.Object) (u RequestUser)

type RequestUserId added in v0.14.0

type RequestUserId string

func (RequestUserId) Exist added in v1.0.6

func (id RequestUserId) Exist() (ok bool)

func (RequestUserId) Int added in v0.14.0

func (id RequestUserId) Int() (n int64)

func (RequestUserId) String added in v0.14.0

func (id RequestUserId) String() string

type RequestVersion added in v1.0.10

type RequestVersion struct {
	Pattern string
	Begin   versions.Version
	End     versions.Version
	Exact   bool
}

func ParseRequestVersion added in v1.0.10

func ParseRequestVersion(s string) (rv *RequestVersion, err error)

func (*RequestVersion) Accept added in v1.0.10

func (rv *RequestVersion) Accept(serviceName string, target versions.Version) (ok bool)

func (*RequestVersion) String added in v1.0.10

func (rv *RequestVersion) String() string

type RequestVersions added in v1.0.10

type RequestVersions []*RequestVersion

func AllowAllRequestVersions added in v1.0.10

func AllowAllRequestVersions() RequestVersions

func ParseRequestVersionFromHeader added in v1.0.10

func ParseRequestVersionFromHeader(header transports.Header) (rvs RequestVersions, has bool, err error)

func (RequestVersions) Accept added in v1.0.10

func (rvs RequestVersions) Accept(serviceName string, target versions.Version) (ok bool)

func (RequestVersions) Empty added in v1.0.10

func (rvs RequestVersions) Empty() (ok bool)

func (RequestVersions) String added in v1.0.10

func (rvs RequestVersions) String() string

type Runtime added in v1.0.10

type Runtime struct {
	// contains filtered or unexported fields
}

func GetRuntime added in v1.0.10

func GetRuntime(ctx context.Context) (v *Runtime)

func (*Runtime) AppId added in v1.0.10

func (rt *Runtime) AppId() string

func (*Runtime) AppName added in v1.0.10

func (rt *Runtime) AppName() string

func (*Runtime) AppStatus added in v1.0.10

func (rt *Runtime) AppStatus() *Status

func (*Runtime) AppVersion added in v1.0.10

func (rt *Runtime) AppVersion() versions.Version

func (*Runtime) Barrier added in v1.0.10

func (rt *Runtime) Barrier() Barrier

func (*Runtime) Discovery added in v1.0.10

func (rt *Runtime) Discovery() EndpointDiscovery

func (*Runtime) RootLog added in v1.0.10

func (rt *Runtime) RootLog() logs.Logger

func (*Runtime) SetIntoContext added in v1.0.10

func (rt *Runtime) SetIntoContext(ctx context.Context) context.Context

func (*Runtime) Shared added in v1.0.10

func (rt *Runtime) Shared() Shared

func (*Runtime) Signer added in v1.0.10

func (rt *Runtime) Signer() *secret.Signer

func (*Runtime) Workers added in v1.0.10

func (rt *Runtime) Workers() Workers

type RuntimeConfig added in v0.14.0

type RuntimeConfig struct {
	MaxWorkers           int                `json:"maxWorkers" yaml:"maxWorkers,omitempty"`
	WorkerMaxIdleSeconds int                `json:"workerMaxIdleSeconds" yaml:"workerMaxIdleSeconds,omitempty"`
	HandleTimeoutSeconds int                `json:"handleTimeoutSeconds" yaml:"handleTimeoutSeconds,omitempty"`
	AutoMaxProcs         AutoMaxProcsConfig `json:"autoMaxProcs" yaml:"autoMaxProcs,omitempty"`
	SecretKey            string             `json:"secretKey" yaml:"secretKey,omitempty"`
}

type Service

type Service interface {
	Build(options Options) (err error)
	Name() (name string)
	Internal() (internal bool)
	Components() (components map[string]Component)
	Document() (doc *documents.Document)
	Handle(ctx context.Context, fn string, argument Argument) (v interface{}, err errors.CodeError)
	Close()
}

type ServicesSupplier added in v1.0.10

type ServicesSupplier interface {
	Services() (services []Service)
}

type Shared added in v0.14.0

type Shared interface {
	Lockers() (lockers shareds.Lockers)
	Store() (store shareds.Store)
	Caches() (cache shareds.Caches)
}

type SharedConfig added in v0.14.0

type SharedConfig struct {
	BarrierDisabled        bool   `json:"barrierDisabled" yaml:"barrierDisabled,omitempty"`
	BarrierTTLMilliseconds uint64 `json:"barrierTTLMilliseconds" yaml:"barrierTTLMilliseconds,omitempty"`
}

type Span

type Span struct {
	Id_         string            `json:"id"`
	Service_    string            `json:"service"`
	Fn_         string            `json:"fn"`
	TracerId_   string            `json:"tracerId"`
	StartAT_    time.Time         `json:"startAt"`
	FinishedAT_ time.Time         `json:"finishedAt"`
	Latency_    string            `json:"latency"`
	Children_   []*Span           `json:"children"`
	Tags_       map[string]string `json:"tags"`
	// contains filtered or unexported fields
}

func (*Span) AddTag

func (s *Span) AddTag(key string, value string)

func (*Span) AppendChild

func (s *Span) AppendChild(children ...*Span)

func (*Span) Children

func (s *Span) Children() (v []*Span)

func (*Span) Finish

func (s *Span) Finish()

func (*Span) FinishedAT

func (s *Span) FinishedAT() (v time.Time)

func (*Span) Id

func (s *Span) Id() (v string)

func (*Span) Latency

func (s *Span) Latency() (v time.Duration)

func (*Span) Parent

func (s *Span) Parent() (v *Span)

func (*Span) StartAT

func (s *Span) StartAT() (v time.Time)

func (*Span) Tags

func (s *Span) Tags() (v map[string]string)

func (*Span) TracerId

func (s *Span) TracerId() (v string)

type Status added in v1.0.10

type Status struct {
	// contains filtered or unexported fields
}

func (*Status) Closed added in v1.0.10

func (status *Status) Closed() (ok bool)

func (*Status) Serving added in v1.0.10

func (status *Status) Serving() (ok bool)

func (*Status) Starting added in v1.0.10

func (status *Status) Starting() (ok bool)

type TLSConfig added in v0.14.0

type TLSConfig struct {
	// Kind
	// ACME
	// SSC(SELF-SIGN-CERT)
	// DEFAULT
	Kind    string          `json:"kind" yaml:"kind,omitempty"`
	Options json.RawMessage `json:"options" yaml:"options,omitempty"`
}

func (*TLSConfig) Config added in v0.14.0

func (config *TLSConfig) Config() (serverTLS *tls.Config, clientTLS *tls.Config, err error)

type Task

type Task interface {
	workers.Task
	Name() (name string)
}

type Tracer

type Tracer interface {
	Id() (id string)
	StartSpan(service string, fn string) (span *Span)
	Span() (span *Span)
	RootSpan() (span *Span)
}

func GetTracer

func GetTracer(ctx context.Context) (t Tracer, has bool)

func NewTracer

func NewTracer(id string) Tracer

type TransportConfig added in v1.0.10

type TransportConfig struct {
	Name        string                 `json:"name" yaml:"name,omitempty"`
	Port        int                    `json:"port" yaml:"port,omitempty"`
	Cors        *transports.CorsConfig `json:"cors" yaml:"cors,omitempty"`
	TLS         *TLSConfig             `json:"tls" yaml:"tls,omitempty"`
	Options     json.RawMessage        `json:"options" yaml:"options,omitempty"`
	Middlewares json.RawMessage        `json:"middlewares" yaml:"middlewares,omitempty"`
	Handlers    json.RawMessage        `json:"handlers" yaml:"handlers,omitempty"`
}

func (*TransportConfig) ConvertToTransportsOptions added in v1.0.10

func (config *TransportConfig) ConvertToTransportsOptions(log logs.Logger, handler transports.Handler) (options transports.Options, err error)

func (*TransportConfig) HandlersConfig added in v1.0.10

func (config *TransportConfig) HandlersConfig() (conf configures.Config, err error)

func (*TransportConfig) MiddlewaresConfig added in v1.0.10

func (config *TransportConfig) MiddlewaresConfig() (conf configures.Config, err error)

type TransportHandler added in v1.0.10

type TransportHandler interface {
	Name() (name string)
	Build(options TransportHandlerOptions) (err error)
	Accept(r *transports.Request) (ok bool)
	transports.Handler
	Close() (err error)
}

type TransportHandlerOptions added in v1.0.10

type TransportHandlerOptions struct {
	Log     logs.Logger
	Config  configures.Config
	Runtime *Runtime
}

type TransportMiddleware added in v1.0.10

type TransportMiddleware interface {
	Name() (name string)
	Build(options TransportMiddlewareOptions) (err error)
	Handler(next transports.Handler) transports.Handler
	Close() (err error)
}

func CacheControlMiddleware added in v1.0.10

func CacheControlMiddleware() TransportMiddleware

func CustomizeRateLimitMiddleware added in v1.0.10

func CustomizeRateLimitMiddleware(counter RateLimitCounter) TransportMiddleware

func RateLimitMiddleware added in v1.0.10

func RateLimitMiddleware() TransportMiddleware

func SignatureMiddleware added in v1.0.10

func SignatureMiddleware(certificates Certificates) TransportMiddleware

SignatureMiddleware

使用SM2进行共享密钥交换,交换成功后双方使用共享密钥进行对签名与验证 签名方式为使用HMAC+XXHASH对path+body签名,使用HEX对签名编码。最终将签名赋值于X-Fns-Signature头。 错误: * 458: 验证签名错误 * 468: 共享密钥超时 * 488: 签名丢失 * 448: 因发起方的秘密哈希不匹配而不同意密钥交换

交换共享密钥: 发起方进行发起交换共享密钥请求 curl -H "Content-Type: application/json" -H "X-Fns-Device-Id: client-uuid" -X POST -d '{"publicKey":"pem string", "keyLength": 20}' http://ip:port/signatures/exchange_key 其中`X-Fns-Device-Id`的值是证书的编号,即证书必须是由响应方签发的。 响应方收到请求后,创建共享密钥,如果成功,则返回响应方的公钥,共享密钥有效期,响应方的共享密钥hash,发起方的共享密钥hash。 成功结果结果: `{"id": "responder id", "publicKey":"pem string", "expireAT": "RFC3339", "responderExchangeKeyHash": []byte}` 发起方拿到响应方的公钥,进行创建共享密钥,然后比对响应方的密钥hash,如果成功,则发起确认请求。 curl -H "Content-Type: application/json" -H "X-Fns-Device-Id: client-uuid" -X POST -d '{"initiatorExchangeKeyHash":[]byte}' http://ip:port/signatures/confirm_exchange_key 响应方收到确认请求后,比对发起方的密钥HASH,如果成功,则同意协商结果。返回{"ok": true}

certificates : 证书仓库

type TransportMiddlewareOptions added in v1.0.10

type TransportMiddlewareOptions struct {
	Log     logs.Logger
	Config  configures.Config
	Runtime *Runtime
}

type TransportOptions added in v1.0.10

type TransportOptions struct {
	Middlewares []TransportMiddleware
	Handlers    []TransportHandler
}

type Workers added in v0.14.0

type Workers interface {
	Dispatch(ctx context.Context, task workers.Task) (ok bool)
	MustDispatch(ctx context.Context, task workers.Task)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL