Files
bl/common/serialize/go-jsonrpc/method_formatter.go
昔念 83ecb90baf refactor(project): 重构项目并更新依赖
- 更新 README.md 中的项目结构说明
- 添加 pprof 性能分析工具的使用说明
- 更新 build.bat 文件,增加 proto 文件编译命令
- 升级 go-logr/logr 依赖至 v1.3.0
- 降级 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc 依赖至 v1.16.0
- 降级 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp 依赖至 v1.16.0
- 升级 go.opentelemetry.io/otel/trace 依赖至 v1.20.0
- 移除 logic/main.go 中的冗余代码
- 重构 logic/server.go 中的 Start 函数
- 更新 login/main.go 文件
2025-07-06 17:05:10 +08:00

39 lines
1.2 KiB
Go

package jsonrpc
import "strings"
// MethodNameFormatter is a function that takes a namespace and a method name and returns the full method name, sent via JSON-RPC.
// This is useful if you want to customize the default behaviour, e.g. send without the namespace or make it lowercase.
type MethodNameFormatter func(namespace, method string) string
// CaseStyle represents the case style for method names.
type CaseStyle int
const (
OriginalCase CaseStyle = iota
LowerFirstCharCase
AllFirstCharCase
)
// NewMethodNameFormatter creates a new method name formatter based on the provided options.
func NewMethodNameFormatter(includeNamespace bool, nameCase CaseStyle) MethodNameFormatter {
return func(namespace, method string) string {
formattedMethod := method
if nameCase == LowerFirstCharCase && len(method) > 0 {
formattedMethod = strings.ToLower(method[:1]) + method[1:]
}
if nameCase == AllFirstCharCase {
return strings.ToLower(namespace + "." + formattedMethod)
}
if includeNamespace {
return namespace + "." + formattedMethod
}
return formattedMethod
}
}
// DefaultMethodNameFormatter is a pass-through formatter with default options.
var DefaultMethodNameFormatter = NewMethodNameFormatter(false, OriginalCase)