Implémenter NewApiClientFromViper()
Remplacer api.New() par api.NewApiClientFromViper() à certains endroits de serverCmd Remplacer hard-coded api protocol et host par viper où api.New() est encore utilisé
This commit is contained in:
parent
04de5cdad2
commit
d6a16a7222
2 changed files with 24 additions and 9 deletions
api
21
api/api.go
21
api/api.go
|
@ -9,6 +9,9 @@ import (
|
|||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/agecem-org/config"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
|
@ -37,6 +40,24 @@ type UploadDocumentResponseInfo struct {
|
|||
Size float64 `json:"size"`
|
||||
}
|
||||
|
||||
func NewApiClientFromViper() (*API, error) {
|
||||
var config config.Config
|
||||
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
api, err := New(config.Server.Api.Protocol, config.Server.Api.Host, config.Server.Api.Port, APIOptions{
|
||||
KeyAuth: config.Server.Api.Auth,
|
||||
Key: config.Server.Api.Key,
|
||||
})
|
||||
if err != nil {
|
||||
return api, err
|
||||
}
|
||||
|
||||
return api, nil
|
||||
}
|
||||
|
||||
func New(protocol, host string, port int, opts APIOptions) (*API, error) {
|
||||
api := API{
|
||||
Protocol: protocol,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue