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")
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user