Merge pull request 'Standardiser l'utilisation de api#NewApiClientFromViper' (#110) from fix/use-api-client-from-viper into main

Reviewed-on: #110
This commit is contained in:
Victor Lacasse-Beaudoin 2023-08-19 14:24:18 -05:00
commit 588432e979
2 changed files with 4 additions and 7 deletions

View file

@ -41,6 +41,9 @@ type UploadDocumentResponseInfo struct {
Size float64 `json:"size"` Size float64 `json:"size"`
} }
// NewApiClientFromViper returns a pointer to a new API object,
// provided the configuration options are managed by
// https://git.agecem.com/agecem/agecem-org/config
func NewApiClientFromViper() (*API, error) { func NewApiClientFromViper() (*API, error) {
var config config.Config var config config.Config

View file

@ -441,13 +441,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
Message string Message string
} }
client, err := api.New(cfg.Server.Api.Protocol, cfg.Server.Api.Host, cfg.Server.Port, api.APIOptions{ client, err := api.NewApiClientFromViper()
KeyAuth: cfg.Server.Api.Auth,
Key: cfg.Server.Api.Key,
BasicAuth: cfg.Server.Admin.Auth,
Username: cfg.Server.Admin.Username,
Password: cfg.Server.Admin.Password,
})
if err != nil { if err != nil {
data.Message = fmt.Sprintf("handleAdminDocumentsUploadPOST#api.New: %s", err) data.Message = fmt.Sprintf("handleAdminDocumentsUploadPOST#api.New: %s", err)
return c.Render(http.StatusInternalServerError, "admin-upload-html", data) return c.Render(http.StatusInternalServerError, "admin-upload-html", data)