service

package
v0.0.0-...-164dcff Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CorsAllowOrigin      = []string{"gaodun.com", "gaodunwangxiao.com"}
	CorsAllowMethods     = "HEAD,GET,POST,PUT,DELETE"
	CorsAllowCredentials = "true"
	CorsAllowHead        = "Origin, X-Requested-With, Content-Type, Accept, Authtoken, Authentication, X_Requested_With, X-Request-ID"
	ExposeHeaders        = "AccessToken, RefreshToken"
)
View Source
var (
	// ServiceName 服务名称
	ServiceName = "XService"
	// ServiceVersion 版本
	ServiceVersion = "1.0.0.1"
	// Concurrency Concurrency
	Concurrency = 100000
	// DisableKeepalive DisableKeepalive
	DisableKeepalive = true
	//Timeout Timeout
	Timeout = 60 * time.Second
	// MaxConnsPerIP MaxConnsPerIP
	MaxConnsPerIP = 100000
	// MaxRequestsPerConn MaxRequestsPerConn
	MaxRequestsPerConn = 100000
	// MaxKeepaliveDuration MaxKeepaliveDuration
	MaxKeepaliveDuration = 120 * time.Second
	// MaxRequestBodySize MaxRequestBodySize
	MaxRequestBodySize = 512 * 1024 * 1024
	// ReadBufferSize ReadBufferSize
	ReadBufferSize = 16 * 1024
	// WriteBufferSize WriteBufferSize
	WriteBufferSize = 16 * 1024
)
View Source
var (
	OPTIONS = []byte("OPTIONS")
)

Logger 日志插件

Functions

func AddRote

func AddRote(path string, r Route)

AddRote 添加路由

func BindRote

func BindRote(path string, methods []string, handle func(*routing.Context) error)

BindRote 注册绑定路由

func GetRoute

func GetRoute() *routing.Router

func GetServer

func GetServer() *fasthttp.Server

func GetUID

func GetUID() string

return unique id

func NewUniqueIDAsync

func NewUniqueIDAsync()

异步 unique id

func NewUniqueIDBlocked

func NewUniqueIDBlocked()

阻塞式 unique id

func RegisterGroup

func RegisterGroup(router *routing.Router, group IResourceGrouper)

调用此接口将一组API注册到总路由器

func RegsitRouter

func RegsitRouter(router *routing.Router, regRouter IRegistRouter)

func Run

func Run(n net.Listener)

Run 启动服务

Types

type BaseGroup

type BaseGroup struct{}

示例Group

func (BaseGroup) GetAuthor

func (bg BaseGroup) GetAuthor(ctx *routing.Context) (err error)

示例API, 返回作者信息

func (BaseGroup) GetResourceMap

func (bg BaseGroup) GetResourceMap() map[string]Resource

实现IResourceGrouper接口

func (BaseGroup) PutAuthor

func (bg BaseGroup) PutAuthor(ctx *routing.Context) (err error)

type BaseResponse

type BaseResponse struct {
	HTTPCode int         `json:"http_code,omitempty"`
	Status   int         `json:"status"`
	Info     string      `json:"info"`
	Result   interface{} `json:"result"`
}

BaseResponse 返回参数

type BaseServer

type BaseServer struct {
	Logger func(title string, msg map[string]interface{})
}

BaseServer 服务基类

func (*BaseServer) Cors

func (bs *BaseServer) Cors(ctx *routing.Context) (err error)

Cors 跨域

func (*BaseServer) FormInt64

func (bs *BaseServer) FormInt64(ctx *routing.Context, key string) int64

FormInt64 获取int

func (*BaseServer) FormString

func (bs *BaseServer) FormString(ctx *routing.Context, key string) string

FormString 获取字符串

func (*BaseServer) GetRouterMap

func (bs *BaseServer) GetRouterMap() map[string]Route

GetRouterMap 路由表

func (*BaseServer) GetStatus

func (bs *BaseServer) GetStatus(ctx *routing.Context) (err error)

GetStatus 状态页

func (*BaseServer) HandleRoot

func (bs *BaseServer) HandleRoot(ctx *routing.Context) (err error)

HandleRoot 测试页

func (*BaseServer) ServerJSON

func (bs *BaseServer) ServerJSON(ctx *routing.Context, v interface{}, status int)

ServerJSON 服务器返回

type Decorator

type Decorator struct {
	RunFuc  func(ctx *routing.Context) error
	PathStr string
}

Decorator 控制拦截

var Dct Decorator

func (Decorator) Decorator

func (d Decorator) Decorator(ctx *routing.Context) (err error)

func (Decorator) GetVerifyList

func (d Decorator) GetVerifyList() map[string]bool

func (Decorator) SetCorsHeader

func (d Decorator) SetCorsHeader(ctx *routing.Context)

func (Decorator) SetVerifyList

func (d Decorator) SetVerifyList(key string)

type IRegistRouter

type IRegistRouter interface {
	GetRouterMap() map[string]Route
}

IRegistRouter 注册路由接口

type IResourceGrouper

type IResourceGrouper interface {
	GetResourceMap() map[string]Resource
}

实现此接口的类可以被注册路由 返回 path -> resource 注册表

type Resource

type Resource map[string]routing.Handler

RESTful 资源 每种HTTP Method对应一个Handler

type Route

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

Route 路由

Jump to

Keyboard shortcuts

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