common

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigEnv  = "GVA_CONFIG"
	ConfigFile = "etc/config.yaml"
)

Variables

View Source
var (
	DB     *gorm.DB
	CONFIG Server
	VP     *viper.Viper
	LOG    *zap.Logger
)
View Source
var (
	Discard = New(log.New(ioutil.Discard, "", log.LstdFlags), log.New(ioutil.Discard, "", log.LstdFlags), GormConfig{})
	Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), log.New(os.Stdout, "\r\n", log.LstdFlags), GormConfig{
		SlowThreshold: 200 * time.Millisecond,
		LogLevel:      logger.Warn,
		Colorful:      true,
	})
	Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}
)

Functions

func CreateDir

func CreateDir(dirs ...string) (err error)

func DBInsertOne

func DBInsertOne(bean interface{}) error

func GetWriteSyncer

func GetWriteSyncer() (zapcore.WriteSyncer, error)

func GormMysql

func GormMysql() *gorm.DB

func MysqlTables

func MysqlTables(db *gorm.DB)

func New

func New(writer Writer, gormWriter logger.Writer, config GormConfig) logger.Interface

func Parse

func Parse() error

func PathExists

func PathExists(path string) (bool, error)

func ReleaseToken

func ReleaseToken(u models.User) (string, error)

Types

type ConfigStruct

type ConfigStruct struct {
	LDAP models.LdapSection `yaml:"ldap"`
}
var Config *ConfigStruct

type Crontab

type Crontab struct {
	AliYun string `mapstructure:"aliyun" json:"aliyun" yaml:"aliyun"`
}

type CustomClaims

type CustomClaims struct {
	ID         uint
	Username   string
	NickName   string
	Role       string
	BufferTime int64
	jwt.StandardClaims
}

func ParseToken

func ParseToken(token string) (*jwt.Token, *CustomClaims, error)

type GormConfig

type GormConfig struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      logger.LogLevel
}

type GormLogger

type GormLogger struct {
	Writer

	GormConfig
	// contains filtered or unexported fields
}

func (*GormLogger) Error

func (g *GormLogger) Error(ctx context.Context, message string, data ...interface{})

func (*GormLogger) Info

func (g *GormLogger) Info(ctx context.Context, message string, data ...interface{})

func (*GormLogger) LogMode

func (g *GormLogger) LogMode(level logger.LogLevel) logger.Interface

func (*GormLogger) Printf

func (g *GormLogger) Printf(message string, data ...interface{})

func (*GormLogger) Trace

func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*GormLogger) Warn

func (g *GormLogger) Warn(ctx context.Context, message string, data ...interface{})

type Mysql

type Mysql struct {
	Path         string `mapstructure:"path" json:"path" yaml:"path"`
	Config       string `mapstructure:"config" json:"config" yaml:"config"`
	Dbname       string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
	Username     string `mapstructure:"username" json:"username" yaml:"username"`
	Password     string `mapstructure:"password" json:"password" yaml:"password"`
	MaxIdleConns int    `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
	MaxOpenConns int    `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
	LogMode      bool   `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
	LogZap       string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
}

type Redis

type Redis struct {
	Host     string `mapstructure:"host" json:"host" yaml:"host"`
	UserName string `mapstructure:"username" json:"username" yaml:"username"`
	PassWord string `mapstructure:"password" json:"password" yaml:"password"`
	DB       int    `mapstructure:"db" json:"db" yaml:"db"`
}

type Server

type Server struct {
	Zap     Zap           `mapstructure:"zap"    json:"zap" yaml:"zap"`
	Mysql   Mysql         `mapstructure:"mysql"  json:"mysql" yaml:"mysql"`
	Casbin  models.Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
	System  System        `mapstructure:"system" json:"system" yaml:"system"`
	Redis   Redis         `mapstructure:"redis"  json:"redis" yaml:"redis"`
	Crontab Crontab       `mapstructure:"crontab" json:"crontab" yaml:"crontab"`
}

type System

type System struct {
	Env    string `mapstructure:"env" json:"env" yaml:"env"`
	Addr   int    `mapstructure:"addr" json:"addr" yaml:"addr"`
	DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"`
}

type Writer

type Writer interface {
	Printf(string, ...interface{})
}

Writer log writer interface

type Zap

type Zap struct {
	Level         string `mapstructure:"level" json:"level" yaml:"level"`
	Format        string `mapstructure:"format" json:"format" yaml:"format"`
	Prefix        string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`
	Director      string `mapstructure:"director" json:"director"  yaml:"director"`
	LinkName      string `mapstructure:"link-name" json:"linkName" yaml:"link-name"`
	ShowLine      bool   `mapstructure:"show-line" json:"showLine" yaml:"showLine"`
	EncodeLevel   string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"`
	StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"`
	LogInConsole  bool   `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"`
}

Jump to

Keyboard shortcuts

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