Documentation
¶
Index ¶
- Constants
- func CreateFileHandler(logFile string) (*os.File, error)
- func CreateLogger(logFile string) (logger *slog.Logger, err error)
- func GetElemType(valueOf reflect.Value) reflect.Type
- func GetElemValue(valueOf reflect.Value) reflect.Value
- func GetFieldNames(typeOf reflect.Type) (names []string)
- func GetTableID(typeOf reflect.Type) (reflect.StructField, bool)
- func GetTableModel(fieldOf reflect.Value) reflect.Value
- func GetTagValue(tag string, key string) (string, bool)
- func HasTagValue(tag string, key string) bool
- func IsTableModel(fieldOf reflect.Value) bool
- func MakeDirForFile(filename string) (err error)
- func ParseSchemaTag(tag string) (schema, prefix string)
- func ParseTableNameByType(typeOf reflect.Type) string
- func ParseTableNameByValue(valueOf reflect.Value) string
- func TableNameMethod(valueOf reflect.Value) string
- func TableNamePattern(name string) string
- func ToAnySlice(value any) ([]any, int)
- func ToCamelCase(s string) string
- func ToPlural(name string) string
- func ToSingular(name string) string
- func ToSnakeCase(word string) string
- func ToSnakeCaseV0(word string) string
- func ToTitleCase(word string) string
- func UniqueStrings(words []string) []string
- func WriteToFile(buf *bytes.Buffer, outputPath string) error
- type CoMap
- func (m *CoMap[K, V]) Delete(key K)
- func (m *CoMap[K, V]) Each() iter.Seq2[K, *V]
- func (m *CoMap[K, V]) Get(key K) (*V, bool)
- func (m *CoMap[K, V]) Keys() []K
- func (m *CoMap[K, V]) Set(key K, value *V)
- func (m *CoMap[K, V]) Size() int
- func (m *CoMap[K, V]) SortedKeys() []K
- func (m *CoMap[K, V]) Update(data map[K]*V)
- type Entry
- type Environ
- func (v *Environ) Get(key string) string
- func (v *Environ) GetBool(key string, fallback ...bool) bool
- func (v *Environ) GetInt(key string, fallback ...int) int
- func (v *Environ) GetInt64(key string, fallback ...int64) int64
- func (v *Environ) GetStr(key string, fallback ...string) string
- func (v *Environ) Load(reader io.ReadCloser, err error) error
- func (v *Environ) Lookup(key string) (Entry, bool)
- func (v *Environ) ScanLines(reader io.Reader) error
- type Imports
Constants ¶
const ( // MaxRecurDepth is the maximum recursion depth for nested environment variables // It limits how deeply nested environment variables can be expanded MaxRecurDepth = 3 )
Variables ¶
This section is empty.
Functions ¶
func CreateFileHandler ¶ added in v0.8.4
CreateFileHandler creates a file handler for logging It ensures the directory exists and opens the file for writing Returns the file handler or an error
func CreateLogger ¶
CreateLogger creates a logger by log file If log file directory doesn't exist, it creates it Returns the created logger or an error
func GetElemType ¶
GetElemType returns the element type of a pointer If the value is a pointer, it returns the element type Otherwise, it returns the type itself
func GetElemValue ¶
GetElemValue returns the element value of a pointer If the value is a non-nil pointer, it returns the element Otherwise, it returns the value itself
func GetFieldNames ¶
GetFieldNames returns a slice of field names for the given struct type. It only includes exported fields.
func GetTableID ¶
func GetTableID(typeOf reflect.Type) (reflect.StructField, bool)
GetTableID returns the struct field with the name "ID" in the given table model type. If no such field exists, it returns an empty StructField and false.
func GetTableModel ¶
GetTableModel returns the "Model" field of the given table model field. If the field is not a table model, or if the "Model" field does not exist, it returns an invalid reflect.Value.
func GetTagValue ¶
GetTagValue gets tag value by key It returns the value and a boolean indicating if the key was found
func HasTagValue ¶
HasTagValue checks if tag has key value It returns true if the tag contains the specified key
func IsTableModel ¶
IsTableModel checks if the given field is a table model. A table model is a struct type that has a field named "Model" of type *T.
func MakeDirForFile ¶
MakeDirForFile creates directory for file if it doesn't exist It creates all necessary parent directories Returns an error if directory creation fails
func ParseSchemaTag ¶
ParseSchemaTag parses the schema tag and returns the schema name and table prefix. Example: "public;prefix:t_" returns ("public", "t_") Example: "auth" returns ("auth", "")
func ParseTableNameByType ¶
ParseTableNameByType parses table name by type It uses the TableName method if available, otherwise uses the type name
func ParseTableNameByValue ¶
ParseTableNameByValue parses table name by value If method TableName is found, return its value Otherwise, parse table name by type name
func TableNameMethod ¶
TableNameMethod tries to get table name from method TableName If method TableName is not found, return empty string
func TableNamePattern ¶
TableNamePattern is the default name patterning for mapping struct to table It converts the name to snake_case format
func ToAnySlice ¶ added in v0.8.6
ToAnySlice converts a value to a slice of any type.
func ToCamelCase ¶ added in v0.8.6
ToCamelCase converts snake_case to CamelCase
func ToSingular ¶ added in v0.8.6
ToSingular converts a plural name to its singular form.
func ToSnakeCase ¶
ToSnakeCase converts camelCase or PascalCase to snake_case
func ToSnakeCaseV0 ¶ added in v0.8.6
ToSnakeCaseV0 converts camelCase or PascalCase to snake_case in early version of golang
func ToTitleCase ¶ added in v0.8.6
ToTitleCase converts a string to title case It capitalizes the first letter of each word
func UniqueStrings ¶ added in v0.8.6
UniqueStrings sort and unique strings in the slice.
Types ¶
type CoMap ¶
func NewCoMap ¶
NewCoMap creates a new thread-safe concurrent map It initializes the map with the specified key and value types
func NewCoMapSize ¶ added in v0.8.6
NewCoMapSize creates a new thread-safe concurrent map It initializes the map with the specified key and value types
func (*CoMap[K, V]) Delete ¶
func (m *CoMap[K, V]) Delete(key K)
Delete removes a value from the map by key It uses a write lock for thread safety
func (*CoMap[K, V]) Each ¶
Each returns an iterator over all key-value pairs in the map It uses a read lock for thread safety
func (*CoMap[K, V]) Get ¶
Get retrieves a value from the map by key It returns the value and a boolean indicating if the key was found
func (*CoMap[K, V]) Keys ¶
func (m *CoMap[K, V]) Keys() []K
Keys returns all keys in the map as a slice
func (*CoMap[K, V]) Set ¶
func (m *CoMap[K, V]) Set(key K, value *V)
Set adds or updates a value in the map
func (*CoMap[K, V]) SortedKeys ¶ added in v0.8.6
func (m *CoMap[K, V]) SortedKeys() []K
SortedKeys returns sorted keys from the map
type Entry ¶ added in v0.8.4
type Entry struct {
Key string // Environment variable key
Value string // Environment variable value
}
Entry represents an environment variable entry with a key and a value It stores a single environment variable's key-value pair
func (*Entry) Bool ¶ added in v0.8.4
Bool converts the entry's value to a boolean It supports "yes", "no", "true", and "false" as valid boolean values If the conversion fails, it returns false
func (*Entry) Int ¶ added in v0.8.4
Int converts the entry's value to an integer If the conversion fails, it returns 0
type Environ ¶ added in v0.8.4
type Environ struct {
// contains filtered or unexported fields
}
Environ represents an environment variable manager It stores environment variables in a map and supports loading from a file and the system environment
func NewEnv ¶ added in v0.8.4
func NewEnv() *Environ
NewEnv creates a new Environ instance and loads environment variables from the default .env file It initializes the environment manager with variables from the default .env file
func NewEnvWithFile ¶ added in v0.8.4
NewEnvWithFile creates a new Environ instance and loads environment variables from the specified file It initializes the storage map and attempts to Load the file If the file cannot be opened or read, the error is ignored
func (*Environ) Get ¶ added in v0.8.4
Get retrieves and expands the value of an environment variable by key It recursively expands nested environment variables up to MaxRecurDepth
func (*Environ) GetBool ¶ added in v0.8.4
GetBool retrieves the boolean value of an environment variable by key It supports "yes", "no", "true", and "false" as valid boolean values If the variable is not found or the value cannot be converted to a boolean, it returns the fallback value
func (*Environ) GetInt ¶ added in v0.8.4
GetInt retrieves the integer value of an environment variable by key If the variable is not found or the value cannot be converted to an integer, it returns the fallback value
func (*Environ) GetInt64 ¶ added in v0.8.4
GetInt64 retrieves the 64-bit integer value of an environment variable by key If the variable is not found or the value cannot be converted to a 64-bit integer, it returns the fallback value
func (*Environ) GetStr ¶ added in v0.8.4
GetStr retrieves the string value of an environment variable by key If the variable is not found, it returns the fallback value
func (*Environ) Load ¶ added in v0.8.4
func (v *Environ) Load(reader io.ReadCloser, err error) error
Load loads environment variables from a file and stores them in the internal storage It reads from the provided reader and handles closing the reader
func (*Environ) Lookup ¶ added in v0.8.4
Lookup searches for an environment variable by key It first checks the internal storage. If not found, it checks the system environment variables If the variable is found, it returns the Entry and true; otherwise, it returns an empty Entry and false If the variable is found in the system environment, it is added to the internal storage
func (*Environ) ScanLines ¶ added in v0.8.4
ScanLines reads environment variables from a reader and stores them in the internal storage It skips comments (lines starting with #) and empty lines It splits each line into key-value pairs using the first '=' character It trims whitespace from keys and values and removes surrounding quotes if present If there is an error reading the file, it returns the error
type Imports ¶ added in v0.8.6
type Imports struct {
// contains filtered or unexported fields
}
func NewImports ¶ added in v0.8.6
func NewImports() *Imports