Documentation
¶
Overview ¶
Package golory is ALL IN ONE package for go software development with best practice usages support
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Error occurred when parse configuration ErrParseCfg = errors.New("parse cfg failed") )
Exported errors
Functions ¶
func Boot ¶
func Boot(cfg interface{}) error
Boot initiate components from configuration file or binary content. Toml, Json, Yaml supported.
Example ¶
package main import ( "fmt" "github.com/1pb-club/golory" ) func main() { cfg := ` [golory] [golory.logger.default] debug = true level = "info" path = "./default.log" ` fmt.Println(golory.Boot([]byte(cfg))) }
Output: <nil>
Types ¶
type GormCfg ¶
type GormCfg struct { Debug bool Engine string // Database type, default: mysql Username string // Database Username Password string // Database Password (requires User) Net string // Database Network type Addr string // Database Network address (requires Net) DBName string // Database name Params map[string]interface{} // mysql suffix params ,See in detail:https://github.com/go-sql-driver/mysql#parameters TablePrefix string // database table prefix SingularTable bool // Set true to disable table name's pluralization globally MaxOpenConn int // Maximum connection of database MaxIdleConn int // Maximum idle connection number of database MaxLifetime time.Duration // The maximum time of a single connection in a database }
GormCfg is sql config struct
type GormClient ¶
GormClient contains information for current db connection
type LoggerClient ¶
LoggerClient wrapped zapper TODO: for dynamic config & more log api
func Logger ¶
func Logger(name string) *LoggerClient
Logger return a log.Logger by name
Example ¶
package main import ( "fmt" "github.com/1pb-club/golory" ) func main() { cfg := ` [golory] [golory.logger.golory] debug = true level = "error" path = "golory.log" [golory.logger.default] debug = true level = "info" path = "default.log" ` if err := golory.Boot([]byte(cfg)); err != nil { fmt.Printf("boot golory failed, %s", err) } fmt.Println(golory.Logger("golory") == nil) fmt.Println(golory.Logger("default") == nil) }
Output: false false
type RedisCfg ¶
type RedisCfg struct {
Addr string
}
RedisCfg wrapped go-redis options and some other golory options
type RedisClient ¶
RedisClient wrapped go-redis RedisClient
func Redis ¶
func Redis(name string) *RedisClient
Redis return a redis.Client by name
Example ¶
package main import ( "fmt" "github.com/1pb-club/golory" ) func main() { cfg := ` [golory] [golory.redis.default] Addr = "127.0.0.1:6379" [golory.redis.user] Addr = "127.0.0.1:6479" ` if err := golory.Boot([]byte(cfg)); err != nil { fmt.Printf("boot golory failed, %s", err) } fmt.Println(golory.Redis("default") == nil) fmt.Println(golory.Redis("no-this-user") == nil) }
Output: false true
type TDengineCfg ¶
type TDengineCfg struct { Username string // Database Username Password string // Database Password (requires User) Addr string // Database Network address DBName string // Database name }
TDengineCfg wrapped tdengine options and some other golory options
type TDengineClient ¶
TDengineClient wrapped go-redis TDengineClient
func TDengine ¶
func TDengine(name string) *TDengineClient
TDengine return *TDengineClient by name
Example ¶
package main import ( "fmt" "github.com/1pb-club/golory" ) func main() { cfg := ` [golory] [golory.tdengine.default] username = "root" password = "taosdata" addr = "192.168.1.99:6030" DBName = "top1" ` if err := golory.Boot([]byte(cfg)); err != nil { fmt.Printf("boot golory failed, %s", err) } fmt.Println(golory.TDengine("default") == nil) }
Output: false