api

package
v0.0.0-...-a4f8eeb Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	API    = []*APIItem{}
	Menu   = []*MenuItem{}
	Router *gin.RouterGroup
	Locker sync.Mutex
)
View Source
var RspMsg = [CodeMax]string{
	"response.success",
	"response.user.invalid",
	"response.user.exist",
	"response.recaptcha.invalid",
	"response.restart",
	"response.group.notexist",
	"response.group.exist",
	"response.group.rootupdate",
	"response.group.rootdelete",
	"response.plugin.notexist",
	"response.plugin.formaterror",
	"response.plugin.exist",
}

Functions

func AddAPI

func AddAPI(item []*APIItem)

func AddMenu

func AddMenu(item *MenuItem, parent uuid.UUID) bool

func CheckPerm

func CheckPerm(perm map[uuid.UUID]*handler.Perm, target *handler.Perm) bool

func GetMenuPluginID

func GetMenuPluginID(req *Request) ([]uuid.UUID, error)

func Init

func Init(r *gin.RouterGroup)

Types

type APIFunc

type APIFunc func(r *Request) (*Response, error)

APIFunc is API function type.

id is current user id when user signin, otherwise uuid.Nil.

return http response and error.

type APIItem

type APIItem struct {
	Path    string          // API path
	Method  APIMethod       // API http method
	Perm    *handler.Perm   // API permission
	Func    APIFunc         // API function
	Checker PermCheckerFunc // custom perm checker, invoke when default perm check failed
}

APIItem is API item struct.

type APIMethod

type APIMethod int32

APIMethod is http method for API.

const (
	// APIGet represents HTTP Get method
	APIGet APIMethod = iota
	// APIPost represents HTTP Post method
	APIPost
	// APIPut represents HTTP Put method
	APIPut
	// APIPatch represents HTTP Patch method
	APIPatch
	// APIDelete represents HTTP Delete method
	APIDelete
	// APIOptions represents HTTP Options method
	APIOptions
	// APIHead represents HTTP Head method
	APIHead
	// APIAny represents any HTTP method
	APIAny
)
type MenuItem struct {
	ID        uuid.UUID
	Name      string
	Path      string
	Icon      string
	OmitEmpty bool
	Children  []*MenuItem
	Perm      *handler.Perm
	Checker   PermCheckerFunc
}
func (m *MenuItem) Check(p map[uuid.UUID]*handler.Perm) bool

type PermCheckerFunc

type PermCheckerFunc func(perm map[uuid.UUID]*handler.Perm) bool

SNCheckerFunc is permission checker function type.

type Request

type Request struct {
	ID         uuid.UUID
	Context    *gin.Context
	Logger     *logrus.Entry
	Translator *i18n.Localizer
	Perm       map[uuid.UUID]*handler.Perm
}

func ParseRequest

func ParseRequest(c *gin.Context) (*Request, error)

func (*Request) ShouldBind

func (req *Request) ShouldBind(to any) error

func (*Request) ShouldBindQuery

func (req *Request) ShouldBindQuery(to any) error

func (*Request) ShouldBindUri

func (req *Request) ShouldBindUri(to any) error

type Response

type Response struct {
	HTTPCode int     `json:"-"`
	Code     RspCode `json:"code"`
	Msg      string  `json:"msg"`
	Data     any     `json:"data,omitempty"`
}

func APIAddGroup

func APIAddGroup(req *Request) (*Response, error)

func APIAddUser

func APIAddUser(req *Request) (*Response, error)

func APIDeleteGroup

func APIDeleteGroup(req *Request) (*Response, error)

func APIDeleteNotification

func APIDeleteNotification(req *Request) (*Response, error)

func APIDeleteUser

func APIDeleteUser(req *Request) (*Response, error)

func APIGetAccess

func APIGetAccess(req *Request) (*Response, error)

func APIGetCSRFToken

func APIGetCSRFToken(req *Request) (*Response, error)

func APIGetGroup

func APIGetGroup(req *Request) (*Response, error)

func APIGetMenu

func APIGetMenu(req *Request) (*Response, error)

func APIGetNotification

func APIGetNotification(req *Request) (*Response, error)

func APIGetPlugin

func APIGetPlugin(req *Request) (*Response, error)

func APIGetPluginEntry

func APIGetPluginEntry(req *Request) (*Response, error)

func APIGetPublicSetting

func APIGetPublicSetting(req *Request) (*Response, error)

func APIGetUser

func APIGetUser(req *Request) (*Response, error)

func APIPing

func APIPing(req *Request) (*Response, error)

func APIPutGroup

func APIPutGroup(req *Request) (*Response, error)

func APIPutPlugin

func APIPutPlugin(req *Request) (*Response, error)

func APIReload

func APIReload(req *Request) (*Response, error)

func APISignIn

func APISignIn(req *Request) (*Response, error)

func APISignOut

func APISignOut(req *Request) (*Response, error)

func NewPageResponse

func NewPageResponse(data any, total int64) *Response

type RspCode

type RspCode int32
const (
	CodeOK RspCode = iota
	CodeInvalidUserOrPass
	CodeUsernameExist
	CodeInvalidRecaptcha
	CodeRestarting
	CodeGroupNotExist
	CodeGroupNameExist
	CodeRootNotAllowedUpdate
	CodeRootNotAllowedDelete
	CodePluginNotExist
	CodePluginFormatError
	CodePluginExist

	CodeMax
)

func (RspCode) String

func (c RspCode) String(t *i18n.Localizer) string

Jump to

Keyboard shortcuts

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