Documentation ¶
Index ¶
- Variables
- func BytesToStr(value []byte) string
- func DecodeKey(value string) (string, error)
- func EncodeKey(value string) string
- func FormatTime(str string) string
- func InStr(s []string, str string) bool
- func LoadConfigFile(configPath string) error
- func ParseRoute(key, keyPrefix string) (routeGroupID, routePath, routeMethod string, err error)
- func StrToBytes(s string) []byte
- func SyncMapClean(m *sync.Map)
- func SyncMapLen(m *sync.Map) (count int)
- type DiscoverType
- type HostType
- type MiddlewareType
- type ModuleConfig
- type NodeType
- type ServiceType
- type StorageType
Constants ¶
This section is empty.
Variables ¶
var ( SnowflakeNode *snowflake.Node Storage StorageType // 存储器 Hosts sync.Map // 主机 key=hostname, value=HostType HostMiddleware sync.Map // 主机中间件 key=hostname, value=[]MiddlewareType Routes sync.Map // 路由 key=routeGroupID@path@method, value=serviceID Services sync.Map // 服务 key=RouteGroupID, value=ServiceType ServicesMiddleware sync.Map // 服务中间件 key=MiddlewareName, value=[]MiddlewareType // HTTP方法允许的值 HTTPMethods = []string{ "ANY", "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE", "CONNECT", } )
var Config struct { Logger struct { Level string `yaml:"level"` FilePath string `yaml:"filePath"` FileMode os.FileMode `yaml:"fileMode"` Encode string `yaml:"encode"` TimeFormat string `yaml:"timeFormat"` } `yaml:"logger"` Storage struct { Name string `yaml:"name"` Config string `yaml:"config"` } `yaml:"storage"` Proxy struct { IP string `yaml:"ip"` QuitWaitTimeout time.Duration `yaml:"quitWaitTimeout"` ReadTimeout time.Duration `yaml:"readTimeout"` ReadHeaderTimeout time.Duration `yaml:"readHeaderTimeout"` WriteTimeout time.Duration `yaml:"writeTimeout"` IdleTimeout time.Duration `yaml:"idleTimeout"` HTTP struct { Port uint16 `yaml:"port"` } `yaml:"http"` HTTPS struct { Port uint16 `yaml:"port"` HTTP2 bool `yaml:"http2"` CertFile string `yaml:"certFile"` KeyFile string `yaml:"keyFile"` } `yaml:"https"` } `yaml:"proxy"` API struct { IP string `yaml:"ip"` Secret string `yaml:"secret"` QuitWaitTimeout time.Duration `yaml:"quitWaitTimeout"` ReadTimeout time.Duration `yaml:"readTimeout"` ReadHeaderTimeout time.Duration `yaml:"readHeaderTimeout"` WriteTimeout time.Duration `yaml:"writeTimeout"` IdleTimeout time.Duration `yaml:"idleTimeout"` HTTP struct { Port uint16 `yaml:"port"` } `yaml:"http"` HTTPS struct { Port uint16 `yaml:"port"` HTTP2 bool `yaml:"http2"` CertFile string `yaml:"certFile"` KeyFile string `yaml:"keyFile"` } `yaml:"https"` } `yaml:"api"` }
引擎配置
Functions ¶
func BytesToStr ¶
func FormatTime ¶
func ParseRoute ¶
从键名解析路由信息
func StrToBytes ¶
Types ¶
type HostType ¶
type HostType struct { RouteGroupID string `json:"route_group_id"` // 路由分组ID Middleware []ModuleConfig `json:"middleware,omitempty"` // 中间件配置 }
主机
func (HostType) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (HostType) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*HostType) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*HostType) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type MiddlewareType ¶
type MiddlewareType interface { Action(http.ResponseWriter, *http.Request) (bool, error) GetName() string }
中间件接口
type ModuleConfig ¶
type ModuleConfig struct { Name string `json:"name,omitempty"` Config string `json:"config,omitempty"` }
用于构建服务、中间件、存储器模块时的参数配置
func (ModuleConfig) MarshalEasyJSON ¶
func (v ModuleConfig) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (ModuleConfig) MarshalJSON ¶
func (v ModuleConfig) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*ModuleConfig) UnmarshalEasyJSON ¶
func (v *ModuleConfig) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ModuleConfig) UnmarshalJSON ¶
func (v *ModuleConfig) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type NodeType ¶
func (NodeType) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (NodeType) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*NodeType) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*NodeType) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type ServiceType ¶
type ServiceType struct { ID string `json:"id"` // 服务ID // Retry uint8 `json:"retry,omitempty"` // 重试次数,默认为0,表示不重试 // RetryInterval uint16 `json:"retry_interval,omitempty"` // 重试间隔时间(毫秒),默认为0表示不间隔 Middleware []ModuleConfig `json:"middleware,omitempty"` // 中间件配置 StaticEndpoint string `json:"static_endpoint,omitempty"` // 静态端点地址,优先级高于Discover Discover ModuleConfig `json:"discover,omitempty"` // 探测器配置 }
服务
func (ServiceType) MarshalEasyJSON ¶
func (v ServiceType) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (ServiceType) MarshalJSON ¶
func (v ServiceType) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*ServiceType) UnmarshalEasyJSON ¶
func (v *ServiceType) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ServiceType) UnmarshalJSON ¶
func (v *ServiceType) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type StorageType ¶
type StorageType interface { LoadAll() error // 从存储器加载所有数据到本地 SaveAll() error // 将本地所有数据保存到存储器 LoadAllHost() error // 从存储器加载所有主机数据到本地 SaveAllHost() error // 将本地所有主机数据保存到存储器 LoadHost(string, []byte) error // 从存储器加载单个主机数据 SaveHost(string, string) error // 将本地单个主机数据保存到存储器 DeleteLocalHost(string) error // 删除本地单个主机数据 DeleteStorageHost(string) error // 删除存储器中单个主机数据 LoadAllService() error // 从存储器加载所有服务到本地 LoadService([]byte) error // 从存储器加载单个服务数据 SaveAllService() error // 将本地所有服务数据保存到存储器 SaveService(string, string) error // 将本地单个服务数据保存到存储器 DeleteLocalService(string) error // 删除本地单个服务数据 DeleteStorageService(string) error // 删除存储器中单个服务数据 LoadAllRoute() error // 从存储器加载所有路由数据到本地 LoadRoute(string, []byte) error // 从存储器加载单个路由数据 SaveAllRoute() error // 将本地所有路由保存到存储器 SaveRoute(string, string, string, string) error // 将本地单个路由数据保存到存储器 DeleteLocalRoute(string) error // 删除本地单个路由数据 DeleteStorageRoute(string, string, string) error // 删除存储器中单个路由数据 Watch() error // 监听存储器的数据变更 }
存储器