跳过正文

Go

Zap日志包
·410 字
zap # go get -u go.uber.org/zap 初始化logger # package logs import ( "os" "github.com/natefinch/lumberjack" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func InitLogger() { // 生
Viper配置包
·66 字
viper # go get github.com/spf13/viper 封装加载配置方法 # package configs import "github.com/spf13/viper" func LoadConfig(filepath string, encoding string, config interface{}) error { vp := viper.New()
Go Sync包
·492 字
WaitGroup # type WaitGroup func (wg *WaitGroup) Add(delta int) func (wg *WaitGroup) Done() func (wg *WaitGroup) Wait() package main import ( "fmt" "sync" ) func main() { var wg sync.WaitGroup
Go Time包
·910 字
时间转换 # func Now() Time // Now returns the current local time. func Unix(sec int64, nsec int64) Time func UnixMicro(usec int64) Time // Go v1.17 func UnixMilli(msec
Singleflight源码解读
·1211 字
singleflight应用在什么场景 # singleflig
Go语言之defer
·709 字
defer的用途 # defer是在函数执行到最后时(retur
Go读取文件
·96 字
读取文件全部内容 # ioutil.ReadFile(filename string) package main import ( "fmt" "io/ioutil" ) func main(){ content, err := ioutil.ReadFile("test.txt") if err != nil { fmt.Printf("read
设计模式-单例模式
·57 字
sync.Once 实现单例模式 # package singleton import "sync" type singleton struct { // 单例对象的状态 } var ( instance *singleton once
接口跨域问题
·277 字
前端请求接口跨域 # 前端报错信息 Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight 原因及解
Grpc学习
·168 字
依赖 # protoc wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip unzip protoc-21.12-linux-x86_64.zip cd protoc-21.12-linux-x86_64 ./configure make sudo make install protoc-gen-go、p