Documentation
¶
Overview ¶
Package utils provides utility functions for internal use.
This file was generated by setup_project.sh script.
Index ¶
- Constants
- Variables
- func Clamp[T constraints.Ordered](v, x, y T) T
- func Env() string
- func GinHandleError(c *gin.Context, log logrus.FieldLogger, status int, err error, msg string, ...)
- func GinMWParseID() gin.HandlerFunc
- func GinMWParseTAG() gin.HandlerFunc
- func GinMustGetTAG(c *gin.Context) (tag string)
- func ParallelBatchProcess(ctx context.Context, total int, processor BatchProcessor, opts ...Option) error
- type BatchProcessor
- type ErrorResponse
- type GinHandleErrorOption
- type Option
- type Pager
- type ParallelOptions
- type Percentage
- func (p Percentage) Clamp0100() Percentage
- func (p *Percentage) FromNormalizedFloat(v float64)
- func (p *Percentage) MarshalJSON() ([]byte, error)
- func (p Percentage) NormalizedFloat() float64
- func (p Percentage) Raw() uint8
- func (p *Percentage) Times(v float64) float64
- func (p *Percentage) UnmarshalJSON(b []byte) error
- type UInt64
Constants ¶
const ( RuntimeENVDev = "dev" RuntimeENVLocal = "local" RuntimeENVStaging = "staging" RuntimeENVProd = "prod" )
const ENVKey = "MEMORIA_NEXUS_ENV"
Variables ¶
var (
Zero = UInt64(0)
)
Functions ¶
func Clamp ¶
func Clamp[T constraints.Ordered](v, x, y T) T
func GinHandleError ¶
func GinHandleError(c *gin.Context, log logrus.FieldLogger, status int, err error, msg string, options ...GinHandleErrorOption)
GinHandleError handles errors by logging them and sending a ErrorResponse.
func GinMWParseID ¶
func GinMWParseID() gin.HandlerFunc
func GinMWParseTAG ¶
func GinMWParseTAG() gin.HandlerFunc
func GinMustGetTAG ¶
GinMustGetTAG should be used with GinMWParseID
func ParallelBatchProcess ¶
func ParallelBatchProcess(ctx context.Context, total int, processor BatchProcessor, opts ...Option) error
ParallelBatchProcess processes tasks in parallel batches with specified options.
Types ¶
type BatchProcessor ¶
BatchProcessor defines a function to process a batch of tasks.
type ErrorResponse ¶
ErrorResponse defines the standard error response structure.
type GinHandleErrorOption ¶
type GinHandleErrorOption func(*ginHandleErrorOptions)
GinHandleErrorOption defines the type for functional options.
func GinErrWithExtra ¶
func GinErrWithExtra(key string, val any) GinHandleErrorOption
GinErrWithExtra sets the requestContents option.
func GinErrWithReqBody ¶
func GinErrWithReqBody(req any) GinHandleErrorOption
GinErrWithReqBody sets the requestBody
func GinErrWithReqContents ¶
func GinErrWithReqContents(params map[string]any) GinHandleErrorOption
GinErrWithReqContents sets the requestContents option.
type Option ¶
type Option func(*ParallelOptions)
Option defines a function to set options for parallel batch processing.
func BatchWithMaxGoroutines ¶
BatchWithMaxGoroutines sets the maximum number of concurrent goroutines.
func BatchWithSize ¶
BatchWithSize sets the size for each batch.
func BatchWithTimeout ¶
BatchWithTimeout sets a timeout duration for batch processing.
type Pager ¶
type Pager struct { Offset int `json:"offset"` Limit int `json:"limit"` Total int64 `json:"total,omitempty"` }
func GinGetPagerFromQuery ¶
func (*Pager) SetFirstCount ¶
func (*Pager) SetOffsetAndLimit ¶
func (*Pager) SetPageAndLimit ¶
type ParallelOptions ¶
ParallelOptions defines options for parallel batch processing.
type Percentage ¶
type Percentage uint8
Percentage is a custom type to handle JSON serialization of percentages as uint8.
func ParsePercentageFromString ¶
func ParsePercentageFromString(value string) (Percentage, error)
ParsePercentageFromString supports parsing from a string value directly.
func Percentage100 ¶
func Percentage100() Percentage
func (Percentage) Clamp0100 ¶
func (p Percentage) Clamp0100() Percentage
func (*Percentage) FromNormalizedFloat ¶
func (p *Percentage) FromNormalizedFloat(v float64)
func (*Percentage) MarshalJSON ¶
func (p *Percentage) MarshalJSON() ([]byte, error)
MarshalJSON serializes the Percentage as a string to avoid precision loss in JavaScript.
func (Percentage) NormalizedFloat ¶
func (p Percentage) NormalizedFloat() float64
func (Percentage) Raw ¶
func (p Percentage) Raw() uint8
Raw returns the raw uint8 value of the percentage.
func (*Percentage) Times ¶
func (p *Percentage) Times(v float64) float64
func (*Percentage) UnmarshalJSON ¶
func (p *Percentage) UnmarshalJSON(b []byte) error
UnmarshalJSON supports parsing the Percentage from a number or a string in JSON.
type UInt64 ¶
type UInt64 uint64
UInt64 is a custom type to handle JSON serialization of 64-bit integers.
func GinMustGetID ¶
GinMustGetID should be used with GinMWParseID
func GinMustGetUserID ¶
func ParseIDFromString ¶
ParseIDFromString Support parsing from a string value directly.
func (*UInt64) MarshalJSON ¶
MarshalJSON serializes the UInt64 as a string to avoid precision loss in JavaScript.
func (*UInt64) UnmarshalJSON ¶
UnmarshalJSON supports parsing the UInt64 from a number or a string in JSON.