Ajouter data.NewApiClientFromViper()

This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-02 02:43:37 -04:00
parent 098d255190
commit 4673612e06

View file

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"git.agecem.com/agecem/bottin/v4/models" "git.agecem.com/agecem/bottin/v4/models"
"github.com/spf13/viper"
) )
type ApiClient struct { type ApiClient struct {
@ -18,6 +19,15 @@ type ApiClient struct {
Protocol string Protocol string
} }
func NewApiClientFromViper() *ApiClient {
apiClientKey := viper.GetString("web.api.key")
apiClientHost := viper.GetString("web.api.host")
apiClientProtocol := viper.GetString("web.api.protocol")
apiClientPort := viper.GetInt("web.api.port")
return NewApiClient(apiClientKey, apiClientHost, apiClientProtocol, apiClientPort)
}
func NewApiClient(key, host, protocol string, port int) *ApiClient { func NewApiClient(key, host, protocol string, port int) *ApiClient {
return &ApiClient{ return &ApiClient{
Key: key, Key: key,