api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusTooManyRequests = &Error{
		Code: http.StatusTooManyRequests,
		Msg: ErrMsg{
			"en": http.StatusText(http.StatusTooManyRequests),
			"zh": "请求太频繁,请稍后再试",
		},
	}
)

Functions

func AddGobModels

func AddGobModels(models ...interface{})

func AddLocaleAlias added in v0.2.0

func AddLocaleAlias(locale, alias string)

func AddTranslator added in v0.2.0

func AddTranslator(locale string, t *ut.Translator, alias ...string)

func ErrorWrap added in v0.2.5

func ErrorWrap(err *Error, keysAndValues ...interface{}) error

func GetLanguage added in v0.2.0

func GetLanguage(c *gin.Context) string

func NoRoute added in v0.2.0

func NoRoute(c *gin.Context)

func Validator added in v0.2.0

func Validator() error

func WriteJSON added in v0.2.0

func WriteJSON(w http.ResponseWriter, groups []string, obj interface{}) error

Types

type API

type API struct {
	Session *Session
}

func NewApi added in v0.2.0

func NewApi() *API

func (*API) Context added in v0.2.0

func (a *API) Context(c *gin.Context) *Context

func (*API) Data added in v0.2.0

func (a *API) Data(c *gin.Context, data interface{})

func (*API) Err

func (a *API) Err(c *gin.Context, err error)

func (*API) ErrResp

func (a *API) ErrResp(c *gin.Context, err error)

func (*API) Groups added in v0.2.0

func (a *API) Groups(c *gin.Context, groups ...string)

func (*API) Handler added in v0.2.1

func (a *API) Handler(c *gin.Context, f func(resp *Response) error)

func (*API) HttpStatus added in v0.2.0

func (a *API) HttpStatus(c *gin.Context, status int)

func (*API) Resp

func (a *API) Resp(c *gin.Context)

func (*API) Verifies

func (a *API) Verifies(c *gin.Context, bindsAndFuncs ...interface{}) bool

func (*API) Verify

func (a *API) Verify(c *gin.Context, req interface{}) bool

type Bind

type Bind struct {
	Obj  interface{}
	Func BindFunc
}

func (*Bind) Verify added in v0.2.0

func (b *Bind) Verify(c *gin.Context) (bool, interface{})

type BindFunc added in v0.2.0

type BindFunc func(obj interface{}) error

type Context added in v0.2.0

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

func NewContext added in v0.2.0

func NewContext() *Context

func (*Context) AddGroups added in v0.2.0

func (c *Context) AddGroups(groups ...string)

func (*Context) Groups added in v0.2.0

func (c *Context) Groups() []string

func (*Context) Response added in v0.2.0

func (c *Context) Response() *Response

type DiffGroupsJSON added in v0.2.0

type DiffGroupsJSON struct {
	Groups []string
	Data   interface{}
}

func (DiffGroupsJSON) Render added in v0.2.0

func (d DiffGroupsJSON) Render(w http.ResponseWriter) (err error)

func (DiffGroupsJSON) WriteContentType added in v0.2.0

func (d DiffGroupsJSON) WriteContentType(w http.ResponseWriter)

type ErrMsg added in v0.2.0

type ErrMsg map[string]string

ErrMsg {"en": "user not found", "zh": "用户不存在"}

type Error

type Error struct {
	Code  int
	Msg   ErrMsg
	Debug map[string]interface{}
}

func (*Error) DebugMsg added in v0.2.5

func (e *Error) DebugMsg(keysAndValues ...interface{})

func (*Error) ErrCode

func (e *Error) ErrCode() int

func (*Error) ErrMsg

func (e *Error) ErrMsg(locale string) interface{}

func (*Error) Error

func (e *Error) Error() string

type PageOptional

type PageOptional struct {
	Page int `json:"page" form:"page" binding:"omitempty,gte=1"`
	Size int `json:"size" form:"size" binding:"omitempty,gte=1,lte=50"`
}

type Pageable

type Pageable struct {
	Page int `json:"page" form:"page" binding:"required,gte=1"`
	Size int `json:"size" form:"size" binding:"required,gte=1,lte=50"`
}

type Response

type Response struct {
	Code      int         `json:"code"`
	Data      interface{} `json:"data"`
	Message   interface{} `json:"msg"`
	Timestamp int64       `json:"timestamp"`
	// contains filtered or unexported fields
}

func (*Response) Err

func (r *Response) Err() *Error

func (*Response) GetCode added in v0.2.0

func (r *Response) GetCode() int

func (*Response) GetData added in v0.2.0

func (r *Response) GetData() interface{}

func (*Response) HttpStatus

func (r *Response) HttpStatus() int

func (*Response) Msg added in v0.2.0

func (r *Response) Msg() interface{}

func (*Response) SetCode added in v0.2.0

func (r *Response) SetCode(code int)

func (*Response) SetData added in v0.2.0

func (r *Response) SetData(data interface{})

func (*Response) SetErr added in v0.2.0

func (r *Response) SetErr(err *Error)

func (*Response) SetHttpStatus added in v0.2.0

func (r *Response) SetHttpStatus(status int)

func (*Response) SetMsg added in v0.2.0

func (r *Response) SetMsg(msg interface{})

func (*Response) SetTime added in v0.2.0

func (r *Response) SetTime(timestamp int64)

func (*Response) Time added in v0.2.0

func (r *Response) Time() int64

type Session added in v0.2.0

type Session struct{}

func (*Session) Delete added in v0.2.0

func (s *Session) Delete(c *gin.Context, key interface{}) error

func (*Session) Get added in v0.2.0

func (s *Session) Get(c *gin.Context, key interface{}) interface{}

func (*Session) GetRoles added in v0.2.0

func (s *Session) GetRoles(c *gin.Context) []string

func (*Session) GetToken added in v0.2.0

func (s *Session) GetToken(c *gin.Context) *auth.User

func (*Session) HasRole added in v0.2.0

func (s *Session) HasRole(c *gin.Context, role string) bool

func (*Session) Set added in v0.2.0

func (s *Session) Set(c *gin.Context, key interface{}, val interface{}) error

func (*Session) SetToken added in v0.2.0

func (s *Session) SetToken(c *gin.Context, id int64, state bool) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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