49 lines
1 KiB
Go
49 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.agecem.com/bottin/agendas/ui"
|
|
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
)
|
|
|
|
func RunServer(ctx context.Context, cfg Config, bottinClient *bottin.APIClient, dbClient *DBClient) error {
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
default:
|
|
if bottinClient == nil {
|
|
return fmt.Errorf("nil bottin client")
|
|
}
|
|
|
|
if dbClient == nil {
|
|
return fmt.Errorf("nil dbClient")
|
|
}
|
|
|
|
e := echo.New()
|
|
|
|
e.Renderer = ui.NewRenderer()
|
|
|
|
e.Pre(middleware.AddTrailingSlash())
|
|
|
|
//TODO basic auth
|
|
//TODO log successful basic auths username
|
|
|
|
e.GET("/", UIIndex(ctx, bottinClient, dbClient))
|
|
//e.GET("/transaction/", UIReadTransaction
|
|
e.POST("/transaction/", UICreateTransaction(ctx, cfg, bottinClient, dbClient))
|
|
|
|
//e.GET("/membre/", UIReadMembre(ctx, bottinClient))
|
|
|
|
address := fmt.Sprintf(":%d", cfg.Port)
|
|
|
|
if cfg.TLS.Enabled {
|
|
return e.StartTLS(address, cfg.TLS.Cert, cfg.TLS.Key)
|
|
} else {
|
|
return e.Start(address)
|
|
}
|
|
}
|
|
}
|