mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
Proxy: Remove dependency of godotenv. #4158
This commit is contained in:
parent
2e4014ae1c
commit
e674f8266a
3 changed files with 36 additions and 14 deletions
43
proxy/env.go
43
proxy/env.go
|
@ -5,10 +5,10 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"strings"
|
||||
|
||||
"srs-proxy/errors"
|
||||
"srs-proxy/logger"
|
||||
|
@ -16,14 +16,41 @@ import (
|
|||
|
||||
// loadEnvFile loads the environment variables from file. Note that we only use .env file.
|
||||
func loadEnvFile(ctx context.Context) error {
|
||||
if workDir, err := os.Getwd(); err != nil {
|
||||
workDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "getpwd")
|
||||
} else {
|
||||
envFile := path.Join(workDir, ".env")
|
||||
if _, err := os.Stat(envFile); err == nil {
|
||||
if err := godotenv.Load(envFile); err != nil {
|
||||
return errors.Wrapf(err, "load %v", envFile)
|
||||
}
|
||||
|
||||
envFile := path.Join(workDir, ".env")
|
||||
if _, err := os.Stat(envFile); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.Open(envFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "open %v", envFile)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "read %v", envFile)
|
||||
}
|
||||
|
||||
lines := strings.Split(strings.Replace(string(b), "\r\n", "\n", -1), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
if pos := strings.IndexByte(line, '='); pos > 0 {
|
||||
key := strings.TrimSpace(line[:pos])
|
||||
value := strings.TrimSpace(line[pos+1:])
|
||||
if v := os.Getenv(key); v != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ module srs-proxy
|
|||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
require github.com/go-redis/redis/v8 v8.11.5
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
|
|
|
@ -5,8 +5,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
|
|||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
|
|
Loading…
Reference in a new issue