Documentation ¶
Index ¶
- Constants
- Variables
- func AddHandlerIgnoreErrors(errs ...interface{})
- func AfterHandler(ictx context.Context, o interface{}, err error)
- func ArrJoin(arrL interface{}, arrR interface{}, keyL, keyR interface{}, ...) interface{}
- func ArrayFilterNotEmpty(arr interface{}) []interface{}
- func ArrayGetColumnSet(arr interface{}, key string) *hashset.Set
- func ArrayToHashmap(arr interface{}, mapKeyField interface{}) *hashmap.Map
- func BinPath() string
- func CancelAfterHandler(ictx context.Context)
- func ContainsUint32(s []uint32, v uint32) bool
- func DefaultString(v, def string) string
- func DefaultUint32(v, def uint32) uint32
- func EqualValUint32(a *uint32, b uint32) bool
- func FileGetBase64(filenameOrURL string, timeout ...time.Duration) (out string, err error)
- func FileRenameExt(s, ext string) string
- func FirstError(es ...error) error
- func FixSetCookie(ctx context.Context)
- func FormHasValue(ctx context.Context, name string) bool
- func FormatSqlError(err error) error
- func FromPrtZeroUint32(ptr *uint32) uint32
- func GetFileBaseName(s string) string
- func GetIDs(ms interface{}) []uint32
- func GetItemString(arr []string, index int) (out string, ok bool)
- func GetScope(g *gorm.DB) *gorm.Scope
- func GetSelectAttrs(g *gorm.DB) []string
- func GormAddSelect(g *gorm.DB, fields ...string) *gorm.DB
- func GormIn(g *gorm.DB, field string, arg interface{}) *gorm.DB
- func GormNotIn(g *gorm.DB, field string, arg interface{}) *gorm.DB
- func JsonMarshalToString(obj interface{}) string
- func MapGetColumn(arr interface{}, key string) []interface{}
- func MapGetColumnString(arr interface{}, key string) []string
- func MapGetColumnUint32(arr interface{}, key string) []uint32
- func Md5Sum(s string) string
- func MinInt(a, b int) int
- func NewErrExisted() *errors.Error
- func NewErrNotFound() *errors.Error
- func NewErrParams() *errors.Error
- func NewErrPermission() *errors.Error
- func Nothing(...interface{})
- func NowPtr() *time.Time
- func ObjectGet(v, f interface{}) interface{}
- func ParseForm(v url.Values, outPtr interface{}) (err error)
- func ParseFormIris(ictx context.Context, params interface{}) (err error)
- func PrintError(err error)
- func PtrOf(ob interface{}) (out interface{})
- func RandStringRunes(n int) string
- func RowsLength(rows *sql.Rows) (l int)
- func ScopeOmitFields(scope *gorm.Scope, fields ...string)
- func SqlEscape(source string) string
- func StrFromUint32(u uint32) string
- func StrIsEmpty(s string) bool
- func StrToInt32(s string) (r int32)
- func StrToUint32(s string) (r uint32)
- func SubString(s string, start, length int) (sub string)
- func ToInterfaceArray(m interface{}) []interface{}
- func ToInterfaceArrayString(t []string) []interface{}
- func ToPrtZeroUint32(ptr uint32) *uint32
- func TrimSpaceArr(s []string) (out []string)
- type ErrJson
- type ErrorList
- type IGetDB
- type IModel
- type IModelParent
- type IModelTime
- type MConfig
- type Model
- func (m *Model) AfterDelete(scope *gorm.Scope) error
- func (m *Model) AutoEnd(commit bool) (err error)
- func (m *Model) BatchDelete(ids []uint32) (err error)
- func (m *Model) BatchInsertBad(items []*Model) (err error)
- func (m *Model) BeforeDelete(scope *gorm.Scope) error
- func (m *Model) BeforeUpdate(scope *gorm.Scope) (err error)
- func (m *Model) Begin() *gorm.DB
- func (m *Model) Commit() (err error)
- func (m *Model) Delete() error
- func (m *Model) Exist(where ...interface{}) bool
- func (m *Model) ExistID() bool
- func (m *Model) FSave() (err error)
- func (m *Model) FetchColumnValue(keys ...string) (out interface{})
- func (m *Model) Find(out interface{}, where ...interface{}) (db *gorm.DB)
- func (m *Model) FindList(where ...interface{}) (interface{}, error)
- func (m *Model) First(out interface{}, where ...interface{}) (err error)
- func (m *Model) FirstOrCreate(where ...interface{}) (err error)
- func (m *Model) FormatColumns(keys ...string) []string
- func (m *Model) FormatError(err error) error
- func (m *Model) FormatFields(str string) string
- func (m *Model) FormatSql(sql string, args ...interface{}) string
- func (m *Model) GModel() *gorm.DB
- func (m *Model) GetDB() *gorm.DB
- func (m *Model) GetModel() *Model
- func (m *Model) GetPK() interface{}
- func (m *Model) GetParent() interface{}
- func (m *Model) GetTableName() string
- func (m *Model) IsLoaded() bool
- func (m *Model) IsValid() (err error)
- func (m *Model) JoinBy(g *gorm.DB, selectKeysMap interface{}, lkey, rkey, jtype string) *gorm.DB
- func (m *Model) JoinIBy(g *gorm.DB, selectKeysMap interface{}, lkey, rkey string) *gorm.DB
- func (m *Model) JoinLBy(g *gorm.DB, selectKeysMap interface{}, lkey, rkey string) *gorm.DB
- func (m *Model) Limit(limit interface{}) *gorm.DB
- func (m *Model) LoadAndSetId(id uint32) error
- func (m *Model) LoadById() error
- func (m *Model) LoadByKey(key string, val interface{}) error
- func (m *Model) MakePSlice() interface{}
- func (m *Model) New() interface{}
- func (m *Model) NewScope() (*gorm.Scope, error)
- func (m *Model) Related(value interface{}, foreignKeys ...string) error
- func (m *Model) Rollback() (err error)
- func (m *Model) Save() (err error)
- func (m *Model) Select(query interface{}, args ...interface{}) *gorm.DB
- func (m *Model) SetDB(g *gorm.DB)
- func (m *Model) SetDBOpt(name string, value interface{}) *gorm.DB
- func (m *Model) SetParent(p interface{})
- func (m *Model) SetSaveAssociations(v bool)
- func (m *Model) Table() *gorm.DB
- func (m *Model) ToMap() map[string]interface{}
- func (m *Model) Update(attrs ...interface{}) error
- func (m *Model) Updates(values interface{}, ignoreProtectedAttrs ...bool) error
- func (m *Model) Upsert(attrs ...interface{}) (err error)
- func (m *Model) Where(query interface{}, args ...interface{}) *gorm.DB
- type ModelTime
- type RedisConf
- type WError
- type WxConfig
Constants ¶
View Source
const (
HANDLER_CANCEL = "wing-handler-cancel"
)
View Source
const (
XSESSION_KEY = "xsession"
)
Variables ¶
View Source
var ( ERR_REQUIRE_LOGIN = errors.New("require login") ERR_REQUIRE_ADMIN = errors.New("require admin") ERR_NO_ACCOUNT = errors.New("no such account") ERR_NO_PERMISSION = errors.New("no permission") ERR_CANNOT_MODIFY = errors.New("cannot modify") ErrNoItem = errors.New("no such item") ErrExisted = errors.New("existed") ErrNotMatch = errors.New("not match") ErrFormat = errors.New("format error") UtilsErrList = []*errors.Error{ERR_REQUIRE_LOGIN, ERR_REQUIRE_ADMIN, ERR_NO_ACCOUNT, ERR_NO_PERMISSION, ERR_CANNOT_MODIFY, ErrNoItem, ErrExisted, ErrNotMatch} )
View Source
var (
DEBUG = true
)
Functions ¶
func AddHandlerIgnoreErrors ¶
func AddHandlerIgnoreErrors(errs ...interface{})
func AfterHandler ¶
func ArrJoin ¶
func ArrJoin(arrL interface{}, arrR interface{}, keyL, keyR interface{}, joinFunc interface{}) interface{}
func ArrayFilterNotEmpty ¶
func ArrayFilterNotEmpty(arr interface{}) []interface{}
func ArrayGetColumnSet ¶
func ArrayToHashmap ¶
数组转hashmap `mapKeyField`可以是`string`或者是`func`
func CancelAfterHandler ¶
func ContainsUint32 ¶
func DefaultString ¶
func DefaultUint32 ¶
func EqualValUint32 ¶
func FileGetBase64 ¶
func FormatSqlError ¶
func FromPrtZeroUint32 ¶
func GetFileBaseName ¶
func GetSelectAttrs ¶
func JsonMarshalToString ¶
func JsonMarshalToString(obj interface{}) string
func MapGetColumn ¶
func MapGetColumn(arr interface{}, key string) []interface{}
func MapGetColumnString ¶
func MapGetColumnUint32 ¶
转换*uint32和uint32
func NewErrExisted ¶
func NewErrNotFound ¶
func NewErrParams ¶
func NewErrPermission ¶
func ParseFormIris ¶
params必须是ptr
func PrintError ¶
func PrintError(err error)
func RandStringRunes ¶
func ScopeOmitFields ¶
func StrFromUint32 ¶
func StrIsEmpty ¶
func StrToInt32 ¶
func StrToUint32 ¶
func ToInterfaceArray ¶
func ToInterfaceArray(m interface{}) []interface{}
func ToInterfaceArrayString ¶
func ToInterfaceArrayString(t []string) []interface{}
func ToPrtZeroUint32 ¶
func TrimSpaceArr ¶
Types ¶
type IModel ¶
type IModel interface { New() interface{} GModel() *gorm.DB GetPK() interface{} GetTableName() string GetModel() *Model GetDB() *gorm.DB SetDB(g *gorm.DB) Begin() *gorm.DB Rollback() (err error) Commit() (err error) NewScope() (*gorm.Scope, error) Limit(limit interface{}) *gorm.DB IsLoaded() bool LoadAndSetId(id uint32) error Exist(where ...interface{}) bool ExistID() bool FetchColumnValue(keys ...string) (out interface{}) Find(out interface{}, where ...interface{}) *gorm.DB MakePSlice() interface{} BatchInsertBad(items []*Model) (err error) Save() error FirstOrCreate(where ...interface{}) (err error) Update(attrs ...interface{}) error Upsert(attrs ...interface{}) error GetParent() interface{} SetParent(p interface{}) IsValid() error FormatError(err error) error Delete() error Where(query interface{}, args ...interface{}) *gorm.DB FormatSql(sql string, args ...interface{}) string SetDBOpt(name string, value interface{}) *gorm.DB //连贯操作 Select(query interface{}, args ...interface{}) *gorm.DB // 永久生效 SetSaveAssociations(v bool) //Association(column string) Table() *gorm.DB }
type IModelParent ¶
type IModelTime ¶
type IModelTime interface {
UnsetTime()
}
type MConfig ¶
type MConfig struct { AppPath string //运行路径,一般不设置,测试使用 Debug bool Addr string //服务地址 Host string Mysql string MysqlDebug bool Mongodb string DefaultPassword string `yaml:"default_password"` //默认密码 MediaPath string WebApps string MaxMediaSize string `yaml:"max_media_size"` CookieExpires int64 `yaml:"cookie_expires"` SiteCreator struct { Mysql string WpDir string } WxConfig WxConfig `yaml:"wechat"` Redis RedisConf Task tconfig.Config Cms struct { } YunCourseTemplate string LibreOfficePath string `yaml:"libreoffice_path"` TestAdminSession string TestStudentSession string TestTeacherSession string Wing struct { FaceKey string FaceSec string } Exam struct { Mysql string } // contains filtered or unexported fields }
main config
var (
DefaultConfig MConfig
)
func LoadConfig ¶
func NewConfigFromFile ¶
func (MConfig) GetConfigPath ¶
type Model ¶
type Model struct { ID uint32 `gorm:"primary_key" bson:"ID" orm:"pk;auto;"` DB *gorm.DB `gorm:"-" json:"-" bson:"-" form:"-"` OmitFields []string `gorm:"-" json:"-" bson:"-" form:"-"` // contains filtered or unexported fields }
func (*Model) BatchInsertBad ¶
deprecated 最蛋疼的多插入
func (*Model) FetchColumnValue ¶
只返回第一个
func (*Model) FirstOrCreate ¶
func (*Model) FormatColumns ¶
func (*Model) FormatError ¶
格式化错误 IMPORTANT: 记得最后调用 err = p.Model.FormatError(err)
func (*Model) FormatFields ¶
func (*Model) GetTableName ¶
func (*Model) IsValid ¶
用法
func (p *Term) IsValid() error { errs := make([]error, 1) if cutils.IsValidSlug(p.Slug) { errs = append(errs, errors.New("Slug not valid")) } return utils.FirstError(errs...) }
func (*Model) JoinBy ¶
被JOIN selectKeysMap = nil | map[string]string k:to SELECT <map> FROM ... JOIN <m.TableName> ON <m.TableName>.<rkey> == <g.Table>.<lkey>
func (*Model) LoadAndSetId ¶
func (*Model) MakePSlice ¶
func (m *Model) MakePSlice() interface{}
创建对应父Slice切片的地址,指针 *[]*ParentType
type ModelTime ¶
type WError ¶
type WError struct { Err *errors.Error Frames []errors.StackFrame }
func (*WError) ErrorStack ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.