mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
|
|
||||||
"srs-proxy/errors"
|
"srs-proxy/errors"
|
||||||
"srs-proxy/logger"
|
"srs-proxy/logger"
|
||||||
|
@ -16,14 +16,41 @@ import (
|
||||||
|
|
||||||
// loadEnvFile loads the environment variables from file. Note that we only use .env file.
|
// loadEnvFile loads the environment variables from file. Note that we only use .env file.
|
||||||
func loadEnvFile(ctx context.Context) error {
|
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")
|
return errors.Wrapf(err, "getpwd")
|
||||||
} else {
|
}
|
||||||
envFile := path.Join(workDir, ".env")
|
|
||||||
if _, err := os.Stat(envFile); err == nil {
|
envFile := path.Join(workDir, ".env")
|
||||||
if err := godotenv.Load(envFile); err != nil {
|
if _, err := os.Stat(envFile); err != nil {
|
||||||
return errors.Wrapf(err, "load %v", envFile)
|
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
|
go 1.18
|
||||||
|
|
||||||
require (
|
require github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
github.com/joho/godotenv v1.5.1
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
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/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 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
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/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue