Documentation
¶
Index ¶
- Constants
- func ErrorMessage(msg string, code int, params ...map[string]string) contracts.ResponseContract
- func GetOpenApiModel(name string) (any, bool)
- func RegisterOpenApiModel(name string, model any)
- func RegisterOpenApiQueryHandle[U Model](name string, handle OpenApiQueryHandle[U])
- func WithDeleteHandler[U Model]()
- func WithDetailHandler[U Model]()
- func WithListHandler[U Model]()
- func WithLoadRelations(fields []QueryField) func(*gorm.DB) *gorm.DB
- func WithModels()
- func WithSaveHandler[U Model]()
- type APIService
- type ApiModelAfterSave
- type ApiModelBeforeSave
- type ApiModelDeleteHook
- type ApiModelQuerySelect
- type ApiModelSaveControl
- type ApiModelWithQueryScope
- type Config
- type ErrorResp
- type JoinDefine
- type Model
- type OpenApi
- type OpenApiHandleRequest
- type OpenApiHandler
- type OpenApiQueryHandle
- type QueryDefine
- type QueryField
Constants ¶
View Source
const ( QueryTypeList = "list" QueryTypeSave = "save" QueryTypeDelete = "delete" QueryTypeDetail = "detail" )
Variables ¶
This section is empty.
Functions ¶
func ErrorMessage ¶
func GetOpenApiModel ¶
func RegisterOpenApiModel ¶
func RegisterOpenApiQueryHandle ¶
func RegisterOpenApiQueryHandle[U Model](name string, handle OpenApiQueryHandle[U])
func WithDeleteHandler ¶
func WithDeleteHandler[U Model]()
func WithDetailHandler ¶
func WithDetailHandler[U Model]()
func WithListHandler ¶
func WithListHandler[U Model]()
func WithLoadRelations ¶ added in v0.0.12
func WithLoadRelations(fields []QueryField) func(*gorm.DB) *gorm.DB
func WithModels ¶
func WithModels()
func WithSaveHandler ¶
func WithSaveHandler[U Model]()
Types ¶
type APIService ¶
type APIService[U Model] struct { // contains filtered or unexported fields }
func NewApiService ¶
func NewApiService[U Model]() *APIService[U]
func (*APIService[U]) Register ¶
func (as *APIService[U]) Register(app *framework.App) error
Register service when app starting, before http server start you can configure service, prepare global vars etc. running at main goroutine
func (*APIService[U]) RegisterRoutes ¶
func (as *APIService[U]) RegisterRoutes(rw *router.Wrapper)
type ApiModelAfterSave ¶
type ApiModelAfterSave[U Model] interface { AfterModelSave(tx *gorm.DB, req OpenApiHandleRequest[U]) error }
type ApiModelBeforeSave ¶
type ApiModelBeforeSave[U Model] interface { BeforeModelSave(tx *gorm.DB, req OpenApiHandleRequest[U]) error }
type ApiModelDeleteHook ¶
type ApiModelDeleteHook[U Model] interface { AfterModelDelete(tx *gorm.DB, req OpenApiHandleRequest[U]) error BeforeModelDelete(tx *gorm.DB, req OpenApiHandleRequest[U]) error }
type ApiModelQuerySelect ¶ added in v0.0.16
type ApiModelQuerySelect[U Model] interface { WithQuerySelect(req OpenApiHandleRequest[U]) []string }
type ApiModelSaveControl ¶
type ApiModelSaveControl[U Model] interface { ModelSaveControl(selects []string, req OpenApiHandleRequest[U]) []string }
type ApiModelWithQueryScope ¶
type ErrorResp ¶
type ErrorResp struct { Message string `json:"message"` Code int `json:"code"` Errors validation.ValidateError `json:"errors"` }
type JoinDefine ¶ added in v0.0.5
type JoinDefine struct { Table string `json:"table"` // 表名 Fields []QueryField `json:"fields"` Type string `json:"type"` }
type OpenApi ¶
type OpenApi struct { content.Request `gorm:"-" json:"-"` ID int64 `gorm:"column:id;primaryKey;not null;type:int;autoIncrement" json:"id"` GUID string `gorm:"column:guid;type:varchar(64);index:idx_guid;uniqueIndex:idx_unique_guid" json:"guid"` Query QueryDefine `gorm:"column:query;type:text" json:"query" input:"query"` Joins []JoinDefine `gorm:"column:joins;type:text" json:"joins" input:"joins"` Enabled bool `gorm:"column:enabled;type:tinyint;default:1;comment:是否启用" json:"enabled" input:"enabled"` Remarks string `gorm:"column:remarks;type:varchar(255)" json:"remarks" input:"remarks"` Preset bool `gorm:"column:preset;type:tinyint;default:0;comment:系统预设" json:"preset"` WithModel bool `gorm:"column:with_model;type:tinyint;default:1;comment:是否使用模型" json:"with_model"` WithAuth bool `gorm:"column:with_auth;type:tinyint;default:1;comment:是否需要登录" json:"with_auth"` dbutil.WithTimestamps }
type OpenApiHandleRequest ¶
type OpenApiHandleRequest[U Model] struct { content.Request User U `json:"-" ` GUID string `json:"guid" input:"guid" validate:"required"` Type string `json:"type" input:"type" validate:"required"` Fields []string `json:"fields" input:"fields"` Filters map[string]interface{} `json:"filters" input:"filters"` Data content.MapInput `json:"data" input:"data"` PerPage int `json:"per_page" input:"per_page"` Page int `json:"page" input:"page"` Sort map[string]string `json:"sort" input:"sort"` }
type OpenApiHandler ¶
type OpenApiHandler[U Model] struct { }
func (OpenApiHandler[U]) Handle ¶
func (OpenApiHandler[U]) Handle(req OpenApiHandleRequest[U], user U, db *gorm.DB) contracts.ResponseContract
type OpenApiQueryHandle ¶
type OpenApiQueryHandle[U Model] func(req OpenApiHandleRequest[U], api OpenApi, db *gorm.DB, model any) (any, error)
func GetOpenApiQueryHandle ¶
func GetOpenApiQueryHandle[U Model](name string) (OpenApiQueryHandle[U], bool)
type QueryDefine ¶
type QueryDefine struct { Table string `json:"table"` // 表名 Fields []QueryField `json:"fields"` Connection string `json:"connection"` // 连接名 PK string `json:"pk"` // 主键 CountSelect string `json:"countSelect"` WithCreate bool `json:"with_create"` WithEdit bool `json:"with_edit"` WithDelete bool `json:"with_delete"` WithoutPage bool `json:"without_page"` }
func (*QueryDefine) Scan ¶
func (qd *QueryDefine) Scan(src any) error
Scan assigns a value from a database driver. The src value will be of one of the following types:
int64 float64 bool []byte string time.Time nil - for NULL values
An error should be returned if the value cannot be stored without loss of information.
Reference types such as []byte are only valid until the next call to Scan and should not be retained. Their underlying memory is owned by the driver. If retention is necessary, copy their values before the next call to Scan.
type QueryField ¶
type QueryField struct { Name string `json:"name"` Label string `json:"label"` Width string `json:"width"` DataType string `json:"dataType"` Form string `json:"form"` FormHelp string `json:"formHelp"` Filter string `json:"filter"` Exclude bool `json:"exclude"` Required bool `json:"required"` Omit bool `json:"omit"` Sorter bool `json:"sorter"` Hidden bool `json:"hidden"` Joined bool `json:"joined"` }
Click to show internal directories.
Click to hide internal directories.