LingEcho

package module
v0.0.0-...-0409f2c Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

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 AbortWithJSONError

func AbortWithJSONError(c *gin.Context, code int, err error)

func GetDbConnection

func GetDbConnection(c *gin.Context, objFn GetDB, isCreate bool) (tx *gorm.DB)

func GetRenderPageContext

func GetRenderPageContext(c *gin.Context) map[string]any

func HintAssetsRoot

func HintAssetsRoot(dirName string) string

func NewTemplateFuncs

func NewTemplateFuncs() template.FuncMap

func RegisterHandler

func RegisterHandler(prefix string, r *gin.Engine, uriDocs []UriDoc, objDocs []WebObjectDoc, db *gorm.DB)

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 SanitizeSensitiveValues

func SanitizeSensitiveValues(prefix string, data any) map[string]any

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 BeforeCreateFunc

type BeforeCreateFunc func(db *gorm.DB, ctx *gin.Context, vptr any) error

type BeforeDeleteFunc

type BeforeDeleteFunc func(db *gorm.DB, ctx *gin.Context, vptr any) error

type BeforeQueryRenderFunc

type BeforeQueryRenderFunc func(db *gorm.DB, ctx *gin.Context, r *QueryResult) (any, error)

type BeforeRenderFunc

type BeforeRenderFunc func(db *gorm.DB, ctx *gin.Context, vptr any) (any, error)

type BeforeUpdateFunc

type BeforeUpdateFunc func(db *gorm.DB, ctx *gin.Context, vptr any, vals map[string]any) error

type CombineEmbedFS

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

func NewCombineEmbedFS

func NewCombineEmbedFS(assertDir string, es ...EmbedFS) *CombineEmbedFS

func (*CombineEmbedFS) Open

func (c *CombineEmbedFS) Open(name string) (fs.File, error)

func (*CombineEmbedFS) ReadDir

func (c *CombineEmbedFS) ReadDir(name string) ([]fs.DirEntry, error)

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

func (c *CombineTemplates) RenderError(name, source string, data any, err error) render.Render

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

func GetDocDefine(obj any) *DocField

type EmbedFS

type EmbedFS struct {
	EmbedRoot string
	Embedfs   embed.FS
}

type EmbedFile

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

func (EmbedFile) Close

func (ef EmbedFile) Close() error

Close implements http.File

func (EmbedFile) Read

func (ef EmbedFile) Read(p []byte) (n int, err error)

Read implements http.File

func (EmbedFile) Readdir

func (ef EmbedFile) Readdir(count int) ([]fs.FileInfo, error)

Readdir implements http.File

func (EmbedFile) Seek

func (ef EmbedFile) Seek(offset int64, whence int) (int64, error)

Seek implements http.File

func (EmbedFile) Stat

func (ef EmbedFile) Stat() (fs.FileInfo, error)

Stat implements http.File

type ErrorWithCode

type ErrorWithCode interface {
	StatusCode() int
}

type Filter

type Filter struct {
	Name  string `json:"name"`
	Op    string `json:"op"`
	Value any    `json:"value"`
	// contains filtered or unexported fields
}

func (*Filter) GetQuery

func (f *Filter) GetQuery() string

GetQuery return the combined filter SQL statement. such as "age >= ?", "name IN ?".

type GetDB

type GetDB func(c *gin.Context, isCreate bool) *gorm.DB // designed for group

type OptionFunc

type OptionFunc func(*UriDoc)

type Order

type Order struct {
	Name string `json:"name"`
	Op   string `json:"op"`
}

func (*Order) GetQuery

func (f *Order) GetQuery() string

GetQuery return the combined order SQL statement. such as "id DESC".

type PrepareQuery

type PrepareQuery func(db *gorm.DB, c *gin.Context) (*gorm.DB, *QueryForm, error)

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
}

func DefaultPrepareQuery

func DefaultPrepareQuery(db *gorm.DB, c *gin.Context) (*gorm.DB, *QueryForm, error)

DefaultPrepareQuery return default QueryForm.

type QueryResult

type QueryResult struct {
	TotalCount int    `json:"total,omitempty"`
	Pos        int    `json:"pos,omitempty"`
	Limit      int    `json:"limit,omitempty"`
	Keyword    string `json:"keyword,omitempty"`
	Items      []any  `json:"items"`
}

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) Build

func (obj *WebObject) Build() error

Build fill the properties of obj.

func (*WebObject) BuildPrimaryPath

func (obj *WebObject) BuildPrimaryPath(prefix string) string

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

type WebObjectPrimaryField

type WebObjectPrimaryField struct {
	IsPrimary bool
	Name      string
	Kind      reflect.Kind
	JSONName  string
}

Jump to

Keyboard shortcuts

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