Documentation
¶
Overview ¶
Package rkmysql is an implementation of rkentry.Entry which could be used gorm.DB instance.
Copyright (c) 2021 rookie-ninja ¶
Use of this source code is governed by an Apache-style license that can be found in the LICENSE file.
Index ¶
- Constants
- func RegisterMySqlEntriesWithConfig(configFilePath string) map[string]rkentry.Entry
- type BootConfig
- type Logger
- type MySqlEntry
- func (entry *MySqlEntry) Bootstrap(ctx context.Context)
- func (entry *MySqlEntry) GetDB(name string) *gorm.DB
- func (entry *MySqlEntry) GetDescription() string
- func (entry *MySqlEntry) GetName() string
- func (entry *MySqlEntry) GetType() string
- func (entry *MySqlEntry) Interrupt(ctx context.Context)
- func (entry *MySqlEntry) IsHealthy() bool
- func (entry *MySqlEntry) String() string
- type Option
- func WithAddr(addr string) Option
- func WithDatabase(name string, dryRun, autoCreate bool, params ...string) Option
- func WithDescription(description string) Option
- func WithLoggerEncoding(ec string) Option
- func WithLoggerLevel(level string) Option
- func WithLoggerOutputPaths(path ...string) Option
- func WithName(name string) Option
- func WithPass(pass string) Option
- func WithProtocol(protocol string) Option
- func WithUser(user string) Option
Constants ¶
const ( // EncodingConsole console encoding style of logging EncodingConsole = "console" // EncodingJson console encoding style of logging EncodingJson = "json" // LoggerLevelSilent set logger level of gorm as silent LoggerLevelSilent = "silent" // LoggerLevelError set logger level of gorm as error LoggerLevelError = "error" // LoggerLevelWarn set logger level of gorm as warn LoggerLevelWarn = "warn" // LoggerLevelInfo set logger level of gorm as info LoggerLevelInfo = "info" )
Variables ¶
This section is empty.
Functions ¶
func RegisterMySqlEntriesWithConfig ¶
RegisterMySqlEntriesWithConfig register MySqlEntry based on config file into rkentry.GlobalAppCtx
Types ¶
type BootConfig ¶
type BootConfig struct { MySql []struct { Enabled bool `yaml:"enabled" json:"enabled"` Name string `yaml:"name" json:"name"` Description string `yaml:"description" json:"description"` Locale string `yaml:"locale" json:"locale"` User string `yaml:"user" json:"user"` Pass string `yaml:"pass" json:"pass"` Protocol string `yaml:"protocol" json:"protocol"` Addr string `yaml:"addr" json:"addr"` Database []struct { Name string `yaml:"name" json:"name"` Params []string `yaml:"params" json:"params"` DryRun bool `yaml:"dryRun" json:"dryRun"` AutoCreate bool `yaml:"autoCreate" json:"autoCreate"` } `yaml:"database" json:"database"` Logger struct { Encoding string `yaml:"encoding" json:"encoding"` Level string `yaml:"level" json:"level"` OutputPaths []string `yaml:"outputPaths" json:"outputPaths"` } } `yaml:"mySql" json:"mySql"` }
BootConfig MySql entry boot config which reflects to YAML config
type MySqlEntry ¶
type MySqlEntry struct { EntryName string `yaml:"entryName" yaml:"entryName"` EntryType string `yaml:"entryType" yaml:"entryType"` EntryDescription string `yaml:"-" json:"-"` User string `yaml:"user" json:"user"` Logger *zap.Logger `yaml:"-" json:"-"` Protocol string `yaml:"protocol" json:"protocol"` Addr string `yaml:"addr" json:"addr"` GormDbMap map[string]*gorm.DB `yaml:"-" json:"-"` GormConfigMap map[string]*gorm.Config `yaml:"-" json:"-"` // contains filtered or unexported fields }
MySqlEntry will init gorm.DB or SqlMock with provided arguments
func GetMySqlEntry ¶
func GetMySqlEntry(name string) *MySqlEntry
GetMySqlEntry returns MySqlEntry instance
func RegisterMySqlEntry ¶
func RegisterMySqlEntry(opts ...Option) *MySqlEntry
RegisterMySqlEntry will register Entry into GlobalAppCtx
func (*MySqlEntry) Bootstrap ¶
func (entry *MySqlEntry) Bootstrap(ctx context.Context)
Bootstrap MySqlEntry
func (*MySqlEntry) GetDescription ¶
func (entry *MySqlEntry) GetDescription() string
GetDescription returns entry description
func (*MySqlEntry) Interrupt ¶
func (entry *MySqlEntry) Interrupt(ctx context.Context)
Interrupt MySqlEntry
func (*MySqlEntry) IsHealthy ¶
func (entry *MySqlEntry) IsHealthy() bool
IsHealthy checks healthy status remote provider
func (*MySqlEntry) String ¶
func (entry *MySqlEntry) String() string
String returns json marshalled string
type Option ¶
type Option func(*MySqlEntry)
DataStore will be extended in future.
func WithDatabase ¶
WithDatabase provide database
func WithDescription ¶
WithDescription provide name.
func WithLoggerEncoding ¶
WithLoggerEncoding provide console=0, json=1. json or console is supported.
func WithLoggerLevel ¶ added in v0.0.2
WithLoggerLevel provide logger level in gorm Available options are silent, error, warn, info which matches gorm.logger
func WithLoggerOutputPaths ¶
WithLoggerOutputPaths provide Logger Output Path. Multiple output path could be supported including stdout.