common

package
v0.0.0-...-0bfe986 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: Apache-2.0, BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FastestJsoniter = jsoniter.Config{
	EscapeHTML:                    false,
	UseNumber:                     true,
	MarshalFloatWith6Digits:       true,
	ObjectFieldMustBeSimpleString: true,
}.Froze()

Functions

func GetBodyReq

func GetBodyReq(r *http.Request, object interface{}) (err error)

func GetRetCodeByReflect

func GetRetCodeByReflect(res interface{}) int

func GetStartTime

func GetStartTime(ctx context.Context) time.Time

func WithStartTime

func WithStartTime(ctx context.Context, start time.Time) context.Context

func WriteAPI

func WriteAPI(c *gin.Context, data interface{})

WriteAPI writes a standard API response onto a gin.Context: HTTP 200 with the JSON envelope serialized via FastestJsoniter (NOT gin's encoding/json), so handlers stop hand-rolling c.Writer + Content-Type + status. It is the success-path write helper the cube/inner/notify handlers (and meta's success paths) go through. This is not a unified single write path: cube error responses still build the envelope inline (ret_code/ret_msg under HTTP 200), and the meta package keeps its own writeErr for error responses, some of which return HTTP 400 on a malformed body. The request trace (rt.RetCode) is still set by the caller, since some handlers record a sentinel value for metrics.

func WriteErr

func WriteErr(c *gin.Context, code int, msg string)

WriteErr is a convenience helper that writes an HTTP 200 response carrying a business error (ret_code/ret_msg) in the standard envelope, for the common case where a handler just needs to surface an error code + message. It is currently exercised by the common package's contract tests; production handlers build their error envelopes inline via WriteAPI (cube/inner/notify) or the meta package's own writeErr (which can return HTTP 400), so WriteErr is not yet on the hot path.

func WriteListAPI

func WriteListAPI(c *gin.Context, data interface{})

WriteListAPI is the list-endpoint success-path variant, routing through the bufferpool-backed list encoder (WriteListResponse); same HTTP 200 + FastestJsoniter envelope contract as WriteAPI.

func WriteListResponse

func WriteListResponse(w http.ResponseWriter, code int, data interface{})

func WriteResponse

func WriteResponse(w http.ResponseWriter, code int, data interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL