i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and Swagger annotations to English throughout the source code, generated Swagger docs, config files and CI workflows. Make the English README primary: README.md now holds the English docs and README_EN.md holds the Chinese version, with cross-language links updated accordingly. Note: the generated docs/ swagger files were translated in place; run `go generate ./...` (swag init) to regenerate them from the now-English annotations when a Go toolchain is available. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Vendored
+2
-2
@@ -10,7 +10,7 @@ type Handler interface {
|
||||
Gc() error
|
||||
}
|
||||
|
||||
// MaxTimeOut 最大超时时间
|
||||
// MaxTimeOut maximum timeout
|
||||
|
||||
const (
|
||||
TypeMem = "memory"
|
||||
@@ -49,7 +49,7 @@ func EncodeValue(value interface{}) (string, error) {
|
||||
}
|
||||
|
||||
func DecodeValue(value string, rtv interface{}) error {
|
||||
//判断rtv的类型是否是string,如果是string,直接赋值并返回
|
||||
// check whether rtv's type is string; if so, assign directly and return
|
||||
/*switch rtv.(type) {
|
||||
case *string:
|
||||
*(rtv.(*string)) = value
|
||||
|
||||
Vendored
+6
-6
@@ -42,7 +42,7 @@ func TestFileCacheSet(t *testing.T) {
|
||||
err := fc.Set("123", "ddd", 0)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ func TestFileCacheGet(t *testing.T) {
|
||||
fc := New("file")
|
||||
err := fc.Set("123", "45156", 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
res := ""
|
||||
err = fc.Get("123", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
fmt.Println("res", res)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func TestRedisCacheSet(t *testing.T) {
|
||||
err := rc.Set("123", "ddd", 0)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ func TestRedisCacheGet(t *testing.T) {
|
||||
})
|
||||
err := rc.Set("123", "451156", 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
res := ""
|
||||
err = rc.Get("123", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
fmt.Println("res", res)
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -32,12 +32,12 @@ func (c *FileCache) Get(key string, value interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取值,如果文件不存在或者过期,返回空,过滤掉错误
|
||||
// get value; if the file does not exist or has expired, return empty and ignore errors
|
||||
func (c *FileCache) getValue(key string) (string, error) {
|
||||
f := c.fileName(key)
|
||||
fileInfo, err := os.Stat(f)
|
||||
if err != nil {
|
||||
//文件不存在
|
||||
// file does not exist
|
||||
return "", nil
|
||||
}
|
||||
difT := time.Now().Sub(fileInfo.ModTime())
|
||||
@@ -52,7 +52,7 @@ func (c *FileCache) getValue(key string) (string, error) {
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// 保存值
|
||||
// save value
|
||||
func (c *FileCache) saveValue(key string, value string, exp int) error {
|
||||
f := c.fileName(key)
|
||||
lock := c.getLock(f)
|
||||
@@ -91,7 +91,7 @@ func (c *FileCache) fileName(key string) string {
|
||||
}
|
||||
|
||||
func (c *FileCache) Gc() error {
|
||||
//检查文件过期时间,并删除
|
||||
// check file expiration time and delete
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Vendored
+7
-7
@@ -11,7 +11,7 @@ func TestFileSet(t *testing.T) {
|
||||
err := fc.Set("123", "ddd", 0)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestFileGet(t *testing.T) {
|
||||
err := fc.Get("123", &res)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
fmt.Println("res", res)
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func TestFileSetGet(t *testing.T) {
|
||||
err = fc.Get("key1", &res)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
fmt.Println("res", res)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func TestFileGetJson(t *testing.T) {
|
||||
err2 := fc.Get("123", res)
|
||||
fmt.Println("res", res)
|
||||
if err2 != nil {
|
||||
t.Fatalf("读取失败" + err2.Error())
|
||||
t.Fatalf("read failed" + err2.Error())
|
||||
}
|
||||
}
|
||||
func TestFileSetGetJson(t *testing.T) {
|
||||
@@ -59,7 +59,7 @@ func TestFileSetGetJson(t *testing.T) {
|
||||
}
|
||||
err := fc.Set("123", old, 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
//old_rr.AA = "aaa"
|
||||
fmt.Println("old_rr", old)
|
||||
@@ -68,10 +68,10 @@ func TestFileSetGetJson(t *testing.T) {
|
||||
err2 := fc.Get("123", res)
|
||||
fmt.Println("res", res)
|
||||
if err2 != nil {
|
||||
t.Fatalf("读取失败" + err2.Error())
|
||||
t.Fatalf("read failed" + err2.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(res, old) {
|
||||
t.Fatalf("读取错误")
|
||||
t.Fatalf("read error")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+9
-9
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
type MemoryCache struct {
|
||||
data map[string]*CacheItem
|
||||
ll *list.List // 用于实现LRU
|
||||
pq PriorityQueue // 用于实现TTL
|
||||
ll *list.List // used to implement LRU
|
||||
pq PriorityQueue // used to implement TTL
|
||||
quit chan struct{}
|
||||
mu sync.Mutex
|
||||
maxBytes int64
|
||||
@@ -58,12 +58,12 @@ func (pq *PriorityQueue) Pop() interface{} {
|
||||
}
|
||||
|
||||
func (m *MemoryCache) Get(key string, value interface{}) error {
|
||||
// 使用反射将存储的值设置到传入的指针变量中
|
||||
// use reflection to set the stored value into the passed-in pointer variable
|
||||
val := reflect.ValueOf(value)
|
||||
if val.Kind() != reflect.Ptr {
|
||||
return errors.New("value must be a pointer")
|
||||
}
|
||||
//设为空值
|
||||
// set to zero value
|
||||
val.Elem().Set(reflect.Zero(val.Elem().Type()))
|
||||
|
||||
m.mu.Lock()
|
||||
@@ -78,7 +78,7 @@ func (m *MemoryCache) Get(key string, value interface{}) error {
|
||||
m.deleteItem(item)
|
||||
return nil
|
||||
}
|
||||
//移动到队列尾部
|
||||
// move to the tail of the queue
|
||||
m.ll.MoveToBack(item.ListEle)
|
||||
|
||||
err := DecodeValue(item.Value, value)
|
||||
@@ -97,11 +97,11 @@ func (m *MemoryCache) Set(key string, value interface{}, exp int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//key 所占用的内存
|
||||
// memory occupied by the key
|
||||
keyBytes := int64(len(key))
|
||||
//value所占用的内存空间大小
|
||||
// size of memory occupied by the value
|
||||
valueBytes := int64(len(v))
|
||||
//判断是否超过最大内存限制
|
||||
// check whether the maximum memory limit is exceeded
|
||||
if m.maxBytes != 0 && m.maxBytes < keyBytes+valueBytes {
|
||||
return errors.New("exceed maxBytes")
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func (m *MemoryCache) startEviction() {
|
||||
}()
|
||||
}
|
||||
|
||||
// stopEviction 停止定时清理
|
||||
// stopEviction stops the scheduled cleanup
|
||||
func (m *MemoryCache) stopEviction() {
|
||||
close(m.quit)
|
||||
}
|
||||
|
||||
Vendored
+14
-14
@@ -11,7 +11,7 @@ func TestMemorySet(t *testing.T) {
|
||||
err := mc.Set("123", "44567", 0)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ func TestMemoryGet(t *testing.T) {
|
||||
err := mc.Get("123", &res)
|
||||
fmt.Println("res", res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败 " + err.Error())
|
||||
t.Fatalf("read failed " + err.Error())
|
||||
}
|
||||
if res != "44567" {
|
||||
t.Fatalf("读取错误")
|
||||
t.Fatalf("read error")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,30 +37,30 @@ func TestMemorySetExpGet(t *testing.T) {
|
||||
mc.Set("2", "5", 5)
|
||||
err := mc.Set("3", "3", 3)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
|
||||
res := ""
|
||||
err = mc.Get("3", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res 3", res)
|
||||
time.Sleep(4 * time.Second)
|
||||
//res = ""
|
||||
err = mc.Get("3", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res 3", res)
|
||||
err = mc.Get("2", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res 2", res)
|
||||
err = mc.Get("1", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res 1", res)
|
||||
|
||||
@@ -69,29 +69,29 @@ func TestMemoryLru(t *testing.T) {
|
||||
mc := NewMemoryCache(18)
|
||||
mc.Set("1", "1111", 10)
|
||||
mc.Set("2", "2222", 5)
|
||||
//读取一次,2就会被放到最后
|
||||
// read once, so 2 will be moved to the end
|
||||
mc.Get("1", nil)
|
||||
err := mc.Set("3", "三", 3)
|
||||
err := mc.Set("3", "three", 3)
|
||||
if err != nil {
|
||||
//t.Fatalf("写入失败")
|
||||
//t.Fatalf("write failed")
|
||||
}
|
||||
|
||||
res := ""
|
||||
err = mc.Get("3", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res3", res)
|
||||
res = ""
|
||||
err = mc.Get("2", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res2", res)
|
||||
res = ""
|
||||
err = mc.Get("1", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败" + err.Error())
|
||||
t.Fatalf("read failed" + err.Error())
|
||||
}
|
||||
fmt.Println("res1", res)
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -17,7 +17,7 @@ func TestRedisSet(t *testing.T) {
|
||||
err := rc.Set("123", "ddd", 0)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ func TestRedisGet(t *testing.T) {
|
||||
})
|
||||
err := rc.Set("123", "451156", 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
res := ""
|
||||
err = rc.Get("123", &res)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
fmt.Println("res", res)
|
||||
}
|
||||
@@ -54,16 +54,16 @@ func TestRedisGetJson(t *testing.T) {
|
||||
}
|
||||
err := rc.Set("1233", old, 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
|
||||
res := &r{}
|
||||
err2 := rc.Get("1233", res)
|
||||
if err2 != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
if !reflect.DeepEqual(res, old) {
|
||||
t.Fatalf("读取错误")
|
||||
t.Fatalf("read error")
|
||||
}
|
||||
fmt.Println(res, res.Aa)
|
||||
}
|
||||
|
||||
Vendored
+5
-5
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 此处实现了一个简单的缓存,用于测试
|
||||
// implements a simple cache used for testing
|
||||
// SimpleCache is a simple cache implementation
|
||||
type SimpleCache struct {
|
||||
data map[string]interface{}
|
||||
@@ -19,21 +19,21 @@ func (s *SimpleCache) Get(key string, value interface{}) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
// 使用反射将存储的值设置到传入的指针变量中
|
||||
// use reflection to set the stored value into the passed-in pointer variable
|
||||
val := reflect.ValueOf(value)
|
||||
if val.Kind() != reflect.Ptr {
|
||||
return errors.New("value must be a pointer")
|
||||
}
|
||||
v, ok := s.data[key]
|
||||
if !ok {
|
||||
//设为空值
|
||||
// set to zero value
|
||||
val.Elem().Set(reflect.Zero(val.Elem().Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
vval := reflect.ValueOf(v)
|
||||
if val.Elem().Type() != vval.Type() {
|
||||
//设为空值
|
||||
// set to zero value
|
||||
val.Elem().Set(reflect.Zero(val.Elem().Type()))
|
||||
return nil
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (s *SimpleCache) Get(key string, value interface{}) error {
|
||||
func (s *SimpleCache) Set(key string, value interface{}, exp int) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
// 检查传入的值是否是指针,如果是则取其值
|
||||
// check whether the passed-in value is a pointer; if so, dereference it
|
||||
val := reflect.ValueOf(value)
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val = val.Elem()
|
||||
|
||||
Vendored
+11
-11
@@ -9,11 +9,11 @@ func TestSimpleCache_Set(t *testing.T) {
|
||||
s := NewSimpleCache()
|
||||
err := s.Set("key", "value", 0)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
err = s.Set("key", 111, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestSimpleCache_Get(t *testing.T) {
|
||||
err = s.Get("key", &value)
|
||||
fmt.Println("value", value)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
|
||||
err = s.Set("key1", 11, 0)
|
||||
@@ -32,7 +32,7 @@ func TestSimpleCache_Get(t *testing.T) {
|
||||
err = s.Get("key1", &value1)
|
||||
fmt.Println("value1", value1)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
|
||||
err = s.Set("key2", []byte{'a', 'b'}, 0)
|
||||
@@ -40,7 +40,7 @@ func TestSimpleCache_Get(t *testing.T) {
|
||||
err = s.Get("key2", &value2)
|
||||
fmt.Println("value2", string(value2))
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
|
||||
err = s.Set("key3", 33.33, 0)
|
||||
@@ -48,7 +48,7 @@ func TestSimpleCache_Get(t *testing.T) {
|
||||
err = s.Get("key3", &value3)
|
||||
fmt.Println("value3", value3)
|
||||
if err != nil {
|
||||
t.Fatalf("读取失败")
|
||||
t.Fatalf("read failed")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,18 +80,18 @@ func TestSimpleCache_GetStruct(t *testing.T) {
|
||||
}
|
||||
err := s.Set("key", old, 300)
|
||||
if err != nil {
|
||||
t.Fatalf("写入失败")
|
||||
t.Fatalf("write failed")
|
||||
}
|
||||
|
||||
res := &r{}
|
||||
err2 := s.Get("key", res)
|
||||
fmt.Println("res", res)
|
||||
if err2 != nil {
|
||||
t.Fatalf("读取失败" + err2.Error())
|
||||
t.Fatalf("read failed" + err2.Error())
|
||||
|
||||
}
|
||||
|
||||
//修改原始值,看后面是否会变化
|
||||
// modify the original value to see whether it changes afterward
|
||||
old.A = "aa"
|
||||
old_rr.AA = "aaa"
|
||||
fmt.Println("old", old)
|
||||
@@ -99,10 +99,10 @@ func TestSimpleCache_GetStruct(t *testing.T) {
|
||||
err3 := s.Get("key", res2)
|
||||
fmt.Println("res2", res2, res2.R.AA, res2.R.BB)
|
||||
if err3 != nil {
|
||||
t.Fatalf("读取失败" + err3.Error())
|
||||
t.Fatalf("read failed" + err3.Error())
|
||||
|
||||
}
|
||||
//if reflect.DeepEqual(res, old) {
|
||||
// t.Fatalf("读取错误")
|
||||
// t.Fatalf("read error")
|
||||
//}
|
||||
}
|
||||
|
||||
+6
-6
@@ -34,30 +34,30 @@ Hj4yO4j5LOWDMTgDcLsZTxbGiTzkNc/HghrNIevDAQdgjJQNl84zDjyyCA4r/MA7
|
||||
bYJTtYj8q6J0EDbRdT9b6hMclyzjNXdx2loJxR0R8WUeL1lDEPq8
|
||||
-----END RSA PRIVATE KEY-----`
|
||||
|
||||
// 测试token生成
|
||||
// test token generation
|
||||
func TestGenerateToken(t *testing.T) {
|
||||
jwtService := NewJwt(pk, time.Second*1000)
|
||||
token := jwtService.GenerateToken(1)
|
||||
if token == "" {
|
||||
t.Fatal("token生成失败")
|
||||
t.Fatal("token generation failed")
|
||||
}
|
||||
fmt.Println(pk, token)
|
||||
}
|
||||
|
||||
// 测试token解析
|
||||
// test token parsing
|
||||
func TestParseToken(t *testing.T) {
|
||||
jwtService := NewJwt(pk, time.Second*1000)
|
||||
token := jwtService.GenerateToken(999)
|
||||
if token == "" {
|
||||
t.Fatal("token生成失败")
|
||||
t.Fatal("token generation failed")
|
||||
}
|
||||
uid, err := jwtService.ParseToken(token)
|
||||
if err != nil {
|
||||
|
||||
t.Fatal("token解析失败", err)
|
||||
t.Fatal("token parsing failed", err)
|
||||
}
|
||||
if uid != 999 {
|
||||
t.Fatal("token解析失败")
|
||||
t.Fatal("token parsing failed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ func New(c *Config) *log.Logger {
|
||||
//FieldsOrder: []string{"name", "age"},
|
||||
})
|
||||
|
||||
// 日志文件
|
||||
// log file
|
||||
f := c.Path
|
||||
var write io.Writer
|
||||
if f != "" {
|
||||
|
||||
+7
-7
@@ -17,11 +17,11 @@ type MysqlConfig struct {
|
||||
func NewMysql(mysqlConf *MysqlConfig, logwriter logger.Writer) *gorm.DB {
|
||||
db, err := gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: mysqlConf.Dsn, // DSN data source name
|
||||
DefaultStringSize: 256, // string 类型字段的默认长度
|
||||
//DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||
//DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||
//DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||
//SkipInitializeWithVersion: false, // 根据当前 MySQL 版本自动配置
|
||||
DefaultStringSize: 256, // default length for string type fields
|
||||
//DisableDatetimePrecision: true, // disable datetime precision; not supported by databases before MySQL 5.6
|
||||
//DontSupportRenameIndex: true, // rename indexes by dropping and recreating them; databases before MySQL 5.7 and MariaDB do not support renaming indexes
|
||||
//DontSupportRenameColumn: true, // rename columns using `change`; databases before MySQL 8 and MariaDB do not support renaming columns
|
||||
//SkipInitializeWithVersion: false, // auto-configure based on the current MySQL version
|
||||
}), &gorm.Config{
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
Logger: logger.New(
|
||||
@@ -42,10 +42,10 @@ func NewMysql(mysqlConf *MysqlConfig, logwriter logger.Writer) *gorm.DB {
|
||||
if err2 != nil {
|
||||
fmt.Println(err2)
|
||||
}
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool
|
||||
sqlDB.SetMaxIdleConns(mysqlConf.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
// SetMaxOpenConns sets the maximum number of open database connections.
|
||||
sqlDB.SetMaxOpenConns(mysqlConf.MaxOpenConns)
|
||||
|
||||
return db
|
||||
|
||||
@@ -35,10 +35,10 @@ func NewPostgresql(conf *PostgresqlConfig, logwriter logger.Writer) *gorm.DB {
|
||||
if err2 != nil {
|
||||
fmt.Println(err2)
|
||||
}
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool
|
||||
sqlDB.SetMaxIdleConns(conf.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
// SetMaxOpenConns sets the maximum number of open database connections.
|
||||
sqlDB.SetMaxOpenConns(conf.MaxOpenConns)
|
||||
|
||||
return db
|
||||
|
||||
+2
-2
@@ -34,10 +34,10 @@ func NewSqlite(sqliteConf *SqliteConfig, logwriter logger.Writer) *gorm.DB {
|
||||
if err2 != nil {
|
||||
fmt.Println(err2)
|
||||
}
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool
|
||||
sqlDB.SetMaxIdleConns(sqliteConf.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
// SetMaxOpenConns sets the maximum number of open database connections.
|
||||
sqlDB.SetMaxOpenConns(sqliteConf.MaxOpenConns)
|
||||
|
||||
return db
|
||||
|
||||
+5
-5
@@ -240,11 +240,11 @@ func getMD5FromNewAuthString(r *http.Request) ([]byte, error) {
|
||||
}
|
||||
|
||||
/* VerifySignature
|
||||
* VerifySignature需要三个重要的数据信息来进行签名验证: 1>获取公钥PublicKey; 2>生成新的MD5鉴权串; 3>解码Request携带的鉴权串;
|
||||
* 1>获取公钥PublicKey : 从RequestHeader的"x-oss-pub-key-url"字段中获取 URL, 读取URL链接的包含的公钥内容, 进行解码解析, 将其作为rsa.VerifyPKCS1v15的入参。
|
||||
* 2>生成新的MD5鉴权串 : 把Request中的url中的path部分进行urldecode, 加上url的query部分, 再加上body, 组合之后进行MD5编码, 得到MD5鉴权字节串。
|
||||
* 3>解码Request携带的鉴权串 : 获取RequestHeader的"authorization"字段, 对其进行Base64解码,作为签名验证的鉴权对比串。
|
||||
* rsa.VerifyPKCS1v15进行签名验证,返回验证结果。
|
||||
* VerifySignature needs three pieces of data to perform signature verification: 1> obtain the public key PublicKey; 2> generate a new MD5 authentication string; 3> decode the authentication string carried by the Request;
|
||||
* 1> obtain the public key PublicKey: get the URL from the "x-oss-pub-key-url" field of the RequestHeader, read the public key content the URL points to, decode and parse it, and use it as the input parameter of rsa.VerifyPKCS1v15.
|
||||
* 2> generate a new MD5 authentication string: urldecode the path part of the url in the Request, append the query part of the url, then append the body, combine them and apply MD5 encoding to obtain the MD5 authentication byte string.
|
||||
* 3> decode the authentication string carried by the Request: get the "authorization" field of the RequestHeader and Base64-decode it to use as the comparison authentication string for signature verification.
|
||||
* rsa.VerifyPKCS1v15 performs the signature verification and returns the result.
|
||||
* */
|
||||
func verifySignature(bytePublicKey []byte, byteMd5 []byte, authorization []byte) bool {
|
||||
pubBlock, _ := pem.Decode(bytePublicKey)
|
||||
|
||||
Reference in New Issue
Block a user