# goenv **Repository Path**: Draco26/goenv ## Basic Information - **Project Name**: goenv - **Description**: Go语言环境变量解析库,提供简单易用的环境变量读取和类型转换功能。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-11 - **Last Updated**: 2026-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # goenv Go语言环境变量解析库,提供简单易用的环境变量读取和类型转换功能。 ## 功能特性 - 支持多种数据类型:`string`、`bool`、`int`、`int64`、`uint64`、`float64`、`complex128` - 提供默认值机制,当环境变量不存在时返回指定的默认值 - 简洁的API设计,易于使用 ## 安装 ```bash go get gitee.com/chenhonghua/goenv ``` ## 使用示例 ```go package main import ( "fmt" "gitee.com/chenhonghua/goenv" ) func main() { // 读取字符串类型环境变量 name := goenv.String("APP_NAME") fmt.Println("App Name:", name) // 读取字符串类型环境变量,带默认值 host := goenv.StringVal("DB_HOST", "localhost") fmt.Println("DB Host:", host) // 读取整数类型环境变量 port := goenv.Int("APP_PORT") fmt.Println("App Port:", port) // 读取整数类型环境变量,带默认值 timeout := goenv.IntVal("TIMEOUT", 30) fmt.Println("Timeout:", timeout) // 读取布尔类型环境变量 debug := goenv.Bool("DEBUG") fmt.Println("Debug Mode:", debug) // 读取布尔类型环境变量,带默认值 enabled := goenv.BoolVal("FEATURE_ENABLED", true) fmt.Println("Feature Enabled:", enabled) // 读取浮点数类型环境变量 ratio := goenv.Float64("RATIO") fmt.Println("Ratio:", ratio) // 读取64位整数类型环境变量 maxSize := goenv.Int64("MAX_SIZE") fmt.Println("Max Size:", maxSize) } ``` ## API 参考 ### 字符串类型 | 函数 | 说明 | |------|------| | `String(envName string) string` | 读取环境变量,不存在返回空字符串 | | `StringVal(envName, defaultValue string) string` | 读取环境变量,不存在返回默认值 | ### 布尔类型 | 函数 | 说明 | |------|------| | `Bool(envName string) bool` | 读取环境变量,不存在返回 `false` | | `BoolVal(envName string, defaultValue bool) bool` | 读取环境变量,不存在返回默认值 | ### 整数类型 | 函数 | 说明 | |------|------| | `Int(envName string) int` | 读取环境变量,不存在返回 `0` | | `IntVal(envName string, defaultValue int) int` | 读取环境变量,不存在返回默认值 | | `Int64(envName string) int64` | 读取环境变量,不存在返回 `0` | | `Int64Val(envName string, defaultValue int64) int64` | 读取环境变量,不存在返回默认值 | | `Uint64(envName string) uint64` | 读取环境变量,不存在返回 `0` | | `Uint64Val(envName string, defaultValue uint64) uint64` | 读取环境变量,不存在返回默认值 | ### 浮点数类型 | 函数 | 说明 | |------|------| | `Float64(envName string) float64` | 读取环境变量,不存在返回 `0.0` | | `Float64Val(envName string, defaultValue float64) float64` | 读取环境变量,不存在返回默认值 | ### 复数类型 | 函数 | 说明 | |------|------| | `Complex128(envName string) complex128` | 读取环境变量,不存在返回 `0+0i` | | `Complex128Val(envName string, defaultValue complex128) complex128` | 读取环境变量,不存在返回默认值 | ## 许可证 MIT License