catgo

package module
v0.0.0-...-9e9a511 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 22 Imported by: 5

README

catgo

Catgo is a web framework of go, based on Gin and Gorm

To do list

*[x] validate *[ ] cache *[ ] config *[ ] env

Documentation

Overview

利用 reflect 技术把结构体的可 export 值复制到 dst 中,dst 必须是相似结构体的指针。 copy the exported value of a struct to dst , with reflect.

Index

Constants

This section is empty.

Variables

View Source
var (
	DB       *gorm.DB
	DBs      map[string]*gorm.DB
	DBConfig map[string]string
)
View Source
var (
	IsEmail         = govalidator.IsEmail
	IsExistingEmail = govalidator.IsExistingEmail
	IsAlpha         = govalidator.IsAlpha
	IsAlphanumeric  = govalidator.IsAlphanumeric
	IsBase64        = govalidator.IsBase64
	IsFloat         = govalidator.IsFloat
	IsIP            = govalidator.IsIP
)
View Source
var Dump = godump.Dump
View Source
var (
	Router *gin.Engine
)

Functions

func Any

func Any(relativePath string, handlers ...interface{}) gin.IRouter

Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.

func CheckMobile

func CheckMobile(mobile string) bool

func ComparePassword

func ComparePassword(password, passwordInDb string) bool

func DELETE

func DELETE(relativePath string, handlers ...interface{}) gin.IRouter

DELETE is a shortcut for catgo.Handle("DELETE", path, handle).

func Db

func Db(params ...interface{}) *gorm.DB

func DefaultGroup

func DefaultGroup(handlers ...interface{})

change currentRouterGroup to Router

func GET

func GET(relativePath string, handlers ...interface{}) gin.IRouter

GET is a shortcut for catgo.Handle("GET", path, handle).

func GetCurrentPath

func GetCurrentPath() (string, error)

func Gorm

func Gorm(params ...interface{}) *gorm.DB

func Group

func Group(relativePath string, handlers ...interface{}) gin.IRouter

create new route group relativePath,examples: /users /users/:id handlers,examples:gin.HandlerFunc,catgo.HandlerFunc

func HEAD(relativePath string, handlers ...interface{}) gin.IRouter

HEAD is a shortcut for catgo.Handle("HEAD", path, handle).

func Handle

func Handle(httpMethod, relativePath string, handlers ...interface{}) gin.IRouter

Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in GitHub.

For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func JwtParseToken

func JwtParseToken(token string, secret ...string) (map[string]interface{}, error)

func JwtToken

func JwtToken(data map[string]interface{}, secret ...string) (string, error)

func OPTIONS

func OPTIONS(relativePath string, handlers ...interface{}) gin.IRouter

OPTIONS is a shortcut for catgo.Handle("OPTIONS", path, handle).

func PATCH

func PATCH(relativePath string, handlers ...interface{}) gin.IRouter

PATCH is a shortcut for catgo.Handle("PATCH", path, handle).

func POST

func POST(relativePath string, handlers ...interface{}) gin.IRouter

POST is a shortcut for catgo.Handle("POST", path, handle).

func PUT

func PUT(relativePath string, handlers ...interface{}) gin.IRouter

PUT is a shortcut for catgo.Handle("PUT", path, handle).

func ParseMainDbDsn

func ParseMainDbDsn() string

func Password

func Password(password string, authCode ...string) string

func Run

func Run(addr ...string)

func Struct2Map

func Struct2Map(src interface{}, dst map[string]interface{}) error

func StructCopy

func StructCopy(src, dst interface{}, ignoreFields ...string) error

StructCopy copy the exported value of a struct to a likely struct , with reflect.

func StructFill

func StructFill(src, dst interface{}) error

func Validate

func Validate(data interface{}, scene ...string) (bool, string)

func ValidateBatch

func ValidateBatch(data interface{}, scene ...string) (bool, map[string]map[string]string)

Types

type Config

type Config struct {
}

func NewConfig

func NewConfig() *Config

func (*Config) AllSettings

func (t *Config) AllSettings() map[string]interface{}

func (*Config) Get

func (t *Config) Get(key string) interface{}

func (*Config) GetString

func (t *Config) GetString(key string) string

func (*Config) IsSet

func (t *Config) IsSet(key string) bool

func (*Config) ReadConfig

func (t *Config) ReadConfig(name string) (bool, error)

func (*Config) ReadDataBaseConfig

func (t *Config) ReadDataBaseConfig() map[string]string

func (*Config) Set

func (t *Config) Set(key string, value interface{})

func (*Config) SetDefault

func (t *Config) SetDefault(key string, value interface{})

type Context

type Context struct {
	*gin.Context
}

func (*Context) DefaultParamInt

func (c *Context) DefaultParamInt(key string, defaultResult int) (result int)

param int with default value defaultResult

func (*Context) DefaultParamInt64

func (c *Context) DefaultParamInt64(key string, defaultResult int64) (result int64)

param int64 with default value defaultResult

func (*Context) DefaultParamUint

func (c *Context) DefaultParamUint(key string, defaultResult uint) (result uint)

param uint with default value defaultResult

func (*Context) DefaultParamUint64

func (c *Context) DefaultParamUint64(key string, defaultResult uint64) (result uint64)

param uint64 with default value defaultResult

func (*Context) DefaultQueryInt

func (c *Context) DefaultQueryInt(key string, defaultResult int) (result int)

query int with default value defaultResult

func (*Context) DefaultQueryInt64

func (c *Context) DefaultQueryInt64(key string, defaultResult int64) (result int64)

query int64 with default value defaultResult

func (*Context) DefaultQueryUint

func (c *Context) DefaultQueryUint(key string, defaultResult uint) (result uint)

query uint with default value defaultResult

func (*Context) DefaultQueryUint64

func (c *Context) DefaultQueryUint64(key string, defaultResult uint64) (result uint64)

query uint64 with default value defaultResult

func (*Context) Error

func (c *Context) Error(msg string, params ...interface{})

msg params[0] data params[1] map[string]string header

func (*Context) ParamInt

func (c *Context) ParamInt(key string) (result int)

param int

func (*Context) ParamInt64

func (c *Context) ParamInt64(key string) (result int64)

param int64

func (*Context) ParamUint

func (c *Context) ParamUint(key string) (result uint)

param uint

func (*Context) ParamUint64

func (c *Context) ParamUint64(key string) (result uint64)

param uint64

func (*Context) QueryInt

func (c *Context) QueryInt(key string) (result int)

query int

func (*Context) QueryInt64

func (c *Context) QueryInt64(key string) (result int64)

query int64

func (*Context) QueryPage

func (c *Context) QueryPage(defaultPageSize ...int) (page, pageSize int)

parse query page defaultPageSize 10

func (*Context) QueryUint

func (c *Context) QueryUint(key string) (result uint)

query int

func (*Context) QueryUint64

func (c *Context) QueryUint64(key string) (result uint64)

query uint64

func (*Context) Result

func (c *Context) Result(msg string, code int, params ...interface{})

msg code 0|1 params[0] data params[1] map[string]string header

func (*Context) SetUserId

func (c *Context) SetUserId(userId string)

set user id

func (*Context) ShouldBindFailError

func (c *Context) ShouldBindFailError(obj interface{}, msg ...string)

ShouldBind data then fail error

func (*Context) ShouldBindValidateFailError

func (c *Context) ShouldBindValidateFailError(obj interface{}, msg1scene2 ...string)

ShouldBind & Validate data then fail error

func (*Context) Success

func (c *Context) Success(msg string, params ...interface{})

msg params[0] data params[1] map[string]string header

func (*Context) UserId

func (c *Context) UserId() string

get user id

func (*Context) ValidateFailError

func (c *Context) ValidateFailError(data interface{}, scene ...string)

Validate data then fail error

type HandlerFunc

type HandlerFunc func(*Context)

type Model

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

func (*Model) Find

func (c *Model) Find(params ...interface{}) *Model

func (*Model) Init

func (c *Model) Init(child interface{}) *Model

func (*Model) InitDb

func (c *Model) InitDb(params ...interface{}) *Model

Jump to

Keyboard shortcuts

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