Merge pull request 'Fix client web démarre sans API server accessible' (#5) from fix/web-without-api into main
Reviewed-on: #5
This commit is contained in:
commit
fa71f729f2
2 changed files with 50 additions and 6 deletions
|
@ -6,7 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.agecem.com/agecem/bottin/v4/data"
|
||||||
"git.agecem.com/agecem/bottin/v4/web"
|
"git.agecem.com/agecem/bottin/v4/web"
|
||||||
"git.agecem.com/agecem/bottin/v4/web/webhandlers"
|
"git.agecem.com/agecem/bottin/v4/web/webhandlers"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
@ -16,12 +18,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
webUser string
|
webUser string
|
||||||
webPassword string
|
webPassword string
|
||||||
webPort int
|
webPort int
|
||||||
webApiHost string
|
webApiHost string
|
||||||
webApiKey string
|
webApiKey string
|
||||||
webApiPort int
|
webApiPort int
|
||||||
|
webApiProtocol string
|
||||||
)
|
)
|
||||||
|
|
||||||
var templatesFS embed.FS
|
var templatesFS embed.FS
|
||||||
|
@ -43,10 +46,22 @@ var webCmd = &cobra.Command{
|
||||||
webApiHost = viper.GetString("web.api.host")
|
webApiHost = viper.GetString("web.api.host")
|
||||||
webApiKey = viper.GetString("web.api.key")
|
webApiKey = viper.GetString("web.api.key")
|
||||||
webApiPort = viper.GetInt("web.api.port")
|
webApiPort = viper.GetInt("web.api.port")
|
||||||
|
webApiProtocol = viper.GetString("web.api.protocol")
|
||||||
webPassword = viper.GetString("web.password")
|
webPassword = viper.GetString("web.password")
|
||||||
webPort = viper.GetInt("web.port")
|
webPort = viper.GetInt("web.port")
|
||||||
webUser = viper.GetString("web.user")
|
webUser = viper.GetString("web.user")
|
||||||
|
|
||||||
|
// Ping API server
|
||||||
|
|
||||||
|
apiClient := data.NewApiClient(webApiKey, webApiHost, webApiProtocol, webApiPort)
|
||||||
|
|
||||||
|
pingResult, err := apiClient.GetV4()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(pingResult)
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// Middlewares
|
// Middlewares
|
||||||
|
|
|
@ -69,6 +69,35 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetV4 allows checking for API v4 server health
|
||||||
|
func (a *ApiClient) GetV4() (string, error) {
|
||||||
|
var getV4Response struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := a.Call(http.MethodGet, "/v4", nil, true)
|
||||||
|
if err != nil {
|
||||||
|
return getV4Response.Message, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return getV4Response.Message, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(body, &getV4Response); err != nil {
|
||||||
|
return getV4Response.Message, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if getV4Response.Message == "" {
|
||||||
|
return getV4Response.Message, errors.New("Could not confirm that API server is up, no response message")
|
||||||
|
}
|
||||||
|
|
||||||
|
return getV4Response.Message, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) {
|
func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) {
|
||||||
var getMembreResponse struct {
|
var getMembreResponse struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
|
Loading…
Reference in a new issue