package module
Version: v0.6.15 Latest Latest

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 34 Imported by: 3




public host and public port
  • docker
    • 默认 public host 使用 docker container 的 hostname ip,如果非容器内访问,则需要在 config 中设置,或者设置 PUBLIC_HOST 环境变量。
    • 默认 public port 为 port,如果 expose port,则需要在 config 中设置,或者设置 PUBLIC_PORT 环境变量。
  • kubernetes
    • 设置 config 中的 public host,或者设置 PUBLIC_HOST 环境变量,值为 POD IP。设置参考
    • 设置 config 中的 public port,或者设置 PUBLIC_PORT 环境变量,值为 名称为 fns 的 POD PORT。设置参考
  • 其它环境
    • 默认 public host 使用 config 中的 host,优先使用 config 中的设置,其次为 环境变量,最后是默认。
    • 默认 public port 使用 config 中的 port,优先使用 config 中的设置,其次为 环境变量,最后是默认。


K6 结果(50 VUS 30s)

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ./test.js
     output: -

  scenarios: (100.00%) 1 scenario, 50 max VUs, 1m0s max duration (incl. graceful stop):
           * default: 50 looping VUs for 30s (gracefulStop: 30s)

running (0m30.0s), 00/50 VUs, 3565697 complete and 0 interrupted iterations
default ✓ [======================================] 50 VUs  30s

     ✓ status was 200

     checks.........................: 100.00% ✓ 3565697       ✗ 0
     data_received..................: 564 MB  19 MB/s
     data_sent......................: 521 MB  17 MB/s
     http_req_blocked...............: avg=1.58µs   min=0s med=0s   max=5.57ms   p(90)=0s      p(95)=0s
     http_req_connecting............: avg=24ns     min=0s med=0s   max=2.31ms   p(90)=0s      p(95)=0s
     http_req_duration..............: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
       { expected_response:true }...: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
     http_req_failed................: 0.00%   ✓ 0             ✗ 3565697
     http_req_receiving.............: avg=26.91µs  min=0s med=0s   max=8.65ms   p(90)=0s      p(95)=29.3µs
     http_req_sending...............: avg=10.53µs  min=0s med=0s   max=7.7ms    p(90)=0s      p(95)=0s
     http_req_tls_handshaking.......: avg=0s       min=0s med=0s   max=0s       p(90)=0s      p(95)=0s
     http_req_waiting...............: avg=223.86µs min=0s med=0s   max=12.43ms  p(90)=641.9µs p(95)=1ms
     http_reqs......................: 3565697 118850.991763/s
     iteration_duration.............: avg=412.23µs min=0s med=92µs max=118.81ms p(90)=1ms     p(95)=1ms
     iterations.....................: 3565697 118850.991763/s
     vus............................: 50      min=50          max=50
     vus_max........................: 50      min=50          max=50




View Source
const (
	B = 1 << (10 * iota)


View Source
var File_message_proto protoreflect.FileDescriptor


func ConfigActiveFromENV added in v0.1.1

func ConfigActiveFromENV(key string) (active string)

func RegisterAuthorizationsRetriever

func RegisterAuthorizationsRetriever(kind string, retriever AuthorizationsRetriever)

func RegisterPermissionsDefinitionsLoaderRetriever added in v0.1.1

func RegisterPermissionsDefinitionsLoaderRetriever(kind string, retriever PermissionsDefinitionsLoaderRetriever)

func RegisterServiceDiscoveryRetriever

func RegisterServiceDiscoveryRetriever(kind string, retriever ServiceDiscoveryRetriever)

func UID

func UID() (id string)


type AbstractServiceDiscovery added in v0.1.1

type AbstractServiceDiscovery struct {
	Local   ServiceDiscovery
	Clients *HttpClients
	Manager *RegistrationsManager

func NewAbstractServiceDiscovery added in v0.1.1

func NewAbstractServiceDiscovery(clients *HttpClients) AbstractServiceDiscovery

func (*AbstractServiceDiscovery) Close added in v0.1.1

func (discovery *AbstractServiceDiscovery) Close()

func (*AbstractServiceDiscovery) IsLocal added in v0.1.1

func (discovery *AbstractServiceDiscovery) IsLocal(namespace string) (ok bool)

func (*AbstractServiceDiscovery) Proxy added in v0.1.1

func (discovery *AbstractServiceDiscovery) Proxy(ctx Context, namespace string) (proxy ServiceProxy, err errors.CodeError)

type AppRuntime added in v0.1.1

type AppRuntime interface {
	ClusterMode() (ok bool)
	PublicAddress() (address string)
	Log() (log logs.Logger)
	Validate(v interface{}) (err errors.CodeError)
	ServiceProxy(ctx Context, namespace string) (proxy ServiceProxy, err error)
	Authorizations() (authorizations Authorizations)
	Permissions() (permissions Permissions)
	HttpClient() (client HttpClient)

type Application

type Application interface {
	Log() (log logs.Logger)
	Deploy(service ...Service) (err error)
	Run(ctx sc.Context) (err error)
	SyncWithTimeout(timeout time.Duration)

func New

func New(options ...Option) (app Application, err error)

type ApplicationConfig

type ApplicationConfig struct {
	Name        string         `json:"name,omitempty"`
	Concurrency int            `json:"concurrency,omitempty"`
	Http        HttpConfig     `json:"http,omitempty"`
	Log         LogConfig      `json:"log,omitempty"`
	Services    ServicesConfig `json:"services,omitempty"`

type Argument

type Argument interface {
	As(v interface{}) (err errors.CodeError)

func NewArgument

func NewArgument(v interface{}) (arg Argument, err errors.CodeError)

type Authorizations

type Authorizations interface {
	Encode(ctx Context) (token []byte, err errors.CodeError)
	Decode(ctx Context, token []byte) (err errors.CodeError)

type AuthorizationsConfig

type AuthorizationsConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Kind   string          `json:"kind,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`

type AuthorizationsRetriever

type AuthorizationsRetriever func(config configuares.Raw) (authorizations Authorizations, err error)

type Context

type Context interface {
	RequestId() (id string)
	User() (user User)
	Meta() (meta ContextMeta)
	Timeout() (has bool)
	App() (app AppRuntime)

func WithFn

func WithFn(ctx Context, fn string) Context

func WithNamespace

func WithNamespace(ctx Context, namespace string) Context

type ContextMeta

type ContextMeta interface {
	Exists(key string) (has bool)
	Put(key string, value interface{})
	Get(key string, value interface{}) (err error)
	Remove(key string)
	GetString(key string) (value string, has bool)
	GetInt(key string) (value int, has bool)
	GetInt32(key string) (value int32, has bool)
	GetInt64(key string) (value int64, has bool)
	GetFloat32(key string) (value float32, has bool)
	GetFloat64(key string) (value float64, has bool)
	GetBool(key string) (value bool, has bool)
	GetTime(key string) (value time.Time, has bool)
	GetDuration(key string) (value time.Duration, has bool)
	SetExactProxyServiceAddress(namespace string, address string)
	GetExactProxyServiceAddress(namespace string) (address string, has bool)
	DelExactProxyServiceAddress(namespace string)
	Encode() (value []byte)

type CorsConfig

type CorsConfig struct {
	Enable           bool     `json:"enable,omitempty"`
	AllowedOrigins   []string `json:"allowedOrigins,omitempty"`
	AllowedMethods   []string `json:"allowedMethods,omitempty"`
	AllowedHeaders   []string `json:"allowedHeaders,omitempty"`
	ExposedHeaders   []string `json:"exposedHeaders,omitempty"`
	AllowCredentials bool     `json:"allowCredentials,omitempty"`
	MaxAge           int      `json:"maxAge,omitempty"`

type DiscoveryConfig

type DiscoveryConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Kind   string          `json:"kind,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`

type Empty

type Empty struct{}

Empty @description Empty

type Hook

type Hook interface {
	Build(config configuares.Config) (err error)
	Handle(unit HookUnit)

type HookUnit

type HookUnit struct {
	Namespace     string
	FnName        string
	RequestId     string
	Authorization []byte
	RequestSize   int64
	ResponseSize  int64
	Latency       time.Duration
	HandleError   errors.CodeError

type HttpClient added in v0.1.1

type HttpClient interface {
	Get(url string, head http.Header, timeout time.Duration) (response *HttpResponse, err error)
	Post(url string, head http.Header, body []byte, timeout time.Duration) (response *HttpResponse, err error)
	Put(url string, head http.Header, body []byte, timeout time.Duration) (response *HttpResponse, err error)
	Delete(url string, head http.Header, timeout time.Duration) (response *HttpResponse, err error)

type HttpClients added in v0.1.1

type HttpClients struct {
	// contains filtered or unexported fields

func NewHttpClients added in v0.1.1

func NewHttpClients(poolSize int) (hc *HttpClients)

func (*HttpClients) Close added in v0.1.1

func (hc *HttpClients) Close()

type HttpConfig

type HttpConfig struct {
	Host                     string     `json:"host,omitempty"`
	Port                     int        `json:"port,omitempty"`
	PublicHost               string     `json:"publicHost,omitempty"`
	PublicPort               int        `json:"publicPort,omitempty"`
	MaxConnectionsPerIP      int        `json:"maxConnectionsPerIp,omitempty"`
	MaxRequestsPerConnection int        `json:"maxRequestsPerConnection,omitempty"`
	KeepAlive                bool       `json:"keepAlive,omitempty"`
	KeepalivePeriodSecond    int        `json:"keepalivePeriodSecond,omitempty"`
	RequestTimeoutSeconds    int        `json:"requestTimeoutSeconds,omitempty"`
	ReadBufferSize           string     `json:"readBufferSize"`
	WriteBufferSize          string     `json:"writeBufferSize"`
	Cors                     CorsConfig `json:"cors"`

type HttpResponse added in v0.1.1

type HttpResponse struct {
	Status int
	Head   http.Header
	Body   []byte

type LocaledServiceProxy added in v0.1.1

type LocaledServiceProxy struct {
	// contains filtered or unexported fields

func NewLocaledServiceProxy added in v0.1.1

func NewLocaledServiceProxy(service Service) *LocaledServiceProxy

func (*LocaledServiceProxy) Request added in v0.1.1

func (proxy *LocaledServiceProxy) Request(ctx Context, fn string, argument Argument) (result Result)

type LogConfig

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

type Option

type Option func(*Options) error

func ConfigRetriever

func ConfigRetriever(path string, format string, active string, prefix string, splitter byte) Option

func CustomizeValidate

func CustomizeValidate(validate *validator.Validate) Option

func GOPROCS added in v0.3.0

func GOPROCS(min int, max int) Option

func Hooks

func Hooks(hooks ...Hook) Option

func SecretKeyFile

func SecretKeyFile(path string) Option

func Version

func Version(version string) Option

type Options

type Options struct {
	ConfigRetrieverOption configuares.RetrieverOption
	Validate              *validator.Validate
	Hooks                 []Hook
	Version               string
	SecretKey             []byte
	MinPROCS              int
	MaxPROCS              int

type Permissions

type Permissions interface {
	// Validate 验证当前 context 中 user 对 fn 的权限
	Validate(ctx Context, namespace string, fn string) (err errors.CodeError)
	// SaveUserRoles 将角色保存到 当前 context 的 user attributes 中
	SaveUserRoles(ctx Context, roles ...string) (err errors.CodeError)

Permissions 基于RBAC的权限控制器 角色:角色树,控制器不存储用户的角色。 资源:fn 控制:是否可以使用(不可以使用优先于可以使用)

type PermissionsConfig

type PermissionsConfig struct {
	Enable bool            `json:"enable,omitempty"`
	Loader string          `json:"loader,omitempty"`
	Config configuares.Raw `json:"config,omitempty"`

type PermissionsDefinitions added in v0.1.1

type PermissionsDefinitions struct {
	// contains filtered or unexported fields

func (*PermissionsDefinitions) Accessible added in v0.1.1

func (d *PermissionsDefinitions) Accessible(namespace string, fn string, roles []string) (accessible bool)

func (*PermissionsDefinitions) Add added in v0.1.1

func (d *PermissionsDefinitions) Add(namespace string, fn string, role string, accessible bool)

type PermissionsDefinitionsLoader added in v0.1.1

type PermissionsDefinitionsLoader interface {
	Load() (definitions *PermissionsDefinitions, err errors.CodeError)

PermissionsDefinitionsLoader 存储权限设定的加载器

type PermissionsDefinitionsLoaderRetriever added in v0.1.1

type PermissionsDefinitionsLoaderRetriever func(config configuares.Raw) (loader PermissionsDefinitionsLoader, err error)

type Registration added in v0.1.1

type Registration struct {
	Id        string `json:"id"`
	Namespace string `json:"namespace,omitempty"`
	Address   string `json:"address"`
	Reversion int64  `json:"-"`

func (Registration) Key added in v0.1.1

func (r Registration) Key() (key string)

type Registrations added in v0.1.1

type Registrations struct {
	// contains filtered or unexported fields

func NewRegistrations added in v0.1.1

func NewRegistrations() (registrations *Registrations)

func (*Registrations) Append added in v0.1.1

func (r *Registrations) Append(v Registration)

func (*Registrations) Next added in v0.1.1

func (r *Registrations) Next() (v *Registration, has bool)

func (*Registrations) Remove added in v0.1.1

func (r *Registrations) Remove(v Registration)

func (*Registrations) Size added in v0.1.1

func (r *Registrations) Size() (size int)

type RegistrationsManager added in v0.1.1

type RegistrationsManager struct {
	// contains filtered or unexported fields

func (*RegistrationsManager) Append added in v0.1.1

func (manager *RegistrationsManager) Append(registration Registration)

func (*RegistrationsManager) CheckRegistration added in v0.1.1

func (manager *RegistrationsManager) CheckRegistration(registration Registration) (ok bool)

func (*RegistrationsManager) Close added in v0.1.1

func (manager *RegistrationsManager) Close()

func (*RegistrationsManager) Get added in v0.1.1

func (manager *RegistrationsManager) Get(namespace string) (registration *Registration, exists bool)

func (*RegistrationsManager) ListenProblemChan added in v0.1.1

func (manager *RegistrationsManager) ListenProblemChan()

func (*RegistrationsManager) ProblemChan added in v0.1.1

func (manager *RegistrationsManager) ProblemChan() (ch chan<- *Registration)

func (*RegistrationsManager) Registrations added in v0.1.1

func (manager *RegistrationsManager) Registrations() (v []Registration)

func (*RegistrationsManager) Remove added in v0.1.1

func (manager *RegistrationsManager) Remove(registration Registration)

type RemoteRequest added in v0.6.15

type RemoteRequest struct {
	Meta []byte `protobuf:"bytes,1,opt,name=meta,proto3" json:"meta,omitempty"`
	Arg  []byte `protobuf:"bytes,2,opt,name=arg,proto3" json:"arg,omitempty"`
	// contains filtered or unexported fields

func (*RemoteRequest) Descriptor deprecated added in v0.6.15

This method has been deprecated.
func (*RemoteRequest) Descriptor() ([]byte, []int)

Deprecated: Use RemoteRequest.ProtoReflect.Descriptor instead.

func (*RemoteRequest) GetArg added in v0.6.15

func (x *RemoteRequest) GetArg() []byte

func (*RemoteRequest) GetMeta added in v0.6.15

func (x *RemoteRequest) GetMeta() []byte

func (*RemoteRequest) ProtoMessage added in v0.6.15

func (*RemoteRequest) ProtoMessage()

func (*RemoteRequest) ProtoReflect added in v0.6.15

func (x *RemoteRequest) ProtoReflect() protoreflect.Message

func (*RemoteRequest) Reset added in v0.6.15

func (x *RemoteRequest) Reset()

func (*RemoteRequest) String added in v0.6.15

func (x *RemoteRequest) String() string

type RemotedServiceProxy

type RemotedServiceProxy struct {
	// contains filtered or unexported fields

func NewRemotedServiceProxy added in v0.1.1

func NewRemotedServiceProxy(clients *HttpClients, registration *Registration, problemCh chan<- *Registration) (proxy *RemotedServiceProxy)

func (*RemotedServiceProxy) Request

func (proxy *RemotedServiceProxy) Request(ctx Context, fn string, argument Argument) (result Result)

type Result

type Result interface {
	Succeed(v interface{})
	Failed(err errors.CodeError)
	Get(ctx sc.Context, v interface{}) (err errors.CodeError)

func AsyncResult

func AsyncResult() Result

func SyncResult

func SyncResult() Result

type Service

type Service interface {
	Namespace() (namespace string)
	Internal() (internal bool)
	Build(config configuares.Config) (err error)
	Description() (description []byte)
	Handle(context Context, fn string, argument Argument) (result interface{}, err errors.CodeError)
	Close() (err error)

Service 管理 Fn 的服务

type ServiceDiscovery

type ServiceDiscovery interface {
	Publish(service Service) (err error)
	IsLocal(namespace string) (ok bool)
	Proxy(ctx Context, namespace string) (proxy ServiceProxy, err errors.CodeError)

type ServiceDiscoveryOption

type ServiceDiscoveryOption struct {
	Address     string
	HttpClients *HttpClients
	Config      configuares.Raw

type ServiceDiscoveryRetriever

type ServiceDiscoveryRetriever func(option ServiceDiscoveryOption) (discovery ServiceDiscovery, err error)

type ServiceProxy

type ServiceProxy interface {
	Request(ctx Context, fn string, argument Argument) (result Result)

type ServicesConfig

type ServicesConfig struct {
	HandleTimeoutSecond int                  `json:"handleTimeoutSecond,omitempty"`
	MaxIdleTimeSecond   int                  `json:"maxIdleTimeSecond,omitempty"`
	ReduceMemoryUsage   bool                 `json:"reduceMemoryUsage,omitempty"`
	Discovery           DiscoveryConfig      `json:"discovery,omitempty"`
	Authorization       AuthorizationsConfig `json:"authorization,omitempty"`
	Permission          PermissionsConfig    `json:"permission,omitempty"`
	HttpClientPoolSize  int                  `json:"httpClientPoolSize,omitempty"`

type User

type User interface {
	Exists() (ok bool)
	Id() (id string)
	Principals() (principal *json.Object)
	Attributes() (attributes *json.Object)
	Authorization() (authorization []byte, has bool)
	SetAuthorization(authorization []byte)
	String() (value string)


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL