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"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"git.agecem.com/agecem/bottin/v5/data"
|
"git.agecem.com/agecem/bottin/v5/data"
|
||||||
"git.agecem.com/agecem/bottin/v5/web"
|
"git.agecem.com/agecem/bottin/v5/web"
|
||||||
|
@ -53,7 +54,10 @@ var webCmd = &cobra.Command{
|
||||||
|
|
||||||
// Ping API server
|
// 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()
|
pingResult, err := apiClient.GetHealth()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,8 +88,10 @@ var webCmd = &cobra.Command{
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
|
|
||||||
e.GET("/", webhandlers.GetIndex)
|
handler := webhandlers.Handler{APIClient: apiClient}
|
||||||
e.GET("/membre/", webhandlers.GetMembre)
|
|
||||||
|
e.GET("/", handler.GetIndex)
|
||||||
|
e.GET("/membre/", handler.GetMembre)
|
||||||
|
|
||||||
// Execution
|
// Execution
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,19 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"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)
|
return c.Render(http.StatusOK, "index-html", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMembre(c echo.Context) error {
|
func (h *Handler) GetMembre(c echo.Context) error {
|
||||||
apiClient := data.NewApiClientFromViper()
|
|
||||||
|
|
||||||
membreID := c.QueryParam("membre_id")
|
membreID := c.QueryParam("membre_id")
|
||||||
|
|
||||||
membre, err := apiClient.GetMembre(membreID)
|
membre, err := h.APIClient.GetMembre(membreID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Render(http.StatusBadRequest, "index-html", struct {
|
return c.Render(http.StatusBadRequest, "index-html", struct {
|
||||||
Result string
|
Result string
|
||||||
|
|
Loading…
Reference in a new issue