middleware

package module
v0.0.0-...-59d529b Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 12 Imported by: 0

README

gin-middleware

gin-middleware

Documentation

Index

Constants

View Source
const (
	DefaultKey = "github.com/forease/gin-middleware"
)

Variables

View Source
var (
	DefaultLang = "zh_CN"
)

Functions

func AuthRequest

func AuthRequest(disUrls ...string) gin.HandlerFunc

setup not need check authorize URL

 	urls := []string{"/login", "/users", "/firewall"}
	    router.Use(middleware.AuthRequest(urls...))

func EncodeMsg

func EncodeMsg(msg Msg) (body []byte, err error)

func I18N

func I18N(args ...string) gin.HandlerFunc

func LoadLocales

func LoadLocales(dir string) error

func NewContext

func NewContext() gin.HandlerFunc

NewContext -

func NewSession

func NewSession(opt ...session.Option) gin.HandlerFunc

NewSession -

func StructToString

func StructToString(data interface{}) string

StructToString convert struct to string

func Tr

func Tr(format string, args ...interface{}) string

Types

type Context

type Context struct {
	*gin.Context
	// contains filtered or unexported fields
}

Context -

func Default

func Default(c *gin.Context) *Context

Default shortcut to get context

func (*Context) AuthFailed

func (c *Context) AuthFailed()

AuthFailed write auth failed message to client

func (*Context) Clear

func (c *Context) Clear()

Clear -

func (*Context) Data

func (c *Context) Data() (data map[interface{}]interface{})

Data -

func (*Context) DataTable

func (c *Context) DataTable(draw, total, datas interface{}) G

DataTable get Datatable

func (*Context) Delete

func (c *Context) Delete(key string)

Delete -

func (*Context) Get

func (c *Context) Get(key string) (interface{}, bool)

Get data

func (*Context) HMessage

func (c *Context) HMessage(code int, url, message string, v ...interface{})

HMessage Render HTML message

func (*Context) JMessage

func (c *Context) JMessage(code int, url, message string, v ...interface{})

JMessage message Render JSON message

func (*Context) ParamDefault

func (c *Context) ParamDefault(key, defaultValue string) string

ParamDefault -

func (*Context) ParamInt64Default

func (c *Context) ParamInt64Default(key string, defaultValue int64) int64

Param

ParamInt64Default -

func (*Context) QueryInt64Default

func (c *Context) QueryInt64Default(key string, defaultValue int64) int64

QueryInt64Default -

func (*Context) QueryIntDefault

func (c *Context) QueryIntDefault(key string, defaultValue int) int

query value

QueryIntDefault -

func (*Context) ReadRequest

func (c *Context) ReadRequest(body interface{}) (req *Request, err error)

ReadRequest read client's json data

func (*Context) SessClear

func (c *Context) SessClear() error

SessClear -

func (*Context) SessDelete

func (c *Context) SessDelete(key string) interface{}

SessDelete -

func (*Context) SessGet

func (c *Context) SessGet(key string, value interface{}) (err error)

SessGet -

func (*Context) SessGetValue

func (c *Context) SessGetValue(key string) (interface{}, bool)

SessGetValue -

func (*Context) SessSave

func (c *Context) SessSave()

SessSave -

func (*Context) SessSet

func (c *Context) SessSet(key string, value interface{})

SessSet -

func (*Context) Session

func (c *Context) Session() session.Store

Session sessions

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set -

func (*Context) WriteResponse

func (c *Context) WriteResponse(code int, body interface{}, message string, v ...interface{})

WriteResponse write json to client

type G

type G map[string]interface{}

G -

type Msg

type Msg struct {
	Code    int    // status code
	Message string // status message
	Url     string // redirect url
}

func DecodeMsg

func DecodeMsg(body []byte) (msg Msg, err error)

type ReqHeader

type ReqHeader struct {
	Action string
	Time   string
}

ReqHeader request header

type Request

type Request struct {
	Header ReqHeader   // request header
	Body   interface{} // body
}

Request -

func RequestReader

func RequestReader(input io.ReadCloser, body interface{}) (req *Request, err error)

RequestReader read request data

func (*Request) String

func (req *Request) String() string

type Response

type Response struct {
	Code    int         // custom status code
	Message string      // message
	Body    interface{} // body
}

Response -

func ResponseWriter

func ResponseWriter(code int, message string, body interface{}) (res *Response)

ResponseWriter initial response data code: status code message: response messages body: response body

func (*Response) String

func (res *Response) String() string

Jump to

Keyboard shortcuts

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