mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 08:50:00 +08:00
Compare commits
9 Commits
copilot/fi
...
tools/goct
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c320b46e | ||
|
|
bea9d150a1 | ||
|
|
3f756a2cbf | ||
|
|
bbe5bbb0c0 | ||
|
|
5ad2278a69 | ||
|
|
77763fe748 | ||
|
|
538c4fb5c7 | ||
|
|
315fb2fe0a | ||
|
|
e382887eb8 |
@@ -259,12 +259,34 @@ func (s *Redis) BitPosCtx(ctx context.Context, key string, bit, start, end int64
|
||||
}
|
||||
|
||||
// Blpop uses passed in redis connection to execute blocking queries.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode to avoid
|
||||
// exhausting the connection pool. Blocking commands hold connections for extended periods and should
|
||||
// not share the regular connection pool.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// node, err := redis.CreateBlockingNode(rds)
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
// defer node.Close()
|
||||
//
|
||||
// value, err := rds.Blpop(node, "mylist")
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
//
|
||||
// Doesn't benefit from pooling redis connections of blocking queries
|
||||
func (s *Redis) Blpop(node RedisNode, key string) (string, error) {
|
||||
return s.BlpopCtx(context.Background(), node, key)
|
||||
}
|
||||
|
||||
// BlpopCtx uses passed in redis connection to execute blocking queries.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode.
|
||||
// See Blpop for usage examples.
|
||||
//
|
||||
// Doesn't benefit from pooling redis connections of blocking queries
|
||||
func (s *Redis) BlpopCtx(ctx context.Context, node RedisNode, key string) (string, error) {
|
||||
return s.BlpopWithTimeoutCtx(ctx, node, blockingQueryTimeout, key)
|
||||
@@ -272,12 +294,18 @@ func (s *Redis) BlpopCtx(ctx context.Context, node RedisNode, key string) (strin
|
||||
|
||||
// BlpopEx uses passed in redis connection to execute blpop command.
|
||||
// The difference against Blpop is that this method returns a bool to indicate success.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode.
|
||||
// See Blpop for usage examples.
|
||||
func (s *Redis) BlpopEx(node RedisNode, key string) (string, bool, error) {
|
||||
return s.BlpopExCtx(context.Background(), node, key)
|
||||
}
|
||||
|
||||
// BlpopExCtx uses passed in redis connection to execute blpop command.
|
||||
// The difference against Blpop is that this method returns a bool to indicate success.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode.
|
||||
// See Blpop for usage examples.
|
||||
func (s *Redis) BlpopExCtx(ctx context.Context, node RedisNode, key string) (string, bool, error) {
|
||||
if node == nil {
|
||||
return "", false, ErrNilNode
|
||||
@@ -297,12 +325,18 @@ func (s *Redis) BlpopExCtx(ctx context.Context, node RedisNode, key string) (str
|
||||
|
||||
// BlpopWithTimeout uses passed in redis connection to execute blpop command.
|
||||
// Control blocking query timeout
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode.
|
||||
// See Blpop for usage examples.
|
||||
func (s *Redis) BlpopWithTimeout(node RedisNode, timeout time.Duration, key string) (string, error) {
|
||||
return s.BlpopWithTimeoutCtx(context.Background(), node, timeout, key)
|
||||
}
|
||||
|
||||
// BlpopWithTimeoutCtx uses passed in redis connection to execute blpop command.
|
||||
// Control blocking query timeout
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode.
|
||||
// See Blpop for usage examples.
|
||||
func (s *Redis) BlpopWithTimeoutCtx(ctx context.Context, node RedisNode, timeout time.Duration,
|
||||
key string) (string, error) {
|
||||
if node == nil {
|
||||
@@ -1840,6 +1874,29 @@ func (s *Redis) XInfoStreamCtx(ctx context.Context, stream string) (*red.XInfoSt
|
||||
|
||||
// XReadGroup reads messages from Redis streams as part of a consumer group.
|
||||
// It allows for distributed processing of stream messages with automatic message delivery semantics.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode to avoid
|
||||
// exhausting the connection pool. Blocking commands hold connections for extended periods and should
|
||||
// not share the regular connection pool.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// node, err := redis.CreateBlockingNode(rds)
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
// defer node.Close()
|
||||
//
|
||||
// streams, err := rds.XReadGroup(
|
||||
// node, // RedisNode created with CreateBlockingNode
|
||||
// "mygroup", // consumer group name
|
||||
// "consumer1", // consumer ID
|
||||
// 10, // max number of messages to read
|
||||
// 5*time.Second, // block duration
|
||||
// false, // noAck flag
|
||||
// "mystream", // stream name
|
||||
// )
|
||||
//
|
||||
// Doesn't benefit from pooling redis connections of blocking queries.
|
||||
func (s *Redis) XReadGroup(node RedisNode, group string, consumerId string, count int64,
|
||||
block time.Duration, noAck bool, streams ...string) ([]red.XStream, error) {
|
||||
@@ -1847,6 +1904,10 @@ func (s *Redis) XReadGroup(node RedisNode, group string, consumerId string, coun
|
||||
}
|
||||
|
||||
// XReadGroupCtx is the context-aware version of XReadGroup.
|
||||
//
|
||||
// For blocking operations, you must create a dedicated RedisNode using CreateBlockingNode to avoid
|
||||
// exhausting the connection pool. See XReadGroup for usage examples.
|
||||
//
|
||||
// Doesn't benefit from pooling redis connections of blocking queries.
|
||||
func (s *Redis) XReadGroupCtx(ctx context.Context, node RedisNode, group string, consumerId string,
|
||||
count int64, block time.Duration, noAck bool, streams ...string) ([]red.XStream, error) {
|
||||
|
||||
@@ -13,7 +13,37 @@ type ClosableNode interface {
|
||||
Close()
|
||||
}
|
||||
|
||||
// CreateBlockingNode returns a ClosableNode.
|
||||
// CreateBlockingNode creates a dedicated RedisNode for blocking operations.
|
||||
//
|
||||
// Blocking Redis commands (like BLPOP, BRPOP, XREADGROUP with block parameter) hold connections
|
||||
// for extended periods while waiting for data. Using them with the regular Redis connection pool
|
||||
// can exhaust all available connections, causing other operations to fail or timeout.
|
||||
//
|
||||
// CreateBlockingNode creates a separate Redis client with a minimal connection pool (size 1) that
|
||||
// is dedicated to blocking operations. This ensures blocking commands don't interfere with regular
|
||||
// Redis operations.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// rds := redis.MustNewRedis(redis.RedisConf{
|
||||
// Host: "localhost:6379",
|
||||
// Type: redis.NodeType,
|
||||
// })
|
||||
//
|
||||
// // Create a dedicated node for blocking operations
|
||||
// node, err := redis.CreateBlockingNode(rds)
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
// defer node.Close() // Important: close the node when done
|
||||
//
|
||||
// // Use the node for blocking operations
|
||||
// value, err := rds.Blpop(node, "mylist")
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
//
|
||||
// The returned ClosableNode must be closed when no longer needed to release resources.
|
||||
func CreateBlockingNode(r *Redis) (ClosableNode, error) {
|
||||
timeout := readWriteTimeout + blockingQueryTimeout
|
||||
|
||||
|
||||
4
go.mod
4
go.mod
@@ -16,12 +16,12 @@ require (
|
||||
github.com/jhump/protoreflect v1.17.0
|
||||
github.com/pelletier/go-toml/v2 v2.2.2
|
||||
github.com/prometheus/client_golang v1.21.1
|
||||
github.com/redis/go-redis/v9 v9.15.0
|
||||
github.com/redis/go-redis/v9 v9.14.0
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
go.etcd.io/etcd/api/v3 v3.5.15
|
||||
go.etcd.io/etcd/client/v3 v3.5.15
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.0
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.1
|
||||
go.opentelemetry.io/otel v1.24.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
|
||||
|
||||
8
go.sum
8
go.sum
@@ -154,8 +154,8 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ
|
||||
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/redis/go-redis/v9 v9.15.0 h1:2jdes0xJxer4h3NUZrZ4OGSntGlXp4WbXju2nOTRXto=
|
||||
github.com/redis/go-redis/v9 v9.15.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/redis/go-redis/v9 v9.14.0 h1:u4tNCjXOyzfgeLN+vAZaW1xUooqWDqVEsZN0U01jfAE=
|
||||
github.com/redis/go-redis/v9 v9.14.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
@@ -197,8 +197,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
|
||||
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
|
||||
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.0 h1:sh55yOXA2vUjW1QYw/2tRlHSQViwDyPnW61AwpZ4rtU=
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.0/go.mod h1:jHeEDJHJq7tm6ZF45Issun9dbogjfnPySb1vXA7EeAI=
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.1 h1:WrCgSzO7dh1/FrePud9dK5fKNZOE97q5EQimGkos7Wo=
|
||||
go.mongodb.org/mongo-driver/v2 v2.3.1/go.mod h1:jHeEDJHJq7tm6ZF45Issun9dbogjfnPySb1vXA7EeAI=
|
||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
|
||||
|
||||
@@ -175,7 +175,7 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
|
||||
|
||||
* API 文档
|
||||
|
||||
[https://go-zero.dev/cn/](https://go-zero.dev/cn/)
|
||||
[https://go-zero.dev](https://go-zero.dev)
|
||||
|
||||
* awesome 系列(更多文章见『微服务实践』公众号)
|
||||
|
||||
@@ -305,6 +305,7 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
>107. 深圳市聚货通信息科技有限公司
|
||||
>108. 浙江银盾云科技有限公司
|
||||
>109. 南京造世网络科技有限公司
|
||||
>110. 温州飞儿云信息技术有限公司
|
||||
|
||||
如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
|
||||
|
||||
|
||||
@@ -55,32 +55,29 @@ service Test {
|
||||
|
||||
// Verify SSE-specific patterns in handler
|
||||
// Handler should call: err := l.Sse(&req, client)
|
||||
assert.Contains(t, handlerStr, "err := l.Sse(&req, client)",
|
||||
assert.Contains(t, handlerStr, "err := l.Sse(&req, client)",
|
||||
"Handler should call logic with client channel parameter")
|
||||
|
||||
|
||||
// Handler should NOT have the regular pattern: resp, err := l.Sse(&req)
|
||||
assert.NotContains(t, handlerStr, "resp, err := l.Sse(&req)",
|
||||
assert.NotContains(t, handlerStr, "resp, err := l.Sse(&req)",
|
||||
"Handler should not use regular pattern with resp return")
|
||||
|
||||
// Handler should use threading.GoSafeCtx
|
||||
assert.Contains(t, handlerStr, "threading.GoSafeCtx",
|
||||
assert.Contains(t, handlerStr, "threading.GoSafeCtx",
|
||||
"Handler should use threading.GoSafeCtx for SSE")
|
||||
|
||||
// Handler should create client channel
|
||||
assert.Contains(t, handlerStr, "client := make(chan",
|
||||
assert.Contains(t, handlerStr, "client := make(chan",
|
||||
"Handler should create client channel")
|
||||
|
||||
// Verify SSE-specific patterns in logic
|
||||
// Logic should have signature: Sse(req *types.SseReq, client chan<- *types.SseResp) error
|
||||
assert.Contains(t, logicStr, "func (l *SseLogic) Sse(req *types.SseReq, client chan<- *types.SseResp) error",
|
||||
assert.Contains(t, logicStr, "func (l *SseLogic) Sse(req *types.SseReq, client chan<- *types.SseResp) error",
|
||||
"Logic should have SSE signature with client channel parameter")
|
||||
|
||||
// Logic should NOT have regular signature: Sse(req *types.SseReq) (resp *types.SseResp, err error)
|
||||
assert.NotContains(t, logicStr, "(resp *types.SseResp, err error)",
|
||||
assert.NotContains(t, logicStr, "(resp *types.SseResp, err error)",
|
||||
"Logic should not have regular signature with resp return")
|
||||
|
||||
t.Logf("Handler content:\n%s", handlerStr)
|
||||
t.Logf("Logic content:\n%s", logicStr)
|
||||
}
|
||||
|
||||
func TestNonSSEGeneration(t *testing.T) {
|
||||
@@ -126,20 +123,20 @@ service Test {
|
||||
|
||||
// Verify regular (non-SSE) patterns in handler
|
||||
// Handler should call: resp, err := l.Sse(&req)
|
||||
assert.Contains(t, handlerStr, "resp, err := l.Sse(&req)",
|
||||
assert.Contains(t, handlerStr, "resp, err := l.Sse(&req)",
|
||||
"Handler should use regular pattern with resp return")
|
||||
|
||||
// Handler should NOT have SSE pattern: err := l.Sse(&req, client)
|
||||
assert.NotContains(t, handlerStr, "err := l.Sse(&req, client)",
|
||||
assert.NotContains(t, handlerStr, "err := l.Sse(&req, client)",
|
||||
"Handler should not use SSE pattern")
|
||||
|
||||
// Handler should NOT use threading.GoSafeCtx
|
||||
assert.NotContains(t, handlerStr, "threading.GoSafeCtx",
|
||||
assert.NotContains(t, handlerStr, "threading.GoSafeCtx",
|
||||
"Handler should not use threading.GoSafeCtx for regular routes")
|
||||
|
||||
// Verify regular (non-SSE) patterns in logic
|
||||
// Logic should have signature: Sse(req *types.SseReq) (resp *types.SseResp, err error)
|
||||
assert.Contains(t, logicStr, "(resp *types.SseResp, err error)",
|
||||
assert.Contains(t, logicStr, "(resp *types.SseResp, err error)",
|
||||
"Logic should have regular signature with resp return")
|
||||
|
||||
// Logic should NOT have SSE signature with client parameter
|
||||
@@ -151,9 +148,6 @@ service Test {
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.False(t, hasSSESignature,
|
||||
assert.False(t, hasSSESignature,
|
||||
"Logic should not have SSE signature with client channel parameter")
|
||||
|
||||
t.Logf("Handler content:\n%s", handlerStr)
|
||||
t.Logf("Logic content:\n%s", logicStr)
|
||||
}
|
||||
|
||||
17
tools/goctl/api/gogen/jwt.api
Executable file
17
tools/goctl/api/gogen/jwt.api
Executable file
@@ -0,0 +1,17 @@
|
||||
type Request {
|
||||
Name string `path:"name,options=you|me"`
|
||||
}
|
||||
|
||||
type Response {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
@server(
|
||||
jwt: Auth
|
||||
jwtTransition: Trans
|
||||
middleware: TokenValidate
|
||||
)
|
||||
service A-api {
|
||||
@handler GreetHandler
|
||||
get /greet/from/:name(Request) returns (Response)
|
||||
}
|
||||
@@ -24,10 +24,15 @@ func getFirstUsableString(def ...string) string {
|
||||
}
|
||||
|
||||
for _, val := range def {
|
||||
str, err := strconv.Unquote(val)
|
||||
if err == nil && len(str) != 0 {
|
||||
// Try to unquote if it's a quoted string
|
||||
if str, err := strconv.Unquote(val); err == nil && len(str) != 0 {
|
||||
return str
|
||||
}
|
||||
|
||||
// Otherwise, use the value as-is if it's not empty
|
||||
if len(val) != 0 {
|
||||
return val
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
|
||||
@@ -89,3 +89,108 @@ func Test_getListFromInfoOrDefault(t *testing.T) {
|
||||
assert.Equal(t, []string{"query"}, getListFromInfoOrDefault(unquotedProperties, "tags", []string{"default"}))
|
||||
assert.Equal(t, []string{"default"}, getListFromInfoOrDefault(unquotedProperties, "empty", []string{"default"}))
|
||||
}
|
||||
|
||||
func Test_getFirstUsableString(t *testing.T) {
|
||||
t.Run("empty input", func(t *testing.T) {
|
||||
result := getFirstUsableString()
|
||||
assert.Equal(t, "", result, "should return empty string for no arguments")
|
||||
})
|
||||
|
||||
t.Run("single plain string", func(t *testing.T) {
|
||||
result := getFirstUsableString("Check server health status.")
|
||||
assert.Equal(t, "Check server health status.", result)
|
||||
})
|
||||
|
||||
t.Run("single quoted string", func(t *testing.T) {
|
||||
// This is how Go would represent a quoted string literal
|
||||
result := getFirstUsableString(`"Check server health status."`)
|
||||
assert.Equal(t, "Check server health status.", result, "should unquote quoted strings")
|
||||
})
|
||||
|
||||
t.Run("multiple plain strings", func(t *testing.T) {
|
||||
result := getFirstUsableString("", "second", "third")
|
||||
assert.Equal(t, "second", result, "should return first non-empty string")
|
||||
})
|
||||
|
||||
t.Run("handler name fallback", func(t *testing.T) {
|
||||
// Simulates the real use case: @doc text, handler name
|
||||
result := getFirstUsableString("", "HealthCheck")
|
||||
assert.Equal(t, "HealthCheck", result, "should fallback to handler name")
|
||||
})
|
||||
|
||||
t.Run("doc text over handler name", func(t *testing.T) {
|
||||
// Simulates the real use case with @doc text
|
||||
result := getFirstUsableString("Check server health status.", "HealthCheck")
|
||||
assert.Equal(t, "Check server health status.", result, "should use doc text over handler name")
|
||||
})
|
||||
|
||||
t.Run("empty strings before valid", func(t *testing.T) {
|
||||
result := getFirstUsableString("", "", "valid")
|
||||
assert.Equal(t, "valid", result, "should skip empty strings")
|
||||
})
|
||||
|
||||
t.Run("all empty strings", func(t *testing.T) {
|
||||
result := getFirstUsableString("", "", "")
|
||||
assert.Equal(t, "", result, "should return empty if all are empty")
|
||||
})
|
||||
|
||||
t.Run("quoted then plain", func(t *testing.T) {
|
||||
result := getFirstUsableString(`"quoted"`, "plain")
|
||||
assert.Equal(t, "quoted", result, "should unquote first quoted string")
|
||||
})
|
||||
|
||||
t.Run("plain then quoted", func(t *testing.T) {
|
||||
result := getFirstUsableString("plain", `"quoted"`)
|
||||
assert.Equal(t, "plain", result, "should use first plain string")
|
||||
})
|
||||
|
||||
t.Run("invalid quoted string", func(t *testing.T) {
|
||||
// String that looks quoted but isn't valid Go syntax
|
||||
result := getFirstUsableString(`"incomplete`, "fallback")
|
||||
assert.Equal(t, `"incomplete`, result, "should use as-is if unquote fails but not empty")
|
||||
})
|
||||
|
||||
t.Run("whitespace only", func(t *testing.T) {
|
||||
result := getFirstUsableString(" ", "fallback")
|
||||
assert.Equal(t, " ", result, "should not trim whitespace, return as-is")
|
||||
})
|
||||
|
||||
t.Run("real world API doc scenario", func(t *testing.T) {
|
||||
// This is the actual bug scenario from issue #5229
|
||||
atDocText := "Check server health status."
|
||||
handlerName := "HealthCheck"
|
||||
|
||||
result := getFirstUsableString(atDocText, handlerName)
|
||||
assert.Equal(t, "Check server health status.", result,
|
||||
"should use @doc text for API summary")
|
||||
})
|
||||
|
||||
t.Run("real world with empty doc", func(t *testing.T) {
|
||||
// When @doc is empty, should fall back to handler name
|
||||
atDocText := ""
|
||||
handlerName := "HealthCheck"
|
||||
|
||||
result := getFirstUsableString(atDocText, handlerName)
|
||||
assert.Equal(t, "HealthCheck", result,
|
||||
"should fallback to handler name when @doc is empty")
|
||||
})
|
||||
|
||||
t.Run("complex summary with special characters", func(t *testing.T) {
|
||||
result := getFirstUsableString("Get user by ID: /users/{id}")
|
||||
assert.Equal(t, "Get user by ID: /users/{id}", result,
|
||||
"should handle special characters in plain strings")
|
||||
})
|
||||
|
||||
t.Run("multiline string", func(t *testing.T) {
|
||||
result := getFirstUsableString("Line 1\nLine 2")
|
||||
assert.Equal(t, "Line 1\nLine 2", result,
|
||||
"should handle multiline strings")
|
||||
})
|
||||
|
||||
t.Run("unicode characters", func(t *testing.T) {
|
||||
result := getFirstUsableString("健康检查", "HealthCheck")
|
||||
assert.Equal(t, "健康检查", result,
|
||||
"should handle unicode characters")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ require (
|
||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
||||
github.com/zeromicro/antlr v0.0.1
|
||||
github.com/zeromicro/ddl-parser v1.0.5
|
||||
github.com/zeromicro/go-zero v1.9.1
|
||||
github.com/zeromicro/go-zero v1.9.2
|
||||
golang.org/x/text v0.22.0
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/protobuf v1.36.5
|
||||
|
||||
@@ -185,8 +185,8 @@ github.com/zeromicro/antlr v0.0.1 h1:CQpIn/dc0pUjgGQ81y98s/NGOm2Hfru2NNio2I9mQgk
|
||||
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
||||
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
||||
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||
github.com/zeromicro/go-zero v1.9.1 h1:GZCl4jun/ZgZHnSvX3SSNDHf+tEGmEQ8x2Z23xjHa9g=
|
||||
github.com/zeromicro/go-zero v1.9.1/go.mod h1:bHOl7Xr7EV/iHZWEqsUNJwFc/9WgAMrPpPagYvOaMtY=
|
||||
github.com/zeromicro/go-zero v1.9.2 h1:ZXOXBIcazZ1pWAMiHyVnDQ3Sxwy7DYPzjE89Qtj9vqM=
|
||||
github.com/zeromicro/go-zero v1.9.2/go.mod h1:k8YBMEFZKjTd4q/qO5RCW+zDgUlNyAs5vue3P4/Kmn0=
|
||||
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
||||
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildVersion is the version of goctl.
|
||||
const BuildVersion = "1.9.1"
|
||||
const BuildVersion = "1.9.2"
|
||||
|
||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-beta": 2, "beta": 3, "released": 4, "": 5}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package util
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/console"
|
||||
@@ -130,14 +129,3 @@ func FieldsAndTrimSpace(s string, f func(r rune) bool) []string {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
//Deprecated: This function implementation is incomplete and does not properly handle exceptional input cases.
|
||||
//We strongly recommend using the standard library's strconv.Unquote function instead,
|
||||
//which provides robust error handling and comprehensive support for various input formats.
|
||||
func Unquote(s string) string {
|
||||
ns, err := strconv.Unquote(s)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return ns
|
||||
}
|
||||
|
||||
@@ -76,40 +76,40 @@ func TestEscapeGoKeyword(t *testing.T) {
|
||||
|
||||
func TestFieldsAndTrimSpace(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
input string
|
||||
name string
|
||||
input string
|
||||
delimiter func(r rune) bool
|
||||
expected []string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "Comma-separated values",
|
||||
input: "a, b, c",
|
||||
name: "Comma-separated values",
|
||||
input: "a, b, c",
|
||||
delimiter: func(r rune) bool { return r == ',' },
|
||||
expected: []string{"a", " b", " c"},
|
||||
expected: []string{"a", " b", " c"},
|
||||
},
|
||||
{
|
||||
name: "Space-separated values",
|
||||
input: "a b c",
|
||||
name: "Space-separated values",
|
||||
input: "a b c",
|
||||
delimiter: unicode.IsSpace,
|
||||
expected: []string{"a", "b", "c"},
|
||||
expected: []string{"a", "b", "c"},
|
||||
},
|
||||
{
|
||||
name: "Mixed whitespace",
|
||||
input: "a\tb\nc",
|
||||
name: "Mixed whitespace",
|
||||
input: "a\tb\nc",
|
||||
delimiter: unicode.IsSpace,
|
||||
expected: []string{"a", "b", "c"},
|
||||
expected: []string{"a", "b", "c"},
|
||||
},
|
||||
{
|
||||
name: "Empty input",
|
||||
input: "",
|
||||
name: "Empty input",
|
||||
input: "",
|
||||
delimiter: unicode.IsSpace,
|
||||
expected: []string(nil),
|
||||
expected: []string(nil),
|
||||
},
|
||||
{
|
||||
name: "Trailing and leading spaces",
|
||||
input: " a , b , c ",
|
||||
name: "Trailing and leading spaces",
|
||||
input: " a , b , c ",
|
||||
delimiter: func(r rune) bool { return r == ',' },
|
||||
expected: []string{" a ", " b ", " c "},
|
||||
expected: []string{" a ", " b ", " c "},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -120,20 +120,3 @@ func TestFieldsAndTrimSpace(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnquote(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{input: `"hello"`, expected: `hello`},
|
||||
{input: "`world`", expected: `world`},
|
||||
{input: `"foo'bar"`, expected: `foo'bar`},
|
||||
{input: "", expected: ""},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
result := Unquote(tc.input)
|
||||
assert.Equal(t, tc.expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user