调整封装

This commit is contained in:
Yun
2026-07-22 01:17:07 +08:00
parent d3786198df
commit 69f90115dc
10 changed files with 1024 additions and 107 deletions
+30 -6
View File
@@ -12,10 +12,12 @@ type options struct {
defaultSuccessCode int
defaultErrorCode int
code int
data any
message string
pagination *pagination
code int
data any
message string
pagination *Pagination
httpStatusCode int
headers map[string]string
}
var op *options = nil
@@ -62,7 +64,7 @@ func SetMessage(message string) Option {
}
}
func SetPage(page *pagination) Option {
func SetPage(page *Pagination) Option {
return func(o *options) {
o.pagination = page
}
@@ -103,7 +105,29 @@ func SetTraceId(traceId string) Option {
}
}
// trace_id如何获取
// 设置HTTP状态码
func SetHttpStatusCode(code int) Option {
return func(o *options) {
o.httpStatusCode = code
}
}
// 设置单个响应头
func SetHeader(key, value string) Option {
return func(o *options) {
if o.headers == nil {
o.headers = make(map[string]string)
}
o.headers[key] = value
}
}
// 批量设置响应头
func SetHeaders(headers map[string]string) Option {
return func(o *options) {
o.headers = headers
}
}
type Logger interface {
Info(ctx context.Context, args ...interface{})