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 IsFieldHasSchema(valueOf reflect.Value, i int) 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 TitleCase(word string) string
- func ToSnakeCase(name string) string
- type CoMap
- 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
Constants ¶
const (
// MaxRecurDepth is the maximum recursion depth for nested environment variables.
MaxRecurDepth = 3
)
Variables ¶
This section is empty.
Functions ¶
func CreateLogger ¶
CreateLogger create logger by log file If log file directory not exist, create it
func GetFieldNames ¶
func GetTableID ¶
func GetTableID(typeOf reflect.Type) (reflect.StructField, bool)
func HasTagValue ¶
func IsFieldHasSchema ¶
IsFieldHasSchema check if field has schema tag or schema suffix
func IsTableModel ¶
func MakeDirForFile ¶
MakeDirForFile create directory for file if not exist
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 parse table name by type
func ParseTableNameByValue ¶
ParseTableNameByValue parse table name by value
func TableNameMethod ¶
TableNameMethod try to get table name from method TableNames If method TableNames is not found, return empty string
func TableNamePattern ¶
TableNamePattern is the default name patterning for mapping struct to table
func ToSnakeCase ¶
ToSnakeCase convert camelCase or PascalCase to snake_case
Types ¶
type Entry ¶ added in v0.8.4
Entry represents an environment variable entry with a key and a value.
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.
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.
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.
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.