Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterAPIServer(key string, apiServer APIServerProvider)
- func RegisterApp(key string, app AppProvider)
- func RegisterCache(key string, cache CacheProvider)
- func RegisterConfig(key string, config ConfigProvider)
- func RegisterController(key string, controller ControllerProvider)
- func RegisterCookies(key string, cookies CookiesProvider)
- func RegisterCtx(key string, ctx CtxProvider)
- func RegisterDatabase(key string, database DatabaseProvider)
- func RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
- func RegisterError(key string, error ErrorProvider)
- func RegisterHTTPRouter(key string, router HTTPRouterProvider)
- func RegisterHTTPServer(key string, httpServer HTTPServerProvider)
- func RegisterI18n(key string, i18n I18nProvider)
- func RegisterLogger(key string, logger LoggerProvider)
- func RegisterSession(key string, session SessionProvider)
- func RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
- func RegisterTemplate(key string, template TemplateProvider)
- func RegisterView(key string, view ViewProvider)
- func SetCtx(w http.ResponseWriter, c Ctx) http.ResponseWriter
- type APIServer
- type APIServerProvider
- type ActiveRecord
- type App
- type AppProvider
- type AutoProvider
- func (p *AutoProvider) APIServer(key ...string) APIServerProvider
- func (p *AutoProvider) App(key ...string) AppProvider
- func (p *AutoProvider) Cache(key ...string) CacheProvider
- func (p *AutoProvider) Config(key ...string) ConfigProvider
- func (p *AutoProvider) Controller(key ...string) ControllerProvider
- func (p *AutoProvider) Cookies(key ...string) CookiesProvider
- func (p *AutoProvider) Ctx(key ...string) CtxProvider
- func (p *AutoProvider) Database(key ...string) DatabaseProvider
- func (p *AutoProvider) DatabaseGroup(key ...string) DatabaseGroupProvider
- func (p *AutoProvider) Error(key ...string) ErrorProvider
- func (p *AutoProvider) HTTPRouter(key ...string) HTTPRouterProvider
- func (p *AutoProvider) HTTPServer(key ...string) HTTPServerProvider
- func (p *AutoProvider) I18n(key ...string) I18nProvider
- func (p *AutoProvider) Logger(key ...string) LoggerProvider
- func (p *AutoProvider) RegisterAPIServer(key string, apiServer APIServerProvider)
- func (p *AutoProvider) RegisterApp(key string, app AppProvider)
- func (p *AutoProvider) RegisterCache(key string, cache CacheProvider)
- func (p *AutoProvider) RegisterConfig(key string, config ConfigProvider)
- func (p *AutoProvider) RegisterController(key string, controller ControllerProvider)
- func (p *AutoProvider) RegisterCookies(key string, cookies CookiesProvider)
- func (p *AutoProvider) RegisterCtx(key string, ctx CtxProvider)
- func (p *AutoProvider) RegisterDatabase(key string, database DatabaseProvider)
- func (p *AutoProvider) RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
- func (p *AutoProvider) RegisterError(key string, error ErrorProvider)
- func (p *AutoProvider) RegisterHTTPRouter(key string, router HTTPRouterProvider)
- func (p *AutoProvider) RegisterHTTPServer(key string, httpServer HTTPServerProvider)
- func (p *AutoProvider) RegisterI18n(key string, i18n I18nProvider)
- func (p *AutoProvider) RegisterLogger(key string, logger LoggerProvider)
- func (p *AutoProvider) RegisterSession(key string, session SessionProvider)
- func (p *AutoProvider) RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
- func (p *AutoProvider) RegisterTemplate(key string, template TemplateProvider)
- func (p *AutoProvider) RegisterView(key string, view ViewProvider)
- func (p *AutoProvider) Session(key ...string) SessionProvider
- func (p *AutoProvider) SessionStorage(key ...string) SessionStorageProvider
- func (p *AutoProvider) Template(key ...string) TemplateProvider
- func (p *AutoProvider) View(key ...string) ViewProvider
- type Cache
- type CacheProvider
- type CommonConfig
- type Config
- type ConfigProvider
- type Controller
- type ControllerProvider
- type CookieOptions
- type Cookies
- type CookiesProvider
- type Ctx
- type CtxProvider
- type DBCache
- type Database
- type DatabaseGroup
- type DatabaseGroupProvider
- type DatabaseProvider
- type Error
- type ErrorProvider
- type HTTPRouter
- type HTTPRouterProvider
- type HTTPServer
- type HTTPServerProvider
- type Handle
- type Handler
- type I18n
- type I18nProvider
- type LogFlag
- type LogLevel
- type Logger
- type LoggerProvider
- type LoggerWriter
- type Middleware
- type Paginator
- type Param
- type Params
- type ProviderFactory
- func (p *ProviderFactory) APIServer(key string) APIServerProvider
- func (p *ProviderFactory) App(key string) AppProvider
- func (p *ProviderFactory) Cache(key string) CacheProvider
- func (p *ProviderFactory) Config(key string) ConfigProvider
- func (p *ProviderFactory) Controller(key string) ControllerProvider
- func (p *ProviderFactory) Cookies(key string) CookiesProvider
- func (p *ProviderFactory) Ctx(key string) CtxProvider
- func (p *ProviderFactory) Database(key string) DatabaseProvider
- func (p *ProviderFactory) DatabaseGroup(key string) DatabaseGroupProvider
- func (p *ProviderFactory) Error(key string) ErrorProvider
- func (p *ProviderFactory) HTTPRouter(key string) HTTPRouterProvider
- func (p *ProviderFactory) HTTPServer(key string) HTTPServerProvider
- func (p *ProviderFactory) I18n(key string) I18nProvider
- func (p *ProviderFactory) Logger(key string) LoggerProvider
- func (p *ProviderFactory) RegisterAPIServer(key string, apiServer APIServerProvider)
- func (p *ProviderFactory) RegisterApp(key string, app AppProvider)
- func (p *ProviderFactory) RegisterCache(key string, cache CacheProvider)
- func (p *ProviderFactory) RegisterConfig(key string, config ConfigProvider)
- func (p *ProviderFactory) RegisterController(key string, controller ControllerProvider)
- func (p *ProviderFactory) RegisterCookies(key string, cookies CookiesProvider)
- func (p *ProviderFactory) RegisterCtx(key string, ctx CtxProvider)
- func (p *ProviderFactory) RegisterDatabase(key string, database DatabaseProvider)
- func (p *ProviderFactory) RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
- func (p *ProviderFactory) RegisterError(key string, error ErrorProvider)
- func (p *ProviderFactory) RegisterHTTPRouter(key string, router HTTPRouterProvider)
- func (p *ProviderFactory) RegisterHTTPServer(key string, httpServer HTTPServerProvider)
- func (p *ProviderFactory) RegisterI18n(key string, i18n I18nProvider)
- func (p *ProviderFactory) RegisterLogger(key string, logger LoggerProvider)
- func (p *ProviderFactory) RegisterSession(key string, session SessionProvider)
- func (p *ProviderFactory) RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
- func (p *ProviderFactory) RegisterTemplate(key string, template TemplateProvider)
- func (p *ProviderFactory) RegisterView(key string, view ViewProvider)
- func (p *ProviderFactory) Session(key string) SessionProvider
- func (p *ProviderFactory) SessionStorage(key string) SessionStorageProvider
- func (p *ProviderFactory) Template(key string) TemplateProvider
- func (p *ProviderFactory) View(key string) ViewProvider
- type ResponseWriter
- type ResultSet
- type Service
- type ServiceItem
- type Session
- type SessionProvider
- type SessionStorage
- type SessionStorageProvider
- type StackFrame
- type SubConfig
- type Template
- type TemplateProvider
- type View
- type ViewProvider
Constants ¶
const (
DefaultProviderKey = "default"
)
Variables ¶
var DefaultCookieOptions = &CookieOptions{ MaxAge: 0, Path: "/", Domain: "", Secure: false, HTTPOnly: true, }
var MatchedRoutePathParam = "$matchedRoutePath"
MatchedRoutePathParam is the Param name under which the path of the matched route is stored, if Router.SaveMatchedRoutePath is set.
var ParamsKey = paramsKey{}
ParamsKey is the request context key under which URL params are stored.
Functions ¶
func RegisterAPIServer ¶
func RegisterAPIServer(key string, apiServer APIServerProvider)
func RegisterApp ¶
func RegisterApp(key string, app AppProvider)
func RegisterCache ¶
func RegisterCache(key string, cache CacheProvider)
func RegisterConfig ¶
func RegisterConfig(key string, config ConfigProvider)
func RegisterController ¶
func RegisterController(key string, controller ControllerProvider)
func RegisterCookies ¶
func RegisterCookies(key string, cookies CookiesProvider)
func RegisterCtx ¶
func RegisterCtx(key string, ctx CtxProvider)
func RegisterDatabase ¶
func RegisterDatabase(key string, database DatabaseProvider)
func RegisterDatabaseGroup ¶
func RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
func RegisterError ¶
func RegisterError(key string, error ErrorProvider)
func RegisterHTTPRouter ¶
func RegisterHTTPRouter(key string, router HTTPRouterProvider)
func RegisterHTTPServer ¶
func RegisterHTTPServer(key string, httpServer HTTPServerProvider)
func RegisterI18n ¶
func RegisterI18n(key string, i18n I18nProvider)
func RegisterLogger ¶
func RegisterLogger(key string, logger LoggerProvider)
func RegisterSession ¶
func RegisterSession(key string, session SessionProvider)
func RegisterSessionStorage ¶
func RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
func RegisterTemplate ¶
func RegisterTemplate(key string, template TemplateProvider)
func RegisterView ¶
func RegisterView(key string, view ViewProvider)
func SetCtx ¶
func SetCtx(w http.ResponseWriter, c Ctx) http.ResponseWriter
Types ¶
type APIServer ¶
type APIServer interface {
Run() error
Address() string
Server() *http.Server
Router() HTTPRouter
SetTLSFile(certFile, keyFile string)
SetLogger(l Logger)
Logger() Logger
AddMiddleware0(m Middleware)
AddMiddleware1(m Middleware)
AddMiddleware2(m Middleware)
AddMiddleware3(m Middleware)
SetNotFoundHandler(handle func(ctx Ctx))
SetErrorHandler(handle func(ctx Ctx, err interface{}))
ShowErrorStack(isShow bool)
Ext(ext string)
API(path string, handle func(ctx Ctx), ext ...string)
Group(path string) APIServer
PrintRouteTable(w io.Writer)
ActiveConnCount() int64
SetLog(l Logger)
Listeners() []net.Listener
Listener() net.Listener
Ctx() Ctx
ListenerFactory() func(addr string) (net.Listener, error)
SetListenerFactory(listenerFactory func(addr string) (net.Listener, error))
ServeEmbedFS(fs embed.FS, urlPath string)
ServeFiles(rootPath, urlPath string)
}
type APIServerProvider ¶
func ProviderAPIServer ¶
func ProviderAPIServer(key ...string) APIServerProvider
type ActiveRecord ¶
type ActiveRecord interface {
Cache(key string, seconds uint) ActiveRecord
Delete(table string, where map[string]interface{}) ActiveRecord
From(from string) ActiveRecord
FromAs(from, as string) ActiveRecord
GroupBy(column string) ActiveRecord
Having(having string) ActiveRecord
HavingWrap(having, leftWrap, rightWrap string) ActiveRecord
Insert(table string, data map[string]interface{}) ActiveRecord
InsertBatch(table string, data []map[string]interface{}) ActiveRecord
Join(table, as, on, typ string) ActiveRecord
Limit(limit ...int) ActiveRecord
OrderBy(column, typ string) ActiveRecord
Raw(sql string, values ...interface{}) ActiveRecord
Replace(table string, data map[string]interface{}) ActiveRecord
ReplaceBatch(table string, data []map[string]interface{}) ActiveRecord
Reset()
Select(columns string) ActiveRecord
SelectNoWrap(columns string) ActiveRecord
Set(column string, value interface{}) ActiveRecord
SetNoWrap(column string, value interface{}) ActiveRecord
SQL() string
Update(table string, data, where map[string]interface{}) ActiveRecord
UpdateBatch(table string, values []map[string]interface{}, whereColumn []string) ActiveRecord
Values() []interface{}
Where(where map[string]interface{}) ActiveRecord
WhereWrap(where map[string]interface{}, leftWrap, rightWrap string) ActiveRecord
WhereRaw(where string) ActiveRecord
Wrap(v string) string
}
ActiveRecord gmc abstract sql statement builder layer.
type App ¶
type App interface {
SetConfigFile(file string)
SetConfig(cfg Config)
AttachConfigFile(id, file string)
AttachConfig(id string, cfg Config)
Config(id ...string) Config
Run() (err error)
OnRun(fn func(Config) (err error))
OnShutdown(fn func())
SetBlock(isBlockRun bool)
AddService(item ServiceItem)
SetLogger(logger Logger)
Logger() Logger
Stop()
Ctx() Ctx
SetCtx(Ctx)
}
App gmc abstract app layer, to run gmc service or common purpose.
type AppProvider ¶
func ProviderApp ¶
func ProviderApp(key ...string) AppProvider
type AutoProvider ¶
type AutoProvider struct {
// contains filtered or unexported fields
}
func NewAutoProvider ¶
func NewAutoProvider() *AutoProvider
func (*AutoProvider) APIServer ¶
func (p *AutoProvider) APIServer(key ...string) APIServerProvider
func (*AutoProvider) App ¶
func (p *AutoProvider) App(key ...string) AppProvider
func (*AutoProvider) Cache ¶
func (p *AutoProvider) Cache(key ...string) CacheProvider
func (*AutoProvider) Config ¶
func (p *AutoProvider) Config(key ...string) ConfigProvider
func (*AutoProvider) Controller ¶
func (p *AutoProvider) Controller(key ...string) ControllerProvider
func (*AutoProvider) Cookies ¶
func (p *AutoProvider) Cookies(key ...string) CookiesProvider
func (*AutoProvider) Ctx ¶
func (p *AutoProvider) Ctx(key ...string) CtxProvider
func (*AutoProvider) Database ¶
func (p *AutoProvider) Database(key ...string) DatabaseProvider
func (*AutoProvider) DatabaseGroup ¶
func (p *AutoProvider) DatabaseGroup(key ...string) DatabaseGroupProvider
func (*AutoProvider) Error ¶
func (p *AutoProvider) Error(key ...string) ErrorProvider
func (*AutoProvider) HTTPRouter ¶
func (p *AutoProvider) HTTPRouter(key ...string) HTTPRouterProvider
func (*AutoProvider) HTTPServer ¶
func (p *AutoProvider) HTTPServer(key ...string) HTTPServerProvider
func (*AutoProvider) I18n ¶
func (p *AutoProvider) I18n(key ...string) I18nProvider
func (*AutoProvider) Logger ¶
func (p *AutoProvider) Logger(key ...string) LoggerProvider
func (*AutoProvider) RegisterAPIServer ¶
func (p *AutoProvider) RegisterAPIServer(key string, apiServer APIServerProvider)
func (*AutoProvider) RegisterApp ¶
func (p *AutoProvider) RegisterApp(key string, app AppProvider)
func (*AutoProvider) RegisterCache ¶
func (p *AutoProvider) RegisterCache(key string, cache CacheProvider)
func (*AutoProvider) RegisterConfig ¶
func (p *AutoProvider) RegisterConfig(key string, config ConfigProvider)
func (*AutoProvider) RegisterController ¶
func (p *AutoProvider) RegisterController(key string, controller ControllerProvider)
func (*AutoProvider) RegisterCookies ¶
func (p *AutoProvider) RegisterCookies(key string, cookies CookiesProvider)
func (*AutoProvider) RegisterCtx ¶
func (p *AutoProvider) RegisterCtx(key string, ctx CtxProvider)
func (*AutoProvider) RegisterDatabase ¶
func (p *AutoProvider) RegisterDatabase(key string, database DatabaseProvider)
func (*AutoProvider) RegisterDatabaseGroup ¶
func (p *AutoProvider) RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
func (*AutoProvider) RegisterError ¶
func (p *AutoProvider) RegisterError(key string, error ErrorProvider)
func (*AutoProvider) RegisterHTTPRouter ¶
func (p *AutoProvider) RegisterHTTPRouter(key string, router HTTPRouterProvider)
func (*AutoProvider) RegisterHTTPServer ¶
func (p *AutoProvider) RegisterHTTPServer(key string, httpServer HTTPServerProvider)
func (*AutoProvider) RegisterI18n ¶
func (p *AutoProvider) RegisterI18n(key string, i18n I18nProvider)
func (*AutoProvider) RegisterLogger ¶
func (p *AutoProvider) RegisterLogger(key string, logger LoggerProvider)
func (*AutoProvider) RegisterSession ¶
func (p *AutoProvider) RegisterSession(key string, session SessionProvider)
func (*AutoProvider) RegisterSessionStorage ¶
func (p *AutoProvider) RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
func (*AutoProvider) RegisterTemplate ¶
func (p *AutoProvider) RegisterTemplate(key string, template TemplateProvider)
func (*AutoProvider) RegisterView ¶
func (p *AutoProvider) RegisterView(key string, view ViewProvider)
func (*AutoProvider) Session ¶
func (p *AutoProvider) Session(key ...string) SessionProvider
func (*AutoProvider) SessionStorage ¶
func (p *AutoProvider) SessionStorage(key ...string) SessionStorageProvider
func (*AutoProvider) Template ¶
func (p *AutoProvider) Template(key ...string) TemplateProvider
func (*AutoProvider) View ¶
func (p *AutoProvider) View(key ...string) ViewProvider
type Cache ¶
type Cache interface {
// Has returns true if cached value exists.
Has(key string) (bool, error)
// Clear deletes all cached data.
Clear() error
// String returns info about this driver.
String() string
// Get gets cached value by given key.
Get(key string) (string, error)
// Put puts value into cache with key and expire time.
Set(key string, value string, ttl time.Duration) error
// Delete deletes cached value by given key.
Del(key string) error
// GetMulti gets multiple keys's values at once.
GetMulti(keys []string) (map[string]string, error)
// SetMulti sets multiple keys's values at once.
SetMulti(values map[string]string, ttl time.Duration) (err error)
// DelMulti deletes multiple keys's values at once.
DelMulti(keys []string) (err error)
// Incr increases cached int-type value by given key as a counter.
Incr(key string) (int64, error)
// Decr decreases cached int-type value by given key as a counter.
Decr(key string) (int64, error)
// Incr increases N cached int-type value by given key as a counter.
IncrN(key string, n int64) (int64, error)
// Decr decreases N cached int-type value by given key as a counter.
DecrN(key string, n int64) (int64, error)
}
Cache gmc abstract cache layer, to access cache.
type CacheProvider ¶
func ProviderCache ¶
func ProviderCache(key ...string) CacheProvider
type CommonConfig ¶
type CommonConfig interface {
SetConfigFile(in string)
SetEnvPrefix(in string)
AllowEmptyEnv(allowEmptyEnv bool)
ConfigFileUsed() string
AddConfigPath(in string)
SetTypeByDefaultValue(enable bool)
Get(key string) interface{}
GetString(key string) string
GetBool(key string) bool
GetInt(key string) int
GetInt32(key string) int32
GetInt64(key string) int64
GetUint(key string) uint
GetUint32(key string) uint32
GetUint64(key string) uint64
GetFloat64(key string) float64
GetTime(key string) time.Time
GetDuration(key string) time.Duration
GetIntSlice(key string) []int
GetStringSlice(key string) []string
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringMapStringSlice(key string) map[string][]string
GetSizeInBytes(key string) uint
BindEnv(input ...string) error
IsSet(key string) bool
AutomaticEnv()
SetEnvKeyReplacer(r *strings.Replacer)
RegisterAlias(alias string, key string)
InConfig(key string) bool
SetDefault(key string, value interface{})
Set(key string, value interface{})
ReadInConfig() error
MergeInConfig() error
ReadConfig(in io.Reader) error
MergeConfig(in io.Reader) error
MergeConfigMap(cfg map[string]interface{}) error
WriteConfig() error
SafeWriteConfig() error
WriteConfigAs(filename string) error
SafeWriteConfigAs(filename string) error
AllKeys() []string
AllSettings() map[string]interface{}
SetConfigName(in string)
SetConfigType(in string)
SetConfigPermissions(perm os.FileMode)
Debug()
}
CommonConfig gmc basic abstract config layer.
type Config ¶
type Config interface {
CommonConfig
Sub(key string) SubConfig
}
Config gmc abstract config layer, to access config.
type ConfigProvider ¶
type ConfigProvider func() Config
func ProviderConfig ¶
func ProviderConfig(key ...string) ConfigProvider
type Controller ¶
type Controller interface {
MethodCallPre(ctx Ctx)
MethodCallPost()
Tr(key string, defaultText ...string) string
Die(msg ...interface{})
Stop(msg ...interface{})
StopE(err interface{}, fn ...func())
SessionStart() (err error)
SessionDestroy() (err error)
Write(data ...interface{}) (n int, err error)
WriteE(data ...interface{}) (n int, err error)
GetCtx() Ctx
GetParam() Params
GetSession() Session
GetTemplate() Template
GetI18n() I18n
GetSessionStore() SessionStorage
GetRouter() HTTPRouter
GetCookie() Cookies
GetView() View
GetLang() string
GetLogger() Logger
GetConfig() Config
}
type ControllerProvider ¶
type ControllerProvider func(ctx Ctx) Controller
func ProviderController ¶
func ProviderController(key ...string) ControllerProvider
type CookieOptions ¶
type CookieOptions struct {
MaxAge int // optional
Path string // optional, default to "/"
Domain string // optional
Secure bool // optional
HTTPOnly bool // optional, default to `true“
}
CookieOptions is used to setting cookie.
type Cookies ¶
type Cookies interface {
Get(name string) (value string, err error)
Set(name, val string, options ...*CookieOptions)
Remove(name string, options ...*CookieOptions)
}
type CookiesProvider ¶
func ProviderCookies ¶
func ProviderCookies(key ...string) CookiesProvider
type Ctx ¶
type Ctx interface {
Conn() net.Conn
SetConn(conn net.Conn)
RemoteAddr() string
SetRemoteAddr(remoteAddr string)
Template() Template
SetTemplate(template Template)
I18n() I18n
SetI18n(i18n I18n)
Config() Config
SetConfig(config Config)
Logger() Logger
SetLogger(logger Logger)
App() App
SetApp(app App)
Clone() Ctx
CloneWithHTTP(w http.ResponseWriter, r *http.Request, ps ...Params) Ctx
APIServer() APIServer
SetAPIServer(apiServer APIServer)
WebServer() HTTPServer
SetWebServer(webServer HTTPServer)
LocalAddr() string
SetLocalAddr(localAddr string)
Param() Params
GetParam(key string) string
Request() *http.Request
SetRequest(request *http.Request)
Response() http.ResponseWriter
SetResponse(response http.ResponseWriter)
SetParam(param Params)
TimeUsed() time.Duration
SetTimeUsed(t time.Duration)
Write(data ...interface{}) (n int, err error)
WriteTo(w io.Writer, data ...interface{}) (n int, err error)
WriteE(data ...interface{}) (n int, err error)
WriteHeader(statusCode int)
StatusCode() int
Status(code int)
WriteCount() int64
IsPOST() bool
IsGET() bool
IsPUT() bool
IsDELETE() bool
IsPATCH() bool
IsHEAD() bool
IsOPTIONS() bool
IsAJAX() bool
IsWebsocket() bool
Stop(msg ...interface{})
StopJSON(code int, msg interface{})
ClientIP() (ip string)
NewPager(perPage int, total int64) Paginator
GET(key string, Default ...string) (val string)
GETArray(key string, Default ...string) (val []string)
GETData() (data map[string]string)
POST(key string, Default ...string) (val string)
POSTArray(key string, Default ...string) (val []string)
POSTData() (data map[string]string)
GetPost(key string, Default ...string) (val string)
Host() (host string)
JSON(code int, data interface{}) (err error)
JSONTo(w io.Writer, code int, data interface{}) (err error)
PrettyJSON(code int, data interface{}) (err error)
PrettyJSONTo(w io.Writer, code int, data interface{}) (err error)
JSONP(code int, data interface{}) (err error)
JSONPTo(w io.Writer, code int, data interface{}) (err error)
Redirect(url string) (val string)
SetHeader(key, value string)
Header(key string) string
RequestBody() ([]byte, error)
SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
Cookie(name string) string
WriteFile(filepath string)
WriteFileFromFS(filepath string, fs http.FileSystem)
WriteFileAttachment(filepath, filename string)
FullPath() string
Set(key interface{}, value interface{})
Get(key interface{}) (value interface{}, exists bool)
MustGet(key interface{}) (v interface{})
FormFile(name string, maxMultipartMemory int64) (*multipart.FileHeader, error)
MultipartForm(maxMultipartMemory int64) (*multipart.Form, error)
SaveUploadedFile(file *multipart.FileHeader, dst string) error
ControllerMethod() string
SetControllerMethod(controllerMethod string)
IsTLSRequest() bool
Controller() Controller
SetController(controller Controller)
}
Ctx gmc context layer in gmc web.
func GetCtx ¶
func GetCtx(w http.ResponseWriter) Ctx
type CtxProvider ¶
type CtxProvider func() Ctx
func ProviderCtx ¶
func ProviderCtx(key ...string) CtxProvider
type DBCache ¶
type DBCache interface {
Set(key string, val []byte, expire uint) (err error)
Get(key string) (data []byte, err error)
}
DBCache gmc abstract db cache layer, to cache db query.
type Database ¶
type Database interface {
AR() (ar ActiveRecord)
Stats() sql.DBStats
Begin() (tx *sql.Tx, err error)
ExecTx(ar ActiveRecord, tx *sql.Tx) (rs ResultSet, err error)
ExecSQLTx(tx *sql.Tx, sqlStr string, values ...interface{}) (rs ResultSet, err error)
Exec(ar ActiveRecord) (rs ResultSet, err error)
ExecSQL(sqlStr string, values ...interface{}) (rs ResultSet, err error)
QuerySQL(sqlStr string, values ...interface{}) (rs ResultSet, err error)
Query(ar ActiveRecord) (rs ResultSet, err error)
}
Database gmc abstract db access layer, to connect to db and execute sql.
type DatabaseGroup ¶
type DatabaseGroupProvider ¶
type DatabaseGroupProvider func(ctx Ctx) (DatabaseGroup, error)
func ProviderDatabaseGroup ¶
func ProviderDatabaseGroup(key ...string) DatabaseGroupProvider
type DatabaseProvider ¶
func ProviderDatabase ¶
func ProviderDatabase(key ...string) DatabaseProvider
type Error ¶
type Error interface {
New(e interface{}) Error
StackError(e interface{}) string
Wrap(e interface{}) Error
WrapN(e interface{}, skip int) Error
WrapPrefix(e interface{}, prefix string, skip int) Error
WrapPrefixN(e interface{}, prefix string, skip int) Error
Errorf(format string, a ...interface{}) Error
Error() string
Stack() []byte
StackStr() string
String() string
Callers() []uintptr
ErrorStack() string
StackFrames() []StackFrame
TypeName() string
Recover(f ...interface{})
}
type ErrorProvider ¶
type ErrorProvider func() Error
func ProviderError ¶
func ProviderError(key ...string) ErrorProvider
type HTTPRouter ¶
type HTTPRouter interface {
Group(ns string) HTTPRouter
Namespace() string
Ext(ext string)
Controller(urlPath string, obj Controller, ext ...string)
PrintRouteTable(w io.Writer)
RouteTable() (table map[string][]string)
ControllerMethod(urlPath string, obj Controller, method string)
Handle(method, path string, handle Handle)
HandleAny(path string, handle Handle)
Handler(method, path string, handler http.Handler)
HandlerAny(path string, handler http.Handler)
HandlerFunc(method, path string, handler http.HandlerFunc)
HandlerFuncAny(path string, handler http.HandlerFunc)
GET(path string, handle Handle)
HEAD(path string, handle Handle)
OPTIONS(path string, handle Handle)
POST(path string, handle Handle)
PUT(path string, handle Handle)
PATCH(path string, handle Handle)
DELETE(path string, handle Handle)
ServeFiles(path string, root http.FileSystem)
Lookup(method, path string) (Handle, Params, bool)
ServeHTTP(w http.ResponseWriter, req *http.Request)
}
type HTTPRouterProvider ¶
type HTTPRouterProvider func(ctx Ctx) HTTPRouter
func ProviderHTTPRouter ¶
func ProviderHTTPRouter(key ...string) HTTPRouterProvider
type HTTPServer ¶
type HTTPServer interface {
SetNotFoundHandler(fn func(ctx Ctx, tpl Template))
SetErrorHandler(fn func(ctx Ctx, tpl Template, err interface{}))
AddFuncMap(f map[string]interface{})
SetConfig(c Config)
Config() Config
ActiveConnCount() int64
Listener() net.Listener
Listeners() []net.Listener
Server() *http.Server
SetLogger(l Logger)
Logger() Logger
SetRouter(r HTTPRouter)
Router() HTTPRouter
SetTpl(t Template)
Tpl() Template
SetSessionStore(st SessionStorage)
SessionStore() SessionStorage
AddMiddleware0(m Middleware)
AddMiddleware1(m Middleware)
AddMiddleware2(m Middleware)
AddMiddleware3(m Middleware)
PrintRouteTable(w io.Writer)
SetLog(l Logger)
Ctx() Ctx
ListenerFactory() func(addr string) (net.Listener, error)
SetListenerFactory(listenerFactory func(addr string) (net.Listener, error))
SetBinBytes(binData map[string][]byte)
Listen() (err error)
ListenTLS() (err error)
SetCtx(ctx Ctx)
ServeEmbedFS(fs embed.FS, urlPath string)
ServeFiles(rootPath, urlPath string)
}
type HTTPServerProvider ¶
type HTTPServerProvider func(ctx Ctx) HTTPServer
func ProviderHTTPServer ¶
func ProviderHTTPServer(key ...string) HTTPServerProvider
type Handle ¶
type Handle func(http.ResponseWriter, *http.Request, Params)
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (path variables).
type I18n ¶
type I18n interface {
Add(lang string, data map[string]string)
Lang(lang string)
String(lang string)
Tr(lang, key string, defaultMessage ...string) string
TrLangs(langs []string, key string, defaultMessage ...string) string
TrV(lang, key string, defaultMessage ...string) template.HTML
ParseAcceptLanguageStr(s string) (str string, err error)
ParseAcceptLanguageStrT(s string) (t language.Tag, err error)
ParseAcceptLanguage(r *http.Request) (strs []string, err error)
ParseAcceptLanguageT(r *http.Request) (tags []language.Tag, err error)
Languages() (languages []string, err error)
LanguagesT() (languages []language.Tag, err error)
MatchT(languages []language.Tag) (t language.Tag, err error)
MatchAcceptLanguageT(r *http.Request) (tag language.Tag, err error)
Clone(lang string) I18n
}
type I18nProvider ¶
func ProviderI18n ¶
func ProviderI18n(key ...string) I18nProvider
type Logger ¶
type Logger interface {
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Trace(v ...interface{})
Tracef(format string, v ...interface{})
Level() LogLevel
SetLevel(LogLevel)
With(name string) Logger
Namespace() string
Writer() LoggerWriter
AddWriter(LoggerWriter) Logger
AddLevelWriter(io.Writer, LogLevel) Logger
AddLevelsWriter(io.Writer, ...LogLevel) Logger
SetOutput(LoggerWriter)
SetFlag(f LogFlag)
Async() bool
WaitAsyncDone()
EnableAsync()
CallerSkip() int
SetCallerSkip(callerSkip int)
Write(string, LogLevel)
WriteRaw(string, LogLevel)
ExitCode() int
SetExitCode(exitCode int)
ExitFunc() func(int)
SetExitFunc(exitFunc func(int))
WithRate(duration time.Duration) Logger
SetRateCallback(cb func(msg string)) Logger
SetTimeLayout(layout string)
SetAsyncBufferSize(asyncBufferSize int)
SetErrHandler(errHandler func(error))
}
type LoggerProvider ¶
func ProviderLogger ¶
func ProviderLogger(key ...string) LoggerProvider
type LoggerWriter ¶
type Middleware ¶
type Paginator ¶
type Paginator interface {
MaxPages() int
SetMaxPages(maxPages int)
PerPageNums() int
SetPerPageNums(perPageNums int)
Request() *http.Request
SetRequest(request *http.Request)
PageNums() int
Nums() int64
SetNums(nums interface{})
Page() int
Pages() []int
PageLink(page int) string
PageBaseLink() string
PageLinkPrev() (link string)
PageLinkNext() (link string)
PageLinkFirst() (link string)
PageLinkLast() (link string)
HasPrev() bool
HasNext() bool
IsActive(page int) bool
Offset() int
HasPages() bool
}
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
func ParamsFromContext ¶
ParamsFromContext pulls the URL parameters from a request context, or returns nil if none are present.
func (Params) ByName ¶
ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.
func (Params) MatchedRoutePath ¶
MatchedRoutePath retrieves the path of the matched route. Router.SaveMatchedRoutePath must have been enabled when the respective handler was added, otherwise this function always returns an empty string.
type ProviderFactory ¶
type ProviderFactory struct {
// contains filtered or unexported fields
}
func NewProviderFactory ¶
func NewProviderFactory() *ProviderFactory
func (*ProviderFactory) APIServer ¶
func (p *ProviderFactory) APIServer(key string) APIServerProvider
func (*ProviderFactory) App ¶
func (p *ProviderFactory) App(key string) AppProvider
func (*ProviderFactory) Cache ¶
func (p *ProviderFactory) Cache(key string) CacheProvider
func (*ProviderFactory) Config ¶
func (p *ProviderFactory) Config(key string) ConfigProvider
func (*ProviderFactory) Controller ¶
func (p *ProviderFactory) Controller(key string) ControllerProvider
func (*ProviderFactory) Cookies ¶
func (p *ProviderFactory) Cookies(key string) CookiesProvider
func (*ProviderFactory) Ctx ¶
func (p *ProviderFactory) Ctx(key string) CtxProvider
func (*ProviderFactory) Database ¶
func (p *ProviderFactory) Database(key string) DatabaseProvider
func (*ProviderFactory) DatabaseGroup ¶
func (p *ProviderFactory) DatabaseGroup(key string) DatabaseGroupProvider
func (*ProviderFactory) Error ¶
func (p *ProviderFactory) Error(key string) ErrorProvider
func (*ProviderFactory) HTTPRouter ¶
func (p *ProviderFactory) HTTPRouter(key string) HTTPRouterProvider
func (*ProviderFactory) HTTPServer ¶
func (p *ProviderFactory) HTTPServer(key string) HTTPServerProvider
func (*ProviderFactory) I18n ¶
func (p *ProviderFactory) I18n(key string) I18nProvider
func (*ProviderFactory) Logger ¶
func (p *ProviderFactory) Logger(key string) LoggerProvider
func (*ProviderFactory) RegisterAPIServer ¶
func (p *ProviderFactory) RegisterAPIServer(key string, apiServer APIServerProvider)
func (*ProviderFactory) RegisterApp ¶
func (p *ProviderFactory) RegisterApp(key string, app AppProvider)
func (*ProviderFactory) RegisterCache ¶
func (p *ProviderFactory) RegisterCache(key string, cache CacheProvider)
func (*ProviderFactory) RegisterConfig ¶
func (p *ProviderFactory) RegisterConfig(key string, config ConfigProvider)
func (*ProviderFactory) RegisterController ¶
func (p *ProviderFactory) RegisterController(key string, controller ControllerProvider)
func (*ProviderFactory) RegisterCookies ¶
func (p *ProviderFactory) RegisterCookies(key string, cookies CookiesProvider)
func (*ProviderFactory) RegisterCtx ¶
func (p *ProviderFactory) RegisterCtx(key string, ctx CtxProvider)
func (*ProviderFactory) RegisterDatabase ¶
func (p *ProviderFactory) RegisterDatabase(key string, database DatabaseProvider)
func (*ProviderFactory) RegisterDatabaseGroup ¶
func (p *ProviderFactory) RegisterDatabaseGroup(key string, databaseGroup DatabaseGroupProvider)
func (*ProviderFactory) RegisterError ¶
func (p *ProviderFactory) RegisterError(key string, error ErrorProvider)
func (*ProviderFactory) RegisterHTTPRouter ¶
func (p *ProviderFactory) RegisterHTTPRouter(key string, router HTTPRouterProvider)
func (*ProviderFactory) RegisterHTTPServer ¶
func (p *ProviderFactory) RegisterHTTPServer(key string, httpServer HTTPServerProvider)
func (*ProviderFactory) RegisterI18n ¶
func (p *ProviderFactory) RegisterI18n(key string, i18n I18nProvider)
func (*ProviderFactory) RegisterLogger ¶
func (p *ProviderFactory) RegisterLogger(key string, logger LoggerProvider)
func (*ProviderFactory) RegisterSession ¶
func (p *ProviderFactory) RegisterSession(key string, session SessionProvider)
func (*ProviderFactory) RegisterSessionStorage ¶
func (p *ProviderFactory) RegisterSessionStorage(key string, sessionStorage SessionStorageProvider)
func (*ProviderFactory) RegisterTemplate ¶
func (p *ProviderFactory) RegisterTemplate(key string, template TemplateProvider)
func (*ProviderFactory) RegisterView ¶
func (p *ProviderFactory) RegisterView(key string, view ViewProvider)
func (*ProviderFactory) Session ¶
func (p *ProviderFactory) Session(key string) SessionProvider
func (*ProviderFactory) SessionStorage ¶
func (p *ProviderFactory) SessionStorage(key string) SessionStorageProvider
func (*ProviderFactory) Template ¶
func (p *ProviderFactory) Template(key string) TemplateProvider
func (*ProviderFactory) View ¶
func (p *ProviderFactory) View(key string) ViewProvider
type ResponseWriter ¶
type ResultSet ¶
type ResultSet interface {
SQL() string
Len() int
LastInsertID() int64
RowsAffected() int64
TimeUsed() time.Duration
MapRows(keyColumn string) (rowsMap map[string]map[string]string)
MapStructs(keyColumn string, strucT interface{}, tagName ...string) (structsMap map[string]interface{}, err error)
Rows() (rows []map[string]string)
Structs(strucT interface{}, tagName ...string) (structs []interface{}, err error)
Row() (row map[string]string)
Struct(strucT interface{}, tagName ...string) (Struct interface{}, err error)
Values(column string) (values []string)
MapValues(keyColumn, valueColumn string) (values map[string]string)
Value(column string) (value string)
}
type Service ¶
type Service interface {
// init servcie
Init(cfg Config) error
//nonblocking, called After Init -> InjectListeners (when reload) -> Start
Start() error
Stop()
// blocking until all resource are released
GracefulStop()
SetLog(log Logger)
// called After Init
InjectListeners([]net.Listener)
ListenerFactory() func(addr string) (net.Listener, error)
SetListenerFactory(listenerFactory func(addr string) (net.Listener, error))
Listeners() []net.Listener
}
type ServiceItem ¶
type Session ¶
type Session interface {
Set(k interface{}, v interface{})
Get(k interface{}) (value interface{})
Delete(k interface{}) (err error)
Destroy() (err error)
Values() (data map[interface{}]interface{})
IsDestroy() bool
SessionID() (sessionID string)
TouchTime() (time int64)
Touch()
Serialize() (str string, err error)
Unserialize(data string) (err error)
}
type SessionProvider ¶
type SessionProvider func() Session
func ProviderSession ¶
func ProviderSession(key ...string) SessionProvider
type SessionStorage ¶
type SessionStorageProvider ¶
type SessionStorageProvider func(ctx Ctx) (SessionStorage, error)
func ProviderSessionStorage ¶
func ProviderSessionStorage(key ...string) SessionStorageProvider
type StackFrame ¶
type StackFrame interface {
// The path to the file containing this ProgramCounter
GetFile() string
// The LineNumber in that file
GetLineNumber() int
// The Name of the function that contains this ProgramCounter
GetName() string
// The Package that contains this function
GetPackage() string
// The underlying ProgramCounter
GetProgramCounter() uintptr
Func() *runtime.Func
String() string
SourceLine() (string, error)
}
type TemplateProvider ¶
func ProviderTemplate ¶
func ProviderTemplate(key ...string) TemplateProvider
type View ¶
type View interface {
Err() error
Set(key string, val interface{}) View
SetMap(d map[string]interface{}) View
Render(tpl string, data ...map[string]interface{}) View
RenderR(tpl string, data ...map[string]interface{}) (d []byte)
Layout(l string) View
Stop()
OnRenderOnce(f func()) View
SetLayoutDir(layoutDir string)
}
type ViewProvider ¶
func ProviderView ¶
func ProviderView(key ...string) ViewProvider