gos

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MimeHTML           = "text/html"
	MimeJSON           = "application/json"
	MimeFormUrlencoded = "application/x-www-form-urlencoded"
	MimeFormData       = "multipart/form-data"
	HeaderContentType  = "Content-Type"
)
View Source
const (
	HeaderXForwardedProto    = "X-Forwarded-Proto"
	HeaderXForwardedProtocol = "X-Forwarded-Protocol"
	HeaderXForwardedSsl      = "X-Forwarded-Ssl"
	HeaderXUrlScheme         = "X-Url-Scheme"
)

Variables

View Source
var DocGomd = &embed.File{
	FileName:    "doc.gomd",
	FileModTime: 1608536003,
	FileSize:    1307,
	Data: `
H4sIAAAAAAAC/2yU307jRhTG7+cpjkwuIIrjq95YaiVUQLQSJAq5b9xkCG5jO7UnCq1tiaQgVZA0iJIW
WokS7WoXaaU1aFf8383LZMbhal9hNZ4QTDa+mTNnfvPpzDlf4royKMmyRX6tYhU047eibSg/asWfsVlS
akSvOErZctILVjGpgOz7CM3MgOtCelUzMPg+4gJ1nWxAegE7RVuvEt0y+QH6JuIeGWyWQFyfgWFwxS6a
4ZsgbN4gVOBYViMb4PuFOMD+vmHvulyIHQas1ViybGPYO6PtLj1ofb+WWWVnPXrfQahQKBC8SdAKJhtW
SUUA2cxaHqFlrJWwzfffWibBJpHz/JkIAICLqTwASatWK3pR44Urm3K9XpfXLduQa3YFm0WrhEvS+MaS
XsEqSEatQvSqZhMlIksa0QTDq5qi+pNjmRIvE8X69Z1ZrZGsZmuGM9EZ2mmy7jlCHoiI7rfD1+fgQXhx
R0/2wAPa33no3YEHrNMZ9qOjl7eDj3t06x485IEqy7IMo1UsKkykwYuKsTWzjMWcvPhkQex4x8Y7fR3S
OfxLTbcxnyY7Clx3NNkR/twEo+TipmZUK0Imboa4Lyb6EuWSSfGqWd7luWQymjTvJYqc5QHPczLq7Jjm
xDSax2P6C0/2D+l/J6x7ztpvZ9kf+3T3/7nnCpka4YVN0RF1L9q2ZTvTBR8Oj4dB8CT4FXIRgMTdJalS
dj43v/LDYi6XyUkpUBRBD+5ehKcNjhlOWVIl4QVxJqVAfIpCO83h1u/CBxyOzKiCC/FPUR6Ot+nu6aDf
Y43g032LvmoOrvcG17dxVfbPpaia7lwNPvwlkuG/24IRdyObSxNHdL89UeAweM+O/pRSCMBPofGElvP5
bLh7ybYa4WmDHrTiLx1NLPolPxkz4RCN1JwUJAxQv378P3lMg++rcdhMQcLhXCLyBa+Vw3xcahQ5E76L
hZO2+BwAAP//RcmzlRsFAAA=
`,
}
View Source
var DocHtml = &embed.File{
	FileName:    "doc.html",
	FileModTime: 1608541774,
	FileSize:    1202,
	Data: `
H4sIAAAAAAAC/6RUS3PTMBC+51cs4gIzlZ122rR17EyH1xUO4cBRlraxsCwJaROnzeS/M86LxBRaBl28
1rf6HppZ5a8+fH4//fblI1TUmMkg7z5ghJ0V7LFi3QYKNRkAAOQNkgBZiRCRCvZ1+onfsGPIigYLttDY
eheIgXSW0FLBWq2oKhQutES++TkDbTVpYXiUwmBxngz3VKTJ4GS1gmTaVbBe5+l2b4sbbWsIaAoW6cFg
rBCJQRXwvmAVkY9Zmkplk+9RodGLkFik1PomnWmq5iVvRKiVay2XMd5dJsNfyhu+bd2t5NBZOvUAqwPQ
rdItedSP2s4yKF1QGHjpluOTnkbbbdoMLoZD30fFco/e3jyBhpm2GQxBzMmdYl4otRG+vOofu3eWOl+Y
wfnlMbgeHMq7BpUW8ObIwPXo2i/f9iL+Nf+Jj/PffKyfEu4R+oAgncIe83GEiz6vdMaFDF6PRqPxCyRK
42T9Y+4Iwb9U5s9sJEqDQOrsmYaqJ9W6oHgZUNQZ1IieC2NOY7WVJuTRC4kZWNcG4cf/fSnPmEShgMK/
XH4pZD0Lbm4V30viFd6i7Kvm6W6U8nT7fOSd8mSQi0BaGgRpRIwFOzHGNjP/rrPYjfyutePYHU43T9TP
AAAA///3I0uusgQAAA==
`,
}
View Source
var DocIndexGohtml = &embed.File{
	FileName:    "doc_index.gohtml",
	FileModTime: 1608549553,
	FileSize:    1592,
	Data: `
H4sIAAAAAAAC/7SVTVPbPBDH7/kU+/i5tDMoDhkIYOwMM305daY90EOPsrREqmXJlTYvwOS7dxRjiN1Q
4NC9SNF/s7//aux1/t/Hrx+uf3z7BIpqMx/lcQHD7aJI7lQSD5DL+QgAIK+ROAjFfUAqku/Xn9l5si9Z
XmORrDSuG+cpAeEsoaUiWWtJqpC40gLZ7scRaKtJc8OC4AaL4/GkK0WaDM7v72F8HXew3eZpe9bqRtsK
PJoiCXRrMChESkB5vCkSRdSELE2FtOOfQaLRKz+2SKlt6nShSS1LVnNfSbe2TIRwdTKePJF39dp9jPFj
ZunkLdw/CjFKt2FB32m7yKB0XqJnpdtc9nJqbdtuM5hOJs1Q5ZtOvTg/oPqFthlMgC/J9bWGS7kDn5wO
/3bjLEVfmMHxyb64HT1ur2qUmsO7PQNns7Nm837Q4l/77/k4/sPH9hB4ULDxCMJJHFTeb2E6rCuccT6D
/2ez2eUrEKVxovq1dITQvBbzfDXipUEgefRCghqg1s5LVnrkVQYVYsO4Mf221koTstBwgRlYt/a8ufxn
l9K5RC6B/Ftuv+SiWni3tJJ1TDzFCxSvwUoDc5B0kBdfvNi4r7l5+wN9ECRhDnwA60xf7KIPItwQkyic
56SdjW4svhGXKbdC/wx0tosXoEsr0RvdJ++GU/ownfK0nch5hM9Hec21BWF4CEXSM9ZNNTUdDFM1fVCk
eRp2MeWLtlWAbQeMcp7G+nF9wKXtd+J3AAAA///SAP7WOAYAAA==
`,
}

Functions

func IsMapErrorHandled

func IsMapErrorHandled(w http.ResponseWriter, req *http.Request, err error, status *int) (handled bool)

func Render

func Render(w http.ResponseWriter, data interface{}, status *int)

Types

type Context

type Context struct {
	*http.Request

	Printer
	// contains filtered or unexported fields
}

func (*Context) AbsURL

func (c *Context) AbsURL() string

func (*Context) Bind

func (c *Context) Bind(value interface{}) error

func (*Context) GetFormBool

func (c *Context) GetFormBool(name string) bool

func (*Context) GetFormFloat

func (c *Context) GetFormFloat(name string) float64

func (*Context) GetFormInt

func (c *Context) GetFormInt(name string) int64

func (*Context) IsTLS

func (c *Context) IsTLS() bool

func (*Context) MapBad

func (c *Context) MapBad(code, format string, args ...interface{}) *Map

func (*Context) MapUnhandled

func (c *Context) MapUnhandled(code, format string, args ...interface{}) *Map

func (*Context) RealIp

func (c *Context) RealIp() string

func (*Context) Scheme

func (c *Context) Scheme() string

type Doc

type Doc struct {
	Name        string //名称
	Description string //描述
	Path        string //路径

	Errors map[int]M
	Input  interface{}
	Output interface{}

	InputParams []DocParamItem

	sync.Mutex
	// contains filtered or unexported fields
}

func (*Doc) Markdown

func (ad *Doc) Markdown(path string) (md []byte, html string)

type DocParamItem

type DocParamItem struct {
	Name        string //名称
	Type        string //类型
	Description string //描述
	Required    bool   //是否必须
	Example     string //Example
}

type Empty

type Empty struct {
	Code string `json:"code,omitempty"`
}

type HandlerFunc

type HandlerFunc func(*Context) (interface{}, error)

type M

type M map[string]interface{}

func MapOK

func MapOK() M

func (M) Del

func (m M) Del(key string) M

func (M) Get

func (m M) Get(key string) (interface{}, bool)

func (M) MarshalBinary

func (m M) MarshalBinary() ([]byte, error)

func (M) Merge

func (m M) Merge(maps ...M) M

func (M) Set

func (m M) Set(key string, val interface{}) M

type Map

type Map struct {
	M
}

func MapBad

func MapBad(code, format string, args ...interface{}) *Map

输入错误

func MapForbidden

func MapForbidden(code, format string, args ...interface{}) *Map

已验证,无权操作

func MapStatus

func MapStatus(status int) *Map

func MapUnauthorized

func MapUnauthorized(code, format string, args ...interface{}) *Map

未验证,需要登录

func MapUnhandled

func MapUnhandled(code, format string, args ...interface{}) *Map

未处理的错误

func NewMap

func NewMap(maps ...M) *Map

func Redirect

func Redirect(status int, redirectTo string) *Map

func (*Map) Basic

func (m *Map) Basic(code, format string, args ...interface{}) *Map

func (*Map) Del

func (m *Map) Del(key string) *Map

func (*Map) Error

func (m *Map) Error() string

func (Map) MarshalBinary

func (m Map) MarshalBinary() ([]byte, error)

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (*Map) Merge

func (m *Map) Merge(maps ...M) *Map

func (*Map) PopStatus

func (m *Map) PopStatus(status *int) bool

func (*Map) Redirect

func (m *Map) Redirect(status *int, redirectTo *string) bool

func (*Map) Set

func (m *Map) Set(key string, val interface{}) *Map

func (*Map) SetCode

func (m *Map) SetCode(code string) *Map

func (*Map) SetData

func (m *Map) SetData(data interface{}) *Map

func (*Map) SetEx

func (m *Map) SetEx(err error) *Map

func (*Map) SetMessage

func (m *Map) SetMessage(format string, args ...interface{}) *Map

func (*Map) SetStatus

func (m *Map) SetStatus(status int) *Map

func (Map) String

func (m Map) String() string

type Matched

type Matched struct {
	// Either a Node pointer when matched or nil
	Node *Node

	// Either a map contained matched values or empty map.
	Params map[string]string

	// If FixedPathRedirect enabled, it may returns a redirect path,
	// otherwise a empty string.
	FPR string

	// If TrailingSlashRedirect enabled, it may returns a redirect path,
	// otherwise a empty string.
	TSR string
}

Matched is a result returned by trie.Match.

type Mux

type Mux struct {
	Printer
	// contains filtered or unexported fields
}

Mux is a tire base HTTP request router which can be used to dispatch requests to different handler functions.

func New

func New(opts ...Options) *Mux

New returns a Mux instance.

func NewServices

func NewServices(services ...interface{}) *Mux

func (*Mux) Handle

func (m *Mux) Handle(method, pattern string, handler HandlerFunc)

Handle registers a new handler with method and path in the Mux. For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func (*Mux) HandleService

func (m *Mux) HandleService(pathPrefix string, svc interface{})

func (*Mux) HandleServices

func (m *Mux) HandleServices(ss ...interface{})

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Mux) SetBasicAuth

func (m *Mux) SetBasicAuth(auth M)

func (*Mux) Start

func (m *Mux) Start(addr string) error

func (*Mux) StartWith

func (m *Mux) StartWith(s Server) error

type Node

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

Node represents a node on defined patterns that can be matched.

func (*Node) GetAllow

func (n *Node) GetAllow() string

GetAllow returns allow methods defined on the node

trie := New()
trie.Define("/").Handle("GET", handler1)
trie.Define("/").Handle("PUT", handler2)

// trie.Match("/").Node.GetAllow() == "GET, PUT"

func (*Node) GetDescendants

func (n *Node) GetDescendants() []*Node

GetDescendants returns all descendants nodes.

func (*Node) GetHandler

func (n *Node) GetHandler(method string) interface{}

GetHandler ... GetHandler returns handler by method that defined on the node

trie := New()
trie.Define("/api").Handle("GET", func handler1() {})
trie.Define("/api").Handle("PUT", func handler2() {})

trie.Match("/api").Node.GetHandler("GET").(func()) == handler1
trie.Match("/api").Node.GetHandler("PUT").(func()) == handler2

func (*Node) GetMethods

func (n *Node) GetMethods() []string

GetMethods returns methods defined on the node

func (*Node) GetPattern

func (n *Node) GetPattern() string

GetPattern returns pattern defined on the node

func (*Node) Handle

func (n *Node) Handle(method string, handler interface{})

Handle is used to mount a handler with a method name to the node.

t := New()
node := t.Define("/a/b")
node.Handle("GET", handler1)
node.Handle("POST", handler1)

type Options

type Options struct {
	// Ignore case when matching URL path.
	IgnoreCase bool

	// If enabled, the trie will detect if the current path can't be matched but
	// a handler for the fixed path exists.
	// Matched.FPR will returns either a fixed redirect path or an empty string.
	// For example when "/api/foo" defined and matching "/api//foo",
	// The result Matched.FPR is "/api/foo".
	FixedPathRedirect bool

	// If enabled, the trie will detect if the current path can't be matched but
	// a handler for the path with (without) the trailing slash exists.
	// Matched.TSR will returns either a redirect path or an empty string.
	// For example if /foo/ is requested but a route only exists for /foo, the
	// client is redirected to /foo
	// For example when "/api/foo" defined and matching "/api/foo/",
	// The result Matched.TSR is "/api/foo".
	TrailingSlashRedirect bool
}

Options is options for trie.

type Params

type Params map[string]string

Params represents named parameter values

type Printer

type Printer interface {
	Printf(format string, args ...interface{})
}

type Server

type Server interface {
	Start(handler http.Handler) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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