global

package
v0.0.0-...-206c9bf Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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",
	}
)
View Source
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 BytesToStr(value []byte) string

func DecodeKey

func DecodeKey(value string) (string, error)

解码键名

func EncodeKey

func EncodeKey(value string) string

编码键名

func FormatTime

func FormatTime(str string) string

func InStr

func InStr(s []string, str string) bool

InStr 检查string值在一个string slice中是否存在

func LoadConfigFile

func LoadConfigFile(configPath string) error

加载配置文件

func ParseRoute

func ParseRoute(key, keyPrefix string) (routeGroupID, routePath, routeMethod string, err error)

从键名解析路由信息

func StrToBytes

func StrToBytes(s string) []byte

func SyncMapClean

func SyncMapClean(m *sync.Map)

清空sync.Map

func SyncMapLen

func SyncMapLen(m *sync.Map) (count int)

计算sync.Map的长度

Types

type DiscoverType

type DiscoverType interface {
	Fetch(string) (*url.URL, error)
}

端点发现

type HostType

type HostType struct {
	RouteGroupID string         `json:"route_group_id"`       // 路由分组ID
	Middleware   []ModuleConfig `json:"middleware,omitempty"` // 中间件配置
}

主机

func (HostType) MarshalEasyJSON

func (v HostType) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (HostType) MarshalJSON

func (v HostType) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*HostType) UnmarshalEasyJSON

func (v *HostType) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*HostType) UnmarshalJSON

func (v *HostType) UnmarshalJSON(data []byte) error

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

type NodeType struct {
	IP   string `json:"ip"`
	Port uint16 `json:"port"`
}

func (NodeType) MarshalEasyJSON

func (v NodeType) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (NodeType) MarshalJSON

func (v NodeType) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*NodeType) UnmarshalEasyJSON

func (v *NodeType) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*NodeType) UnmarshalJSON

func (v *NodeType) UnmarshalJSON(data []byte) error

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 // 监听存储器的数据变更
}

存储器

Jump to

Keyboard shortcuts

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