Files
extrovert/routes/router.go
2024-07-08 20:16:52 -03:00

50 lines
791 B
Go

package routes
import (
"net/http"
"github.com/a-h/templ"
)
var ROUTES = []Route{
{
Pattern: "/index.html",
Static: true,
Page: IndexPage(),
Handler: IndexHandler,
},
{
Pattern: "/api/oauth/twitter",
Static: false,
Page: TwitterLogin(),
Handler: TwitterLoginHandler,
},
{
Pattern: "/robots.txt",
Static: true,
Page: RobotsTxt(),
Handler: RobotsTxtHandler,
},
{
Pattern: "/ai.txt",
Static: true,
Page: AiTxt(),
Handler: AiTxtHandler,
},
}
type RouteHandler = func(http.ResponseWriter, *http.Request)
type Route struct {
Pattern string
Static bool
Handler RouteHandler
Page templ.Component
}
func RegisterAllRoutes(routes []Route, s *http.ServeMux) {
for _, r := range routes {
s.HandleFunc(r.Pattern, r.Handler)
}
}