ditch dotenv
This commit is contained in:
parent
0f4045a1e2
commit
abeb9e1a6b
1 changed files with 0 additions and 36 deletions
|
|
@ -1,36 +0,0 @@
|
|||
package dotenv
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func LoadEnv() (map[string]string, error) {
|
||||
data, err := os.ReadFile(".env")
|
||||
if err != nil { return nil, err }
|
||||
|
||||
dataString := string(data)
|
||||
lines := strings.Split(dataString, "\n")
|
||||
|
||||
envars := map[string]string{}
|
||||
for _, line := range lines {
|
||||
splits := strings.Split(line, "=")
|
||||
if len(splits) < 2 { continue }
|
||||
|
||||
key := splits[0]
|
||||
value := splits[1]
|
||||
|
||||
if len(value) > 2 && value[0] == '"' && value[len(value) - 1] == '"' {
|
||||
value = value[1:len(value)-1]
|
||||
}
|
||||
|
||||
envars[key] = value
|
||||
}
|
||||
|
||||
return envars, nil
|
||||
}
|
||||
|
||||
func SafeGet(m map[string]string, k string) string {
|
||||
value, _ := m[k]
|
||||
return value
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue