59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
|
|
"git.keks.cloud/kekskurse/miniauth/pkg/userstore"
|
|
"git.keks.cloud/kekskurse/miniauth/pkg/web"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/sethvargo/go-envconfig"
|
|
)
|
|
|
|
//go:embed templates/*
|
|
var templatesFS embed.FS
|
|
|
|
func main() {
|
|
cnf := config()
|
|
router := setupRouter()
|
|
router.Run(fmt.Sprintf(":%v", cnf.Port))
|
|
}
|
|
|
|
type gloableConfig struct {
|
|
UserStoreConfig userstore.Config `env:", prefix=USERSTORE_"`
|
|
Port int `env:"PORT, default=8080"`
|
|
}
|
|
|
|
func config() gloableConfig {
|
|
var c gloableConfig
|
|
err := envconfig.Process(context.Background(), &c)
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("cant parse config")
|
|
}
|
|
return c
|
|
}
|
|
|
|
func loadTemplates() *template.Template {
|
|
tmpl, err := template.ParseFS(templatesFS, "templates/*.html")
|
|
if err != nil {
|
|
panic(err) // Handle error entsprechend
|
|
}
|
|
return tmpl
|
|
}
|
|
|
|
func setupRouter() *gin.Engine {
|
|
router := gin.Default()
|
|
router.SetHTMLTemplate(loadTemplates())
|
|
routesWeb := router.Group("/web")
|
|
|
|
webServer := web.NewWeb()
|
|
webServer.RegisterRoutes(routesWeb)
|
|
|
|
router.GET("/", func(c *gin.Context) {})
|
|
router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") })
|
|
|
|
return router
|
|
}
|