Documentation
¶
Index ¶
- func AvoidNilString(s *string) string
- func ConvertArrayAnyToArrayString(arr []any) []string
- func DecryptToMap(input string) (map[string]any, error)
- func EncryptMap(input map[string]any) (string, error)
- func GetCurrentTimestamp() int64
- func GetCurrentTimestampString() string
- func GetEnv[T any](key string, defaultVal ...T) T
- func GetLocalizationMessage(code LocalizationCode, strs ...any) string
- func IntToDateTime(unixTime int64) string
- func IsStringInSlice(val string, ss []string) bool
- func MaxInt32(a int32, b int32) int32
- func ReadHttpBody(response http.Response) (map[string]any, error)
- func SendHttpRequestJson(c context.Context, method string, url string, jsonBody map[string]any, ...) (*http.Response, error)
- func StringToCapital(s string) string
- func StructToMap(obj any) (map[string]any, error)
- func StructToMapEscapeEmpty(obj any) (map[string]any, error)
- func ToSnakeCase(str string) string
- func UpdateLocalizationData(jsonData []byte) error
- type EnvironmentInfo
- type LocalizationCode
- type LocalizationLanguage
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AvoidNilString ¶
AvoidNilString safely dereferences a string pointer, returning empty string if nil
func ConvertArrayAnyToArrayString ¶
ConvertArrayAnyToArrayString converts a slice of any to a slice of strings Assumes all elements in the input slice can be cast to string
func DecryptToMap ¶
DecryptToMap decrypts a base64 encoded string back to a map[string]any using AES-CBC with PKCS5 padding The decryption uses keys from environment variables CRYPTO_KEY_HEX and CRYPTO_IV_HEX
func EncryptMap ¶
EncryptMap encrypts a map[string]any into a base64 encoded string using AES-CBC with PKCS5 padding The encryption uses keys from environment variables CRYPTO_KEY_HEX and CRYPTO_IV_HEX
func GetCurrentTimestamp ¶
func GetCurrentTimestamp() int64
GetCurrentTimestamp returns the current UTC timestamp as an int64
func GetCurrentTimestampString ¶
func GetCurrentTimestampString() string
GetCurrentTimestampString returns the current UTC timestamp as a string
func GetEnv ¶
GetEnv retrieves an environment variable and converts it to the specified type T Supports bool, int, int32, int64, float32, float64, and string types If the environment variable is not set and no default value is provided, the program will exit with a fatal error
func GetLocalizationMessage ¶
func GetLocalizationMessage(code LocalizationCode, strs ...any) string
GetLocalizationMessage retrieves a localized message by code and language The language is determined by the LOCALIZATION_LANGUAGE environment variable (defaults to "en") If additional string parameters are provided, they are formatted into the message using sprintf
func IntToDateTime ¶
IntToDateTime converts a Unix timestamp to a formatted date-time string Returns the time in "2006-01-02 15:04:05" format
func IsStringInSlice ¶ added in v0.3.7
IsStringInSlice checks if a string exists in a slice of strings Returns false if the input string is empty
func ReadHttpBody ¶
ReadHttpBody reads and parses an HTTP response body as JSON into a map[string]any Automatically closes the response body when finished
func SendHttpRequestJson ¶
func SendHttpRequestJson(c context.Context, method string, url string, jsonBody map[string]any, header map[string]string) (*http.Response, error)
SendHttpRequestJson sends an HTTP request with JSON body and custom headers The jsonBody is marshaled to JSON and sent as the request body
func StringToCapital ¶
StringToCapital capitalizes the first character of a string Returns empty string if input is empty
func StructToMap ¶ added in v0.3.7
StructToMap converts any struct to a map[string]any using JSON marshaling/unmarshaling This preserves JSON tags and handles nested structures
func StructToMapEscapeEmpty ¶
StructToMapEscapeEmpty converts a struct to a map[string]any while excluding empty values Empty values include nil, empty string, and zero integer values Returns an error if the input is not a struct
func ToSnakeCase ¶ added in v0.3.5
ToSnakeCase converts CamelCase or PascalCase strings to snake_case Example: "HelloWorld" becomes "hello_world"
func UpdateLocalizationData ¶
UpdateLocalizationData updates the global localization map with new data from JSON This function is thread-safe and merges new data with existing localization data The JSON structure should be: {"language": {"code": "message"}}
Types ¶
type EnvironmentInfo ¶
type EnvironmentInfo struct {
// Env represents the current environment (e.g., "test", "prod")
Env string
// DebugMode indicates if debug mode is enabled
DebugMode bool
// IsLocal indicates if the application is running in local development mode
IsLocal bool
}
EnvironmentInfo holds application environment configuration
func GetEnvironmentInfo ¶
func GetEnvironmentInfo() EnvironmentInfo
GetEnvironmentInfo retrieves current environment configuration from environment variables Reads ENV, DEBUG, and IS_LOCAL environment variables
type LocalizationCode ¶
type LocalizationCode string
LocalizationCode represents a unique identifier for localized messages
type LocalizationLanguage ¶
type LocalizationLanguage string
LocalizationLanguage represents a language identifier for localization
const ( // English language identifier English LocalizationLanguage = "en" // Taiwanese Traditional Chinese language identifier Taiwanese LocalizationLanguage = "zh_tw" // Simplified Chinese language identifier Chinese LocalizationLanguage = "zh_cn" )
Supported localization languages
type Stack ¶ added in v0.3.0
type Stack[T any] struct { // contains filtered or unexported fields }
Stack is a generic LIFO (Last In, First Out) data structure
func (*Stack[T]) Peek ¶ added in v0.3.0
func (this *Stack[T]) Peek() *T
Peek returns a pointer to the top item on the stack without removing it Returns nil if the stack is empty