core

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 17 Imported by: 0

README

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomTimeEncoder

func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func NewGorm

func NewGorm(driver, dsn string) *gorm.DB
Example
gorm := NewGorm("sqlite", "test.db")
fmt.Printf("%T\n", gorm)
db, _ := gorm.DB()
fmt.Println(db.Ping())
Output:

*gorm.DB
<nil>

func NewRedis

func NewRedis(addr, password string, db int) *redis.Client
Example
r := NewRedis("localhost:6379", "", 0)
fmt.Printf("%T\n", r)
ping := r.Ping(context.Background())
fmt.Println(ping.Val())
fmt.Println(ping.Err())
Output:

*redis.Client
PONG
<nil>

func NewViper

func NewViper(config any, options ...ViperOption) *viper.Viper
Example
type config struct {
	Name  string `mapstructure:"name"`
	Debug bool   `mapstructure:"debug"`
}

cbyte := []byte(`
name: Example
debug: true
`)

os.Setenv("TEST_ENV", "env")
var c config
v := NewViper(&c,
	ViperReadConfig("yaml", cbyte),
	ViperSetEnvPrefix("TEST"),
)
fmt.Println(c.Name)
fmt.Println(c.Debug)
fmt.Println(v.Get("ENV"))
Output:

Example
true
env

func NewZap

func NewZap(level, directory string) *zap.Logger
Example
logger := NewZap("info", "logs")
// logger.Info("Zap Example", zap.String("Test", "test"))
sugar := logger.Sugar()
// sugar.Info("Sugar Example")
// zap.L().Info("Zap L Example")
// zap.S().Info("Zap S Example")
fmt.Printf("%T\n", logger)
fmt.Printf("%T\n", sugar)
fmt.Printf("%T\n", zap.L())
fmt.Printf("%T\n", zap.S())
Output:

*zap.Logger
*zap.SugaredLogger
*zap.Logger
*zap.SugaredLogger

Types

type ViperOption

type ViperOption func(*viper.Viper)

func ViperReadConfig

func ViperReadConfig(t string, c []byte) ViperOption

func ViperSetConfigFile

func ViperSetConfigFile(in string) ViperOption

func ViperSetEnvPrefix

func ViperSetEnvPrefix(in string) ViperOption

Jump to

Keyboard shortcuts

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