93 lines
2 KiB
Go
93 lines
2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// Handling
|
|
func UIIndex(ctx context.Context, bottinClient *bottin.APIClient) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
type data struct {
|
|
Error string
|
|
BottinHealthResponse bottin.ReadHealthResponse
|
|
}
|
|
|
|
return c.Render(http.StatusOK, "index", func() (d data) {
|
|
if err := func() error {
|
|
select {
|
|
case <-ctx.Done():
|
|
return fmt.Errorf("Impossible de contacter le serveur: %s", ctx.Err())
|
|
default:
|
|
// Check client
|
|
if bottinClient == nil {
|
|
return fmt.Errorf("Impossible de contacter le serveur, le client API est nil")
|
|
}
|
|
|
|
// Check bottin health
|
|
bottinHealthResponse, err := bottinClient.ReadHealth(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
d.BottinHealthResponse = bottinHealthResponse
|
|
|
|
// No errors
|
|
return nil
|
|
}
|
|
}(); err != nil {
|
|
// Send error to user
|
|
d.Error = err.Error()
|
|
|
|
// Log error
|
|
log.Println("err:", d.Error)
|
|
}
|
|
return
|
|
}())
|
|
}
|
|
}
|
|
|
|
func UIReadMembre(ctx context.Context, bottinClient *bottin.APIClient) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
type data struct {
|
|
Error string
|
|
BottinMembreResponse bottin.ReadMembreResponse
|
|
}
|
|
|
|
return c.Render(http.StatusOK, "index", func() (d data) {
|
|
if err := func() error {
|
|
select {
|
|
case <-ctx.Done():
|
|
return fmt.Errorf("Impossible de contacter le serveur: %s", ctx.Err())
|
|
default:
|
|
// Check client
|
|
if bottinClient == nil {
|
|
return fmt.Errorf("Impossible de contacter le serveur, le client API est nil")
|
|
}
|
|
|
|
var err error
|
|
|
|
// Check membre
|
|
d.BottinMembreResponse, err = bottinClient.ReadMembre(ctx, c.QueryParam("m"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// No errors
|
|
return nil
|
|
}
|
|
}(); err != nil {
|
|
// Send error to user
|
|
d.Error = err.Error()
|
|
|
|
// Log error
|
|
log.Println("err:", d.Error)
|
|
}
|
|
return
|
|
}())
|
|
}
|
|
}
|