35 lines
494 B
Go
35 lines
494 B
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/sethvargo/go-envconfig"
|
|
)
|
|
|
|
func secretLookuper() envconfig.LookuperFunc {
|
|
return func(key string) (string, bool) {
|
|
fileName := os.Getenv(key + "_FILE")
|
|
if fileName == "" {
|
|
return "", false
|
|
}
|
|
|
|
file, err := os.Open(fileName)
|
|
if err != nil {
|
|
return "", false
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
sb := &strings.Builder{}
|
|
|
|
_, err = io.Copy(sb, file)
|
|
if err != nil {
|
|
return "", false
|
|
}
|
|
|
|
return sb.String(), true
|
|
}
|
|
}
|