Migrate webclient to voki and add webhandlers.Handler
This commit is contained in:
parent
6dff76d871
commit
ad83bc081a
2 changed files with 16 additions and 7 deletions
12
cmd/web.go
12
cmd/web.go
|
@ -7,6 +7,7 @@ import (
|
|||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin/v5/data"
|
||||
"git.agecem.com/agecem/bottin/v5/web"
|
||||
|
@ -53,7 +54,10 @@ var webCmd = &cobra.Command{
|
|||
|
||||
// Ping API server
|
||||
|
||||
apiClient := data.NewApiClient(webApiKey, webApiHost, webApiProtocol, webApiPort)
|
||||
client := http.DefaultClient
|
||||
defer client.CloseIdleConnections()
|
||||
|
||||
apiClient := data.NewApiClient(client, webApiKey, webApiHost, webApiProtocol, webApiPort)
|
||||
|
||||
pingResult, err := apiClient.GetHealth()
|
||||
if err != nil {
|
||||
|
@ -84,8 +88,10 @@ var webCmd = &cobra.Command{
|
|||
|
||||
// Routes
|
||||
|
||||
e.GET("/", webhandlers.GetIndex)
|
||||
e.GET("/membre/", webhandlers.GetMembre)
|
||||
handler := webhandlers.Handler{APIClient: apiClient}
|
||||
|
||||
e.GET("/", handler.GetIndex)
|
||||
e.GET("/membre/", handler.GetMembre)
|
||||
|
||||
// Execution
|
||||
|
||||
|
|
|
@ -8,16 +8,19 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GetIndex(c echo.Context) error {
|
||||
type Handler struct {
|
||||
APIClient *data.ApiClient
|
||||
}
|
||||
|
||||
func (h *Handler) GetIndex(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "index-html", nil)
|
||||
}
|
||||
|
||||
func GetMembre(c echo.Context) error {
|
||||
apiClient := data.NewApiClientFromViper()
|
||||
func (h *Handler) GetMembre(c echo.Context) error {
|
||||
|
||||
membreID := c.QueryParam("membre_id")
|
||||
|
||||
membre, err := apiClient.GetMembre(membreID)
|
||||
membre, err := h.APIClient.GetMembre(membreID)
|
||||
if err != nil {
|
||||
return c.Render(http.StatusBadRequest, "index-html", struct {
|
||||
Result string
|
||||
|
|
Reference in a new issue