-
This commit is contained in:
parent
778f51189b
commit
3aac0570ec
23
pkg/env/parse.go
vendored
23
pkg/env/parse.go
vendored
@ -1,23 +0,0 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
envLoader "github.com/joho/godotenv"
|
||||
envParser "github.com/sethvargo/go-envconfig"
|
||||
)
|
||||
|
||||
func Parse[T interface{}](envFilePath string) (*T, error) {
|
||||
var configuration T
|
||||
|
||||
if err := envLoader.Load(envFilePath); err != nil {
|
||||
log.Printf("load local env file error: %s", err.Error())
|
||||
}
|
||||
if err := envParser.Process(context.Background(), &configuration); err != nil {
|
||||
return nil, fmt.Errorf("parsing env error: %s", err.Error())
|
||||
}
|
||||
|
||||
return &configuration, nil
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func EncodeBuffer(body interface{}) (*bytes.Buffer, error) {
|
||||
buffer := new(bytes.Buffer)
|
||||
|
||||
if err := json.NewEncoder(buffer).Encode(body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buffer, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user