framework

package
v0.0.0-...-7429660 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 52 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LOG_ROTATE_HOUR  = "hour"
	LOG_ROTATE_DAY   = "day"
	LOG_ROTATE_MONTH = "month"
)

Variables

View Source
var Default = New()
View Source
var (
	DefaultKit log.Kit
)
View Source
var (
	GlobalNamespace = newNamespace()
)

Functions

func AddMockHTTPClient

func AddMockHTTPClient(name string, client httpclient.Client) error

func AddMockRedisClient

func AddMockRedisClient(name string, client *redis.Redis) error

func AddMockSqlClient

func AddMockSqlClient(name string, client *sql.Group) error

func Config

func Config() *config.Namespace

func ConfigInstance

func ConfigInstance() config.Config

func ConfigInstanceCtx

func ConfigInstanceCtx(ctx context.Context) config.Config

func File

func File(files ...string) error

func HTTPClient

func HTTPClient(ctx context.Context, name string) httpclient.Client

func HTTPDo

func HTTPDo(ctx context.Context, serviceName, method, uri string, ro *httpclient.RequestOption, body io.Reader) (*httpclient.Response, error)

func HTTPDoRequest

func HTTPDoRequest(ctx context.Context, serviceName string, req *http.Request) (*httpclient.Response, error)

func HTTPServer

func HTTPServer() httpserver.Server

func Init

func Init(options ...Option)

func InitNamespace

func InitNamespace(dir string)

func KafkaConsumeClient

func KafkaConsumeClient(ctx context.Context, consumeFrom string) *kafka.KafkaConsumeClient

func KafkaProducerClient

func KafkaProducerClient(ctx context.Context, producerTo string) *kafka.KafkaClient

func RPCFactory

func RPCFactory(ctx context.Context, name string) rpcclient.Factory

func RPCServer

func RPCServer() rpcserver.Server

func RedisClient

func RedisClient(ctx context.Context, name string) *redis.Redis

func Remote

func Remote(paths ...string) error

func RemoteKV

func RemoteKV(path string) (string, error)

func SQLClient

func SQLClient(ctx context.Context, name string) *sql.Group

func ServiceName

func ServiceName() string

func Shutdown

func Shutdown() error

func SyncProducerClient

func SyncProducerClient(ctx context.Context, producerTo string) *kafka.KafkaSyncClient

func WatchKV

func WatchKV(path string) config.Watcher

func WatchPrefix

func WatchPrefix(prefix string) config.Watcher

func WithAPPKey

func WithAPPKey(ctx context.Context, key string) context.Context

Types

type CircuitConfig

type CircuitConfig struct {
	Type       string   `toml:"type"`
	Service    string   `toml:"service"`
	Resource   string   `toml:"resource"`
	End        string   `toml:"end"`
	Open       bool     `toml:"open"`
	Threshold  float64  `toml:"threshold"`
	Strategy   string   `toml:"strategy"`
	MinSamples int64    `toml:"minsamples"`
	RT         duration `toml:"rt"`
}

type ClientOption

type ClientOption func(*ClientOptions)

type ClientOptions

type ClientOptions struct{}

type DefaultCircuit

type DefaultCircuit struct {
	Server Resource `toml:"server"`
	Client Resource `toml:"client"`
}

type Framework

type Framework struct {
	// Name is discovery name, it is from deploy platform by default.
	// Name will be used to register to discovery service
	Name      string
	Namespace string
	JobName   string
	App       string
	// 版本
	Version      string
	Deps         string
	LogDir       string
	LogLevel     string
	LogRotate    string
	ConfigPath   string
	ConfigMemory []byte
	Clusters     *upstream.ClusterManager
	Manager      *registry.ServiceManager
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) (*Framework, bool)

func New

func New() *Framework

func (*Framework) AddAsyncKafkaClient

func (d *Framework) AddAsyncKafkaClient(name string, client *kafka.KafkaClient) error

func (*Framework) AddHTTPClient

func (d *Framework) AddHTTPClient(name string, client httpclient.Client) error

func (*Framework) AddRedisClient

func (d *Framework) AddRedisClient(name string, client *redis.Redis) error

func (*Framework) AddSqlClient

func (d *Framework) AddSqlClient(name string, client *sql.Group) error

func (*Framework) AddSyncKafkaClient

func (d *Framework) AddSyncKafkaClient(name string, client *kafka.KafkaSyncClient) error

func (*Framework) Config

func (d *Framework) Config() *config.Namespace

func (*Framework) ConfigInstance

func (d *Framework) ConfigInstance() config.Config

func (*Framework) File

func (d *Framework) File(files ...string) error

func (*Framework) FindServerClient

func (d *Framework) FindServerClient(service string) (ServerClient, error)

对于以下方法中的service参数说明: 如果对应的server_client配置了app_name选项,则需要调用方保证service参数带上app_name前缀 如果没有配置,则保持原有逻辑, service参数不用改动

func (*Framework) HTTPClient

func (d *Framework) HTTPClient(name string) httpclient.Client

func (*Framework) HTTPServer

func (d *Framework) HTTPServer() httpserver.Server

func (*Framework) Init

func (d *Framework) Init(options ...Option)

func (*Framework) InitKafkaConsume

func (d *Framework) InitKafkaConsume(kccList []kafka.KafkaConsumeConfig) error

func (*Framework) InitKafkaProducer

func (d *Framework) InitKafkaProducer(kpcList []kafka.KafkaProductConfig) error

func (*Framework) InitRedisClient

func (d *Framework) InitRedisClient(rcList []redis.RedisConfig) error

func (*Framework) InitSqlClient

func (d *Framework) InitSqlClient(sqlList []sql.SQLGroupConfig) error

func (*Framework) InjectServerClient

func (d *Framework) InjectServerClient(sc ServerClient)

func (*Framework) KafkaConsumeClient

func (d *Framework) KafkaConsumeClient(consumeFrom string) *kafka.KafkaConsumeClient

func (*Framework) KafkaProducerClient

func (d *Framework) KafkaProducerClient(producerTo string) *kafka.KafkaClient

func (*Framework) RPCFactory

func (d *Framework) RPCFactory(name string) rpcclient.Factory

RPC create a new rpc client instance, default use http protocol.

func (*Framework) RPCServer

func (d *Framework) RPCServer() rpcserver.Server

func (*Framework) RedisClient

func (d *Framework) RedisClient(name string) *redis.Redis

func (*Framework) Remote

func (d *Framework) Remote(paths ...string) error

func (*Framework) RemoteKV

func (d *Framework) RemoteKV(path string) (string, error)

path param is "/config", remote path is "/service_config/link/link.time.confignew/config"

func (*Framework) SQLClient

func (d *Framework) SQLClient(name string) *sql.Group

func (*Framework) ServiceClientWithApp

func (d *Framework) ServiceClientWithApp(appName, serviceName string) (ServerClient, error)

func (*Framework) Shutdown

func (d *Framework) Shutdown() error

func (*Framework) SyncProducerClient

func (d *Framework) SyncProducerClient(producerTo string) *kafka.KafkaSyncClient

func (*Framework) WatchKV

func (d *Framework) WatchKV(path string) config.Watcher

func (*Framework) WatchPrefix

func (d *Framework) WatchPrefix(path string) config.Watcher

type JSONDataLogOption

type JSONDataLogOption struct {
	Path     string `toml:"path"`
	Rotate   string `toml:"rotate"`
	TaskName string `toml:"task_name"`
}

type Mode

type Mode int

Mode TODO

const (
	// Deprecated: Development func should not use anymore.
	Development Mode = iota // 0
	// Deprecated: Production func should not use anymore.
	Production // 1
)

func (*Mode) String deprecated

func (m *Mode) String() string

Deprecated: String func should not use anymore.

type Option

type Option func(framework *Framework)

func App

func App(app string) Option

func ConfigMemory

func ConfigMemory(mem []byte) Option

func ConfigPath

func ConfigPath(path string) Option

func ConsulAddr deprecated

func ConsulAddr(addr string) Option

Deprecated: ConsulAddr func should not use anymore. 可以使用用户输入: -consul-addr="127.0.0.1:8500" 或者环境变量: "CONSUL_ADDR"

func Deps

func Deps(deps string) Option

func Kit deprecated

func Kit(kit log.Kit) Option

Deprecated: Kit func should not use anymore.

func Name

func Name(name string) Option

func Namespace

func Namespace(namespace string) Option

func NamespaceDir

func NamespaceDir(dir string) Option

func RunMode deprecated

func RunMode(mode Mode) Option

Deprecated: RunMode func should not use anymore.

func TraceReportAddr deprecated

func TraceReportAddr(addr string) Option

Deprecated: TraceReportAddr func should not use anymore. 可以使用用户输入: -trace-addr="127.0.0.1:6831" 或者环境变量: "TRACE_ADDR"

func Tracer deprecated

func Tracer(tracer opentracing.Tracer) Option

Deprecated: Tracer func should not use anymore.

func Version

func Version(ver string) Option

type Resource

type Resource struct {
	ratelimit.LimiterConfig
	breaker.BreakerConfig
}

type ServerClient

type ServerClient struct {
	// 应用名称
	APPName *string `toml:"app_name"`
	// 服务发现名称
	ServiceName string `toml:"service_name"`
	Ipport      string `toml:"endpoints"`
	Balancetype string `toml:"balancetype"`
	// 请求协议,比如http
	ProtoType           string `toml:"proto"`
	ConnectTimeout      int    `toml:"connect_timeout"`
	Namespace           string `toml:"namespace"`
	ReadTimeout         int    `toml:"read_timeout"`
	WriteTimeout        int    `toml:"write_timeout"`
	KeepaliveTimeout    int    `toml:"keepalive_timeout"`
	MaxIdleConns        int    `toml:"max_idleconn"`
	MaxIdleConnsPerHost int    `toml:"max_idleconn_perhost"`
	RetryTimes          int    `toml:"retry_times"`
	SlowTime            int    `toml:"slow_time"`
	EndpointsFrom       string `toml:"endpoints_from"`
	ConsulName          string `toml:"consul_name"`
	LoadBalanceStat     bool   `toml:"loadbalance_stat"`
	DC                  string `toml:"dc,omitempty"`

	// checker config
	CheckInterval      upstreamconfig.Duration `toml:"check_interval"`
	UnHealthyThreshold uint32                  `toml:"check_unhealth_threshold"`
	HealthyThreshold   uint32                  `toml:"check_healthy_threshold"`

	// lb advance config
	LBPanicThreshold int        `toml:"lb_panic_threshold"`
	LBSubsetKeys     [][]string `toml:"lb_subset_selectors"`
	LBDefaultKeys    []string   `toml:"lb_default_keys"`

	// detector config
	DetectInterval             upstreamconfig.Duration `toml:"detect_interval"`
	BaseEjectionDuration       upstreamconfig.Duration `toml:"base_ejection_duration"`
	ConsecutiveError           uint64                  `toml:"consecutive_error"`
	ConsecutiveConnectionError uint64                  `toml:"consecutive_connect_error"`
	MaxEjectionPercent         uint64                  `toml:"max_ejection_percent"`
	SuccessRateMinHosts        uint64                  `toml:"success_rate_min_hosts"`
	SuccessRateRequestVolume   uint64                  `toml:"success_rate_request_volume"`
	SuccessRateStdevFactor     float64                 `toml:"success_rate_stdev_factor"`
	Cluster                    upstreamconfig.Cluster

	Resource map[string]Resource `toml:"resource"` // 当用于http服务调用时, key=uri; 当用于rpc服务调用时, key=func_name; * 通配置
}

ServerClient 远程服务客户端配置

Directories

Path Synopsis
Package circuit implements the Circuit Breaker pattern.
Package circuit implements the Circuit Breaker pattern.
Package config is an interface for dynamic configuration.
Package config is an interface for dynamic configuration.
encoder
Package encoder handles source encoding formats
Package encoder handles source encoding formats
loader
package loader manages loading from multiple sources
package loader manages loading from multiple sources
reader
Package reader parses change sets and provides config values
Package reader parses change sets and provides config values
source
Package source is the interface for sources
Package source is the interface for sources
source/file
Package file is a file source.
Package file is a file source.
source/memory
Package memory is a memory source
Package memory is a memory source
http
internal
Package rate provides a rate limiter.
Package rate provides a rate limiter.
rpc

Jump to

Keyboard shortcuts

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