helper

package
v0.0.0-...-807ff74 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APP = "bible"
)

Variables

View Source
var (
	InitHelper = sync.OnceValue(func() (err error) {
		if snowflakeNode, err = snowflake.NewNode(1); err != nil {
			return
		}
		envSqIDsMinLength, ok := os.LookupEnv("SQIDS_MIN_LENGTH")
		if !ok || envSqIDsMinLength == "" {
			return errors.New("env SQIDS_MIN_LENGTH requires a positive integer")
		}
		sqIDsMinLength, err := strconv.Atoi(envSqIDsMinLength)
		if err != nil {
			return
		}
		sqIDs, err = sqids.New(sqids.Options{
			Alphabet:  lowerCaseAlphanumerics,
			MinLength: min(uint8(sqIDsMinLength), math.MaxUint8),
		})
		if err != nil {
			return
		}
		location, ok := os.LookupEnv("TIME_ZONE")
		if !ok || location == "" {
			return errors.New("env TIME_ZONE is required")
		}
		timeZone, err = time.LoadLocation(location)
		return
	})
)
View Source
var (
	InitLogger = sync.OnceFunc(func() {
		encoderCfg := zap.NewProductionEncoderConfig()
		encoderCfg.TimeKey = "timestamp"
		encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
		logger = zap.Must(zap.Config{
			Level:             zap.NewAtomicLevelAt(zap.InfoLevel),
			Development:       false,
			DisableCaller:     true,
			DisableStacktrace: true,
			Sampling:          nil,
			Encoding:          "json",
			EncoderConfig:     encoderCfg,
			OutputPaths: []string{
				"stderr",
			},
			ErrorOutputPaths: []string{
				"stderr",
			},
			InitialFields: map[string]interface{}{},
		}.Build())
	})
)

Functions

func ByteSlice2String

func ByteSlice2String(bs []byte) string

func Capture

func Capture(ctx context.Context, level zapcore.Level, err error, context, scope string)

func EncodeSqIDs

func EncodeSqIDs(numbers ...uint64) (string, error)

func GenerateUniqueID

func GenerateUniqueID() (numericID int64, alphaNumericID string, err error)

func GetContext

func GetContext(ctx context.Context, c *fiber.Ctx) context.Context

func GetEnv

func GetEnv() string

func GetLogger

func GetLogger() *zap.Logger

func LoadTimeZone

func LoadTimeZone() *time.Location

func Log

func Log(ctx context.Context, level zapcore.Level, message, context, scope string)

func String2ByteSlice

func String2ByteSlice(str string) []byte

Types

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	App     string      `json:"app"`
}

func NewResponse

func NewResponse(code int, msg string, data interface{}) *Response

func (*Response) WriteResponse

func (r *Response) WriteResponse(c *fiber.Ctx) error

Jump to

Keyboard shortcuts

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