server

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

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 (
	// 默认最大连接数
	MAX_CONNECTION = 5000
)
View Source
const META_VERSION = "version"

Variables

This section is empty.

Functions

func GetServiceInfoFromUserValue

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

从请求上下文中取出*ServiceInfo

func GetStringFromUserValue

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

从请求上下文中取出string

func InitGogate

func InitGogate(gogateConfigFile 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 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 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 Server

type Server struct {

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

func NewGatewayServer

func NewGatewayServer(host string, port int, routePath string, maxConn int) (*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) 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) IsInStaticMode added in v1.3.0

func (serv *Server) IsInStaticMode() 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

启动服务器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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