Documentation
¶
Index ¶
- Constants
- Variables
- func AddApi(c any, groups ...string)
- func AddCli(c any, groups ...string)
- func AddGrpcServerOption(o ...grpc.ServerOption)
- func AddRouteApiFunc(controller_name, action_name string, f RouteApiFunc)
- func AddRouteRpcFunc(controller_name, action_name string, f RouteRpcFunc)
- func AddRpc(c any, groups ...string)
- func ArrayColumn[T comparable](m []map[string]T, column string, uniqs ...bool) []T
- func ArrayColumnMap[T comparable](m []map[string]T, column string, index string) map[T]T
- func ArrayMerge[T comparable](arr []T, n ...[]T) []T
- func ArrayRem[T comparable](arr []T, n T) []T
- func ArrayUnique[T comparable](arr []T) []T
- func AsBool(b interface{}, def ...bool) bool
- func AsBytes(arg interface{}, def ...[]byte) []byte
- func AsFloat(num interface{}, def ...float64) float64
- func AsFloat32(num interface{}, def ...float32) float32
- func AsFloat64(num interface{}, def ...float64) float64
- func AsInt(num interface{}, def ...int) int
- func AsInt32(num interface{}, def ...int32) int32
- func AsInt32Slice(v interface{}) []int32
- func AsInt64(num interface{}, def ...int64) int64
- func AsInt64Slice(v interface{}) []int64
- func AsIntSlice(v interface{}) []int
- func AsSlice[T any](arr []T) []any
- func AsString(v any, def ...string) string
- func AsStringSlice(v any) (strs []string)
- func AsUint(num interface{}, def ...uint) uint
- func AsUint32(num interface{}, def ...uint32) uint32
- func AsUint64(num interface{}, def ...uint64) uint64
- func Concat(str ...string) string
- func Cost(start_time time.Time) int
- func Crc32(str string) int
- func Date(times ...any) string
- func DateHour(times ...any) string
- func DateMin(times ...any) string
- func DateTime(times ...any) string
- func Expr(param string) string
- func FileGetContents(path string, options ...interface{}) (string, error)
- func FormatTime(layout string, times ...any) string
- func GetCookie(r *http.Request, key string) string
- func GetIp(r *http.Request) string
- func GetLocalIp() string
- func GetMapNode(m map[string]interface{}, keys ...string) (interface{}, bool)
- func GetNode(i any, keys ...string) any
- func GetSlice(i any, keys ...string) []any
- func GreenString(s string) string
- func Hash(s string) uint64
- func HashMap(m map[string]any) uint64
- func HashSlice(s []any) uint64
- func InArray[T comparable](search T, s []T) bool
- func InMap[T, K comparable](search T, m map[K]T) bool
- func Interceptor(guard bool, errmsg interface{}, fmts ...interface{})
- func Intn(n int) int
- func Ip2long(ipstr string) (ip int)
- func IsDir(path string) (bool, error)
- func IsFile(path string) (bool, error)
- func IsTerm() bool
- func Join(v interface{}, seps ...string) string
- func JsonDecode(data any) any
- func JsonEncode(data any) string
- func JsonEncodeBytes(data any) []byte
- func Long2ip(ip int) string
- func MD5(str string) string
- func MD5File(file string) (string, error)
- func MapMerge[T, K comparable](m map[T]K, ms ...map[T]K) map[T]K
- func MkTime(t ...int) int
- func NewLocalCache(cache_sizes ...int) *cache.Cache
- func NewTCPKeepAliveListener(ln *net.TCPListener, d time.Duration) net.Listener
- func Now() int
- func ParseDate(a any) time.Time
- func ParseDateTime(a any) time.Time
- func ParseDateTime64(a any) time.Time
- func ParseNaN(num float64) float64
- func ParseTime(a any) time.Time
- func ParseTimestamp(a any) time.Time
- func Printf(f string, s ...any)
- func Println(s ...any)
- func Rand(size int, kind int) []byte
- func RandStr(size int, kind ...int) string
- func RedString(s string) string
- func RegisterSqlDriver(name string, dsnfunc SqlDsn, f ...NewDBFunc)
- func RunMonitor(port string)
- func SetCookie(rw http.ResponseWriter, key, val string, lifetime int, options ...interface{})
- func SetHttpMaxHeaderBytes(m int)
- func SetTcpHandler(h func(net.Conn))
- func SetWebsocketHandler(p string, h func(net.Conn))
- func SetWebsocketMaxHeaderBytes(m int)
- func Sha1(str string) string
- func StaticEmbed(filesys embed.FS, fs_path string)
- func StrToTime(datetime string) int
- func TemplateAddFuncs(vals ...interface{})
- func TemplateEmbed(filesys embed.FS, fs_path string)
- func ToFloat(num string) float64
- func ToFloat32(num string) float32
- func ToFloat64(num string) float64
- func ToInt(num string) int
- func ToInt32(v string) int32
- func ToInt32Slice(nums []string) []int32
- func ToInt64(num string) int64
- func ToInt64Slice(nums []string) []int64
- func ToIntSlice(nums []string) []int
- func ToString(num int) string
- func ToStringSlice(nums []int) []string
- func Uint32() uint32
- func VersionCompare(ver, oldver string) bool
- func YellowString(s string) string
- type CliServer
- type ConfVal
- func (cv *ConfVal) Bool(def ...bool) bool
- func (cv *ConfVal) Int(def ...int) int
- func (cv *ConfVal) Int64(def ...int64) int64
- func (cv *ConfVal) IntMap(def ...MAPI) MAPI
- func (cv *ConfVal) IntSlice(def ...[]int) []int
- func (cv *ConfVal) Map(def ...MAP) MAP
- func (cv *ConfVal) MapSlice(def ...[]MAP) []MAP
- func (cv *ConfVal) MapsSlice(def ...[]MAPS) []MAPS
- func (cv *ConfVal) Slice(def ...[]string) []string
- func (cv *ConfVal) String(def ...string) string
- func (cv *ConfVal) StringMap(def ...MAPS) MAPS
- type Config
- func (this *Config) Get(keys ...string) *ConfVal
- func (this *Config) GetBool(keys ...string) bool
- func (this *Config) GetDefBool(def bool, keys ...string) bool
- func (this *Config) GetDefInt(def int, keys ...string) int
- func (this *Config) GetDefInt64(def int64, keys ...string) int64
- func (this *Config) GetDefIntMap(def MAPI, keys ...string) MAPI
- func (this *Config) GetDefIntSlice(def []int, keys ...string) []int
- func (this *Config) GetDefMap(def MAP, keys ...string) MAP
- func (this *Config) GetDefMapSlice(def []MAP, keys ...string) []MAP
- func (this *Config) GetDefMapsSlice(def []MAPS, keys ...string) []MAPS
- func (this *Config) GetDefSlice(def []string, keys ...string) []string
- func (this *Config) GetDefString(def string, keys ...string) string
- func (this *Config) GetDefStringMap(def MAPS, keys ...string) MAPS
- func (this *Config) GetInt(keys ...string) int
- func (this *Config) GetInt64(keys ...string) int64
- func (this *Config) GetIntMap(keys ...string) MAPI
- func (this *Config) GetIntSlice(keys ...string) []int
- func (this *Config) GetMap(keys ...string) MAP
- func (this *Config) GetMapSlice(keys ...string) []MAP
- func (this *Config) GetMapsSlice(keys ...string) []MAPS
- func (this *Config) GetSlice(keys ...string) []string
- func (this *Config) GetString(keys ...string) string
- func (this *Config) GetStringMap(keys ...string) MAPS
- type DBProxy
- type Error
- type Errorf
- type HttpClient
- func (this *HttpClient) Delete(requrl string, headers ...http.Header) (*HttpResponse, error)
- func (this *HttpClient) Get(requrl string, headers ...http.Header) (*HttpResponse, error)
- func (this *HttpClient) Patch(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
- func (this *HttpClient) Post(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
- func (this *HttpClient) Put(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
- func (this *HttpClient) Request(method, requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
- type HttpResponse
- type HttpServer
- type IMAP
- type IMAPI
- type IMAPS
- type MAP
- type MAPA
- type MAPI
- type MAPS
- type Mapper
- type NewDBFunc
- type RedisProxy
- type RouteApiFunc
- type RouteRpcFunc
- type RpcServer
- type SqlClient
- type SqlDsn
- type TcpServer
- type Template
- type WebsocketServer
Constants ¶
View Source
const ( RAND_KIND_NUM = 0 // 纯数字 RAND_KIND_LOWER = 1 // 小写字母 RAND_KIND_UPPER = 2 // 大写字母 RAND_KIND_ALL = 3 // 数字、大小写字母 )
View Source
const ACTION_SUFFIX = "Action"
View Source
const CONTROLLER_SUFFIX = "Controller"
controller中以此后缀结尾的方法会参与路由
Variables ¶
View Source
var ( //多语言时指定默认语言 DEFAULT_LANG = "CN" //成功 ERR_SUC = &Error{0, "OK"} //系统错误码 ERR_SYSTEM = &Error{10, MAPS{"CN": "系统错误", "EN": "system error"}} ERR_METHOD_INVALID = &Error{11, MAPS{"CN": "请求不合法: %+v", "EN": "invalid request: %+v"}} ERR_FREQ = &Error{12, MAPS{"CN": "接口访问过于频繁: %+v", "EN": "request is too frequently: %+v"}} ERR_RPCAUTH = &Error{13, MAPS{"CN": "rpc认证失败:%+v", "EN": "rpc request unauthorized"}} ERR_PARAMS = &Error{14, MAPS{"CN": "参数错误: %+v", "EN": "invalid param: %+v"}} ERR_OTHER = &Error{15, "%+v"} )
View Source
var ( TemplateRoot = "../templates" TemplateSuffix = ".htm" TemplateFuncs = template.FuncMap{ "include": func(string) string { return "" }, "replace": strings.ReplaceAll, "join": Join, "jsonEncode": func(v interface{}) template.JS { js := JsonEncode(v) return template.JS(js) }, "jsonDecode": func(v interface{}) interface{} { return JsonDecode(v) }, "jscode": func(v interface{}) template.JS { return template.JS(fmt.Sprint(v)) }, "htmlcode": func(v interface{}) template.HTML { return template.HTML(fmt.Sprint(v)) }, "formatTime": FormatTime, "dateTime": DateTime, "asint": AsInt, "asfloat": AsFloat, "default": func(def, v interface{}) interface{} { if v == nil { return def } return v }, } )
View Source
var ( Conf_env_mode string Conf_template_enabled bool Conf_max_post_size int64 Conf_access_log_enabled bool Conf_access_log_success_level_name string Conf_access_log_error_level_name string Conf_access_log_omit_params []string Conf_rpc_auth map[string]string Conf_default_controller string Conf_default_action string UrlRoutes map[string]map[string]any UrlParamRoutes map[int]map[int]map[string]map[string]any UrlPrefix []map[string]string )
配置文件变量缓存(框架中使用),初始化时赋值
View Source
var AppRoot string
应用程序根路径
View Source
var DB = NewDBProxy()
全局共用db代理
View Source
var Debug bool
全局 Debug 开关
View Source
var LocalCache *cache.Cache
本地缓存
View Source
var Logger *log.Logger
全局共用日志
View Source
var Redis = NewRedisProxy()
全局共用redis代理
View Source
var TIME_ZONE = "Local" // Asia/Shanghai, UTC
在项目代码中指定时区
Functions ¶
func AddApi ¶
添加http 方法对应的controller实例, 支持分组; 默认url路径: controller/action, 分组时路径: group/controller/action
func AddRouteApiFunc ¶
func AddRouteApiFunc(controller_name, action_name string, f RouteApiFunc)
添加 route 调用方法, 在脚手架生成代码时使用
func AddRouteRpcFunc ¶
func AddRouteRpcFunc(controller_name, action_name string, f RouteRpcFunc)
添加 route 调用方法, 在脚手架生成代码时使用
func ArrayColumn ¶
func ArrayColumn[T comparable](m []map[string]T, column string, uniqs ...bool) []T
func ArrayColumnMap ¶
func ArrayColumnMap[T comparable](m []map[string]T, column string, index string) map[T]T
func FileGetContents ¶
func FormatTime ¶
func GetMapNode ¶
获取map树的某个节点 m[k1][k2]...[kn]
func GreenString ¶
func Interceptor ¶
func Interceptor(guard bool, errmsg interface{}, fmts ...interface{})
捕获异常时,可同时返回data(通过fmts参数最后一个类型为map的值)
func JsonDecode ¶
func JsonEncode ¶
func JsonEncodeBytes ¶
func NewLocalCache ¶
func NewTCPKeepAliveListener ¶
func ParseDateTime ¶
func ParseDateTime64 ¶
func ParseTimestamp ¶
func RegisterSqlDriver ¶
func RunMonitor ¶
func RunMonitor(port string)
func SetCookie ¶
func SetCookie(rw http.ResponseWriter, key, val string, lifetime int, options ...interface{})
lifetime<0时删除cookie options: domain,secure,httponly,path
func YellowString ¶
Types ¶
type CliServer ¶
type CliServer struct {
// contains filtered or unexported fields
}
func NewCliServer ¶
func (*CliServer) AddController ¶
type Config ¶
type Config struct { ConfigFile string // contains filtered or unexported fields }
var Conf *Config
全局共用配置
func (*Config) GetDefMapsSlice ¶
func (*Config) GetIntSlice ¶
func (*Config) GetMapSlice ¶
func (*Config) GetMapsSlice ¶
func (*Config) GetStringMap ¶
type DBProxy ¶
type DBProxy struct {
// contains filtered or unexported fields
}
func NewDBProxy ¶
func NewDBProxy() *DBProxy
type Errorf ¶
type Errorf struct { Code int Msg interface{} // contains filtered or unexported fields }
格式化输出错误信息 用于 Interceptor 拦截抛错 国际化产品,多语言时,Msg 可以设置为MAPS(map[string]string),如:{"CN":"系统错误", "EN":"system error"}
func (*Errorf) GetMessage ¶
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient(timeouts ...int) *HttpClient
func (*HttpClient) Delete ¶
func (this *HttpClient) Delete(requrl string, headers ...http.Header) (*HttpResponse, error)
func (*HttpClient) Get ¶
func (this *HttpClient) Get(requrl string, headers ...http.Header) (*HttpResponse, error)
func (*HttpClient) Patch ¶
func (this *HttpClient) Patch(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
func (*HttpClient) Post ¶
func (this *HttpClient) Post(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
func (*HttpClient) Put ¶
func (this *HttpClient) Put(requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
func (*HttpClient) Request ¶
func (this *HttpClient) Request(method, requrl string, post_data interface{}, headers ...http.Header) (*HttpResponse, error)
post_data 支持map[string]interface{} 和 io.Reader 两种参数类型
type HttpResponse ¶
type HttpResponse struct {
// contains filtered or unexported fields
}
func (*HttpResponse) GetCode ¶
func (r *HttpResponse) GetCode() int
func (*HttpResponse) GetHeader ¶
func (r *HttpResponse) GetHeader() http.Header
func (*HttpResponse) GetResponse ¶
func (r *HttpResponse) GetResponse() string
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
func NewHttpServer ¶
func NewHttpServer(addr string, port, timeout int, useGraceful, enable_pprof, enable_static bool, static_path, static_root string) *HttpServer
func (*HttpServer) AddController ¶
func (this *HttpServer) AddController(c interface{}, group ...string)
func (*HttpServer) Run ¶
func (this *HttpServer) Run()
type RedisProxy ¶
type RedisProxy struct {
// contains filtered or unexported fields
}
func NewRedisProxy ¶
func NewRedisProxy() *RedisProxy
func (*RedisProxy) Get ¶
func (this *RedisProxy) Get(conf_name string) (*redis.RedisClient, error)
type RouteRpcFunc ¶
执行路由方法的函数
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
func (*RpcServer) AddController ¶
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
func (*TcpServer) SetTcpHandler ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
func NewTemplate ¶
func NewTemplate() *Template
type WebsocketServer ¶
type WebsocketServer struct {
// contains filtered or unexported fields
}
func NewWebsocketServer ¶
func NewWebsocketServer(addr string, port, timeout int, useGraceful bool) *WebsocketServer
func (*WebsocketServer) Run ¶
func (this *WebsocketServer) Run()
Source Files
¶
Click to show internal directories.
Click to hide internal directories.