跳过正文

Go

golang base64编解码问题
·398 字
由于业务需要,go 服务需要调用 java 服务接口,其中需要对参数进行 base64 编解码
gvm管理go版本
·18 字
使用gvm管理Go版本 moovweb/gvm Go Version Manager
Go语言技巧
·693 字
Defer两阶段延迟执行 # 记录函数执行时间
Go序列化与反序列化thrift数据
·319 字
thrift IDL文件定义 # foo.thrift
使用lumberjack对gorm日志进行分割
·112 字
示例demo # package mysql import ( "log" "github.com/natefinch/lumberjack" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" ) func InitMySQL() { gormConf := &gorm.Config{ Logger: getLogger(), QueryFields: true, } dsn := "xxxxxxx" db, err := gorm.Open(mysql.Open(dsn), gormConf) //....... } func getLogger() logger.Interface { lg := logger.New(getLogWriter(), logger.Config{ SlowThreshold: 50 * time.Millisecond, Colorful: false, IgnoreRecordNotFoundError: false, LogLevel: logger.Silent, }) return lg } func getLogWriter() logger.Writer { writer := &lumberjack.Logger{ Filename: "xxx", // 日志文件地址 MaxSize: 500, // 500MB MaxBackups: 5, // 分割文件数量 MaxAge: 5, // 保存天数 Compress: false, // 是否压缩日志 } return log.New(writer, "\n", log.LstdFlags) return }
pprof分析
·606 字
服务增加 pprof 监控 # package main import( "net/http" _ "net/http/pprof" ) func main() { go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() // do something } pprof 包初始化方法里注册了相关路由地址
Sort
·1383 字
Functions # Find()-查找元素 # 该方法基于二分查找,需要被查找对象是排好序的,被查找对象升序降序需要与 cmp 方法保持一致,
Go包管理
·1727 字
GOPATH # Go 1.8 版本之前 GOPATH 默认是空的,1.8 版本之后会默认为 GOPATH 设置一个目录路径,它表示的是 Go 语言的工作目录,该目录下有三个子目录
获取图片信息
·360 字
获取远程图片信息 # image库针对远程图片使用image.Decode()方法进行解析时,会遇到无法解析图片格式的情况;
Sentinel Golang
·1702 字
限流规则 # // Strategy type TokenCalculateStrategy int32 const ( Direct TokenCalculateStrategy = iota WarmUp MemoryAdaptive ) // Rule describes the strategy of flow control, the flow control strategy is based on QPS statistic metric type Rule struct { // ID represents the unique ID of the rule (optional). ID string `json:"id,omitempty"` // Resource represents the resource name. Resource string `json:"resource"` TokenCalculateStrategy TokenCalculateStrategy `json:"tokenCalculateStrategy"` ControlBehavior ControlBehavior `json:"controlBehavior"` // Threshold means the threshold during StatIntervalInMs // If StatIntervalInMs is 1000(1 second), Threshold means QPS Threshold float64 `json:"threshold"` RelationStrategy RelationStrategy `json:"relationStrategy"` RefResource string `json:"refResource"` // MaxQueueingTimeMs only takes effect when ControlBehavior is Throttling. // When MaxQueueingTimeMs is 0, it means Throttling only controls interval of requests, // and requests exceeding the threshold will be rejected directly. MaxQueueingTimeMs uint32 `json:"maxQueueingTimeMs"` WarmUpPeriodSec uint32 `json:"warmUpPeriodSec"` WarmUpColdFactor uint32 `json:"warmUpColdFactor"` // StatIntervalInMs indicates the statistic interval and it's the optional setting for flow Rule. // If user doesn't set StatIntervalInMs, that means using default metric statistic of resource. // If the StatIntervalInMs user specifies can not reuse the global statistic of resource, // sentinel will generate independent statistic structure for this rule. StatIntervalInMs uint32 `json:"statIntervalInMs"` // adaptive flow control algorithm related parameters // limitation: LowMemUsageThreshold > HighMemUsageThreshold && MemHighWaterMarkBytes > MemLowWaterMarkBytes // if the current memory usage is less than or equals to MemLowWaterMarkBytes, threshold == LowMemUsageThreshold // if the current memory usage is more than or equals to MemHighWaterMarkBytes, threshold == HighMemUsageThreshold // if the current memory usage is in (MemLowWaterMarkBytes, MemHighWaterMarkBytes), threshold is in (HighMemUsageThreshold, LowMemUsageThreshold) LowMemUsageThreshold int64 `json:"lowMemUsageThreshold"` HighMemUsageThreshold int64 `json:"highMemUsageThreshold"` MemLowWaterMarkBytes int64 `json:"memLowWaterMarkBytes"` MemHighWaterMarkBytes int64 `json:"memHighWaterMarkBytes"` } 熔断规则 # 熔断规则