server

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 默认最大连接数
	MAX_CONNECTION = 5000
	// 注册信息更新间隔, 秒
	REGISTRY_REFRESH_INTERVAL = 60
)
View Source
const (
	SERVICE_NAME = "key_service_name"
	REQUEST_PATH = "key_request_path"
	ROUTE_INFO   = "key_route_info"

	RELOAD_PATH = "/_mgr/reload"
)
View Source
const META_VERSION = "version"

Variables

This section is empty.

Functions

func GetStringFromUserValue

func GetStringFromUserValue(ctx *fasthttp.RequestCtx, key string) string

从请求上下文中取出string

func InitGogate

func InitGogate(gogateConfigFile, logConfigFile string)

func RateLimitPreFilter

func RateLimitPreFilter(s *Server, ctx *fasthttp.RequestCtx, newRequest *fasthttp.Request) bool

控制QPS的前置过虑器

func ServiceMatchPreFilter

func ServiceMatchPreFilter(s *Server, ctx *fasthttp.RequestCtx, newRequest *fasthttp.Request) bool

func UrlRewritePreFilter

func UrlRewritePreFilter(s *Server, ctx *fasthttp.RequestCtx, newRequest *fasthttp.Request) bool

Types

type CanaryInfo

type CanaryInfo struct {
	Meta   string
	Weight int
}

type GogateResponse

type GogateResponse struct {
	Path  string `json:"path"`
	Error string `json:"error"`
}

func NewResponse

func NewResponse(path, msg string) *GogateResponse

func (*GogateResponse) Send

func (resp *GogateResponse) Send(ctx *fasthttp.RequestCtx)

func (*GogateResponse) SendWithStatus

func (resp *GogateResponse) SendWithStatus(ctx *fasthttp.RequestCtx, statusCode int)

func (*GogateResponse) ToJson

func (resp *GogateResponse) ToJson() string

func (*GogateResponse) ToJsonBytes

func (resp *GogateResponse) ToJsonBytes() []byte

type InsInfoArrSyncMap

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

封装sync.map, 提供类型安全的方法调用

func NewInsInfoArrSyncMap

func NewInsInfoArrSyncMap() *InsInfoArrSyncMap

func (*InsInfoArrSyncMap) Each

func (ism *InsInfoArrSyncMap) Each(eachFunc func(key string, val []*InstanceInfo) bool)

func (*InsInfoArrSyncMap) Get

func (ism *InsInfoArrSyncMap) Get(key string) ([]*InstanceInfo, bool)

func (*InsInfoArrSyncMap) GetMap

func (ism *InsInfoArrSyncMap) GetMap() *sync.Map

func (*InsInfoArrSyncMap) Put

func (ism *InsInfoArrSyncMap) Put(key string, val []*InstanceInfo)

type InsLbClientSyncMap

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

封装sync.map, 提供类型安全的方法调用

func NewInsMetaLbClientSyncMap

func NewInsMetaLbClientSyncMap() *InsLbClientSyncMap

func (*InsLbClientSyncMap) Get

func (ism *InsLbClientSyncMap) Get(key string) (*fasthttp.LBClient, bool)

func (*InsLbClientSyncMap) Put

func (ism *InsLbClientSyncMap) Put(key string, val *fasthttp.LBClient)

type InstanceInfo

type InstanceInfo struct {
	// 格式为 host:port
	Addr string
	// eureka中的meta信息
	Meta map[string]string
}

封装服务实例信息

type PostFilter

type PostFilter struct {
	FilterFunc PostFilterFunc
	Name       string
}

后置过滤器对象

func NewPostFilter

func NewPostFilter(name string, filter PostFilterFunc) *PostFilter

func (*PostFilter) String

func (pf *PostFilter) String() string

type PostFilterFunc

type PostFilterFunc func(req *fasthttp.Request, resp *fasthttp.Response) bool

后置过滤器函数

type PreFilter

type PreFilter struct {
	FilterFunc PreFilterFunc
	Name       string
}

前置过滤器对象

func NewPreFilter

func NewPreFilter(name string, filter PreFilterFunc) *PreFilter

func (*PreFilter) String

func (pf *PreFilter) String() string

type PreFilterFunc

type PreFilterFunc func(server *Server, ctx *fasthttp.RequestCtx, newRequest *fasthttp.Request) bool

前置过滤器函数

type RateLimiterSyncMap

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

封装sync.map, 提供类型安全的方法调用

func NewRateLimiterSyncMap

func NewRateLimiterSyncMap() *RateLimiterSyncMap

func (*RateLimiterSyncMap) Get

func (*RateLimiterSyncMap) Put

func (rsm *RateLimiterSyncMap) Put(key string, val throttle.RateLimiter)

type Router

type Router struct {
	ServInfos []*ServiceInfo
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(path string) (*Router, error)

* 创建路由器 * * PARAMS: * - path: 路由配置文件路径 *

func (*Router) ExtractRoute

func (r *Router) ExtractRoute() string

* 将路由信息转换成string返回

func (*Router) Match

func (r *Router) Match(reqPath string) *ServiceInfo

* 根据uri选择一个最匹配的appId * * RETURNS: * 返回最匹配的ServiceInfo

func (*Router) ReloadRoute

func (r *Router) ReloadRoute() error

* 重新加载路由器

type ServInfoSyncMap

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

封装sync.map, 提供类型安全的方法调用

func NewServInfoSyncMap

func NewServInfoSyncMap() *ServInfoSyncMap

func (*ServInfoSyncMap) Each

func (ssm *ServInfoSyncMap) Each(eachFunc func(key string, val *ServiceInfo) bool)

func (*ServInfoSyncMap) Get

func (ssm *ServInfoSyncMap) Get(key string) (*ServiceInfo, bool)

func (*ServInfoSyncMap) GetMap

func (ssm *ServInfoSyncMap) GetMap() *sync.Map

func (*ServInfoSyncMap) Put

func (ssm *ServInfoSyncMap) Put(key string, val *ServiceInfo)

type Server

type Server struct {

	// URI路由组件
	Router *Router
	// contains filtered or unexported fields
}

func NewGatewayServer

func NewGatewayServer(host string, port int, routePath string, maxConn int, useGracefullyShutdown bool, maxWait time.Duration) (*Server, error)

* 创建网关服务对象 * * PARAMS: * - host: 主机名(ip) * - port: 端口 * - routePath: 路由配置文件路径 * - maxConn: 最大连接数, 0表示使用默认值 *

func (*Server) AppendPostFilter

func (serv *Server) AppendPostFilter(post *PostFilter)

注册过滤器, 追加到末尾

func (*Server) AppendPreFilter

func (serv *Server) AppendPreFilter(pre *PreFilter)

注册过滤器, 追加到末尾

func (*Server) ExportAllPostFilters

func (serv *Server) ExportAllPostFilters() []*PostFilter

导出所有后置过滤器

func (*Server) ExportAllPreFilters

func (serv *Server) ExportAllPreFilters() []*PreFilter

导出所有前置过滤器

func (*Server) ExtractRoute

func (serv *Server) ExtractRoute() string

将全部路由信息以字符串形式返回

func (*Server) HandleRequest

func (serv *Server) HandleRequest(ctx *fasthttp.RequestCtx)

HTTP请求处理方法.

func (*Server) InsertPostFilterAhead

func (serv *Server) InsertPostFilterAhead(filter *PostFilter)

在最头部添加后置过滤器

func (*Server) InsertPostFilterBehind

func (serv *Server) InsertPostFilterBehind(filterName string, filter *PostFilter) bool

在指定后置过滤器的后面添加; filterName: 在此过滤器后面添加filter, 如果要在队头添加, 则使用空字符串 filter: 过滤器对象

func (*Server) InsertPreFilterAhead

func (serv *Server) InsertPreFilterAhead(filter *PreFilter)

在最头部添加前置过滤器

func (*Server) InsertPreFilterBehind

func (serv *Server) InsertPreFilterBehind(filterName string, filter *PreFilter) bool

在指定前置过滤器的后面添加

func (*Server) ReloadRoute

func (serv *Server) ReloadRoute() error

更新路由配置文件

func (*Server) Shutdown

func (serv *Server) Shutdown() error

关闭server

func (*Server) Start

func (serv *Server) Start() error

启动服务器

func (*Server) WaitForGracefullyClose

func (serv *Server) WaitForGracefullyClose() error

需要在Shutdown()之后调用, 此方法会一直block直到所有连接关闭或者超时

type ServiceInfo

type ServiceInfo struct {
	Id          string
	Prefix      string
	Host        string
	StripPrefix bool `yaml:"strip-prefix"`
	Qps         int

	Canary []*CanaryInfo
}

func GetServiceInfoFromUserValue

func GetServiceInfoFromUserValue(ctx *fasthttp.RequestCtx, key string) (*ServiceInfo, bool)

从请求上下文中取出*ServiceInfo

func (*ServiceInfo) String

func (info *ServiceInfo) String() string

type StrStrSyncMap

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

封装sync.map, 提供类型安全的方法调用

func NewStrStrSyncMap

func NewStrStrSyncMap() *StrStrSyncMap

func (*StrStrSyncMap) Each

func (ssm *StrStrSyncMap) Each(eachFunc func(key string, val string) bool)

func (*StrStrSyncMap) Get

func (ssm *StrStrSyncMap) Get(key string) (string, bool)

func (*StrStrSyncMap) GetMap

func (ssm *StrStrSyncMap) GetMap() *sync.Map

func (*StrStrSyncMap) Put

func (ssm *StrStrSyncMap) Put(key string, val string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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