Documentation
¶
Index ¶
- Constants
- Variables
- func AbortWithJSONError(c *gin.Context, code int, err error)
- func GetDbConnection(c *gin.Context, objFn GetDB, isCreate bool) (tx *gorm.DB)
- func GetRenderPageContext(c *gin.Context) map[string]any
- func HintAssetsRoot(dirName string) string
- func NewTemplateFuncs() template.FuncMap
- func RegisterHandler(prefix string, r *gin.Engine, uriDocs []UriDoc, objDocs []WebObjectDoc, ...)
- func RegisterHandlerWithAutoGen(prefix string, r *gin.Engine, uriDocs []UriDoc, objDocs []WebObjectDoc, ...)
- func RegisterObject(r *gin.RouterGroup, obj *WebObject) error
- func RegisterObjects(r *gin.RouterGroup, objs []WebObject)
- func SanitizeSensitiveValues(prefix string, data any) map[string]any
- func WithStaticAssets(r *gin.Engine, staticPrefix, staticRootDir string) gin.HandlerFunc
- func WithTemplates(r *gin.Engine, templateRootDir string) gin.HandlerFunc
- type BeforeCreateFunc
- type BeforeDeleteFunc
- type BeforeQueryRenderFunc
- type BeforeRenderFunc
- type BeforeUpdateFunc
- type CombineEmbedFS
- type CombineTemplates
- type DebugTempalte
- type DocField
- type EmbedFS
- type EmbedFile
- type ErrorWithCode
- type Filter
- type GetDB
- type OptionFunc
- type Order
- type PrepareQuery
- type QueryForm
- type QueryResult
- type QueryView
- type UriDoc
- type WebObject
- type WebObjectDoc
- type WebObjectPrimaryField
Constants ¶
View Source
const ( TYPE_DATE = "date" TYPE_STRING = "string" TYPE_INT = "int" TYPE_FLOAT = "float" TYPE_BOOLEAN = "boolean" TYPE_OBJECT = "object" TYPE_MAP = "map" )
View Source
const ( FilterOpIsNot = "is not" FilterOpEqual = "=" FilterOpNotEqual = "<>" FilterOpIn = "in" FilterOpNotIn = "not_in" FilterOpGreater = ">" FilterOpGreaterOrEqual = ">=" FilterOpLess = "<" FilterOpLessOrEqual = "<=" FilterOpLike = "like" FilterOpBetween = "between" )
View Source
const ( OrderOpDesc = "desc" OrderOpAsc = "asc" )
View Source
const ( GET = 1 << 1 CREATE = 1 << 2 EDIT = 1 << 3 DELETE = 1 << 4 QUERY = 1 << 5 )
View Source
const (
DefaultQueryLimit = 102400 // 100k
)
Variables ¶
View Source
var EmbedStaticAssets embed.FS
View Source
var EmbedTemplates embed.FS
View Source
var GroupInvitationHTML string
View Source
var VerificationHTML string
View Source
var WelcomeHTML string
Functions ¶
func GetDbConnection ¶
func HintAssetsRoot ¶
func NewTemplateFuncs ¶
func RegisterHandler ¶
func RegisterHandlerWithAutoGen ¶
func RegisterHandlerWithAutoGen(prefix string, r *gin.Engine, uriDocs []UriDoc, objDocs []WebObjectDoc, db *gorm.DB, autoGen bool)
RegisterHandlerWithAutoGen 注册文档处理器,支持自动生成
func RegisterObject ¶
func RegisterObject(r *gin.RouterGroup, obj *WebObject) error
func RegisterObjects ¶
func RegisterObjects(r *gin.RouterGroup, objs []WebObject)
func WithStaticAssets ¶
func WithStaticAssets(r *gin.Engine, staticPrefix, staticRootDir string) gin.HandlerFunc
func WithTemplates ¶
func WithTemplates(r *gin.Engine, templateRootDir string) gin.HandlerFunc
Types ¶
type BeforeQueryRenderFunc ¶
type BeforeRenderFunc ¶
type BeforeUpdateFunc ¶
type CombineEmbedFS ¶
type CombineEmbedFS struct {
// contains filtered or unexported fields
}
func NewCombineEmbedFS ¶
func NewCombineEmbedFS(assertDir string, es ...EmbedFS) *CombineEmbedFS
type CombineTemplates ¶
type CombineTemplates struct {
CombineFS *CombineEmbedFS
Template *template.Template
Delims render.Delims
FuncMap template.FuncMap
}
func NewCombineTemplates ¶
func NewCombineTemplates(combineFS *CombineEmbedFS) *CombineTemplates
func (*CombineTemplates) Instance ¶
func (c *CombineTemplates) Instance(name string, ctx any) render.Render
gin.render.Render
func (*CombineTemplates) RenderError ¶
type DebugTempalte ¶
type DebugTempalte struct {
Template *template.Template
Name string
Data any
// contains filtered or unexported fields
}
HTML contains template reference and its name with given interface object.
func (DebugTempalte) Render ¶
func (r DebugTempalte) Render(w http.ResponseWriter) error
Render (HTML) executes template and writes its result with custom ContentType for response.
func (DebugTempalte) WriteContentType ¶
func (r DebugTempalte) WriteContentType(w http.ResponseWriter)
WriteContentType (HTML) writes HTML ContentType.
type DocField ¶
type DocField struct {
FieldName string `json:"-"`
Name string `json:"name"`
Desc string `json:"desc,omitempty"`
Type string `json:"type,omitempty"`
Default any `json:"default,omitempty"`
Required bool `json:"required,omitempty"`
CanNull bool `json:"canNull,omitempty"`
IsArray bool `json:"isArray,omitempty"`
IsPrimary bool `json:"isPrimary,omitempty"`
Fields []DocField `json:"fields,omitempty"`
}
func GetDocDefine ¶
type EmbedFile ¶
type EmbedFile struct {
// contains filtered or unexported fields
}
type ErrorWithCode ¶
type ErrorWithCode interface {
StatusCode() int
}
type Filter ¶
type OptionFunc ¶
type OptionFunc func(*UriDoc)
type PrepareQuery ¶
type QueryForm ¶
type QueryForm struct {
Pos int `json:"pos"`
Limit int `json:"limit"`
Keyword string `json:"keyword,omitempty"`
Filters []Filter `json:"filters,omitempty"`
Orders []Order `json:"orders,omitempty"`
ForeignMode bool `json:"foreign"` // for foreign key
ViewFields []string `json:"-"` // for view
// contains filtered or unexported fields
}
type QueryResult ¶
type QueryView ¶
type QueryView struct {
Path string `json:"path"`
Method string `json:"method"`
Desc string `json:"desc"`
Prepare PrepareQuery
}
type UriDoc ¶
type UriDoc struct {
MethodRef any `json:"-"` // just for quick jump to method
Group string `json:"group"`
Path string `json:"path"`
Summary string `json:"summary"`
Desc string `json:"desc,omitempty"`
AuthRequired bool `json:"authRequired,omitempty"`
Method string `json:"method"` // "GET" "POST" "DELETE" "PUT" "PATCH"
Request *DocField `json:"request"`
Response *DocField `json:"response"`
}
type WebObject ¶
type WebObject struct {
Model any
Group string
Name string
Desc string
AuthRequired bool
Editables []string
Filterables []string
Orderables []string
Searchables []string
GetDB GetDB
PrepareQuery PrepareQuery
BeforeCreate BeforeCreateFunc
BeforeUpdate BeforeUpdateFunc
BeforeDelete BeforeDeleteFunc
BeforeRender BeforeRenderFunc
BeforeQueryRender BeforeQueryRenderFunc
Views []QueryView
AllowMethods int
// contains filtered or unexported fields
}
func (*WebObject) BuildPrimaryPath ¶
func (*WebObject) RegisterObject ¶
func (obj *WebObject) RegisterObject(r *gin.RouterGroup) error
type WebObjectDoc ¶
type WebObjectDoc struct {
Group string `json:"group"`
Path string `json:"path"`
Desc string `json:"desc,omitempty"`
AuthRequired bool `json:"authRequired,omitempty"`
AllowMethods []string `json:"allowMethods,omitempty"`
Fields []DocField `json:"fields,omitempty"` // Request Body
Filters []string `json:"filters,omitempty"`
Orders []string `json:"orders,omitempty"`
Searches []string `json:"searches,omitempty"`
Editables []string `json:"editables,omitempty"`
Views []UriDoc `json:"views,omitempty"`
}
func GetWebObjectDocDefine ¶
func GetWebObjectDocDefine(prefix string, obj WebObject) WebObjectDoc
Click to show internal directories.
Click to hide internal directories.