uauth/internal/serve/serve.go

40 lines
972 B
Go
Raw Normal View History

2024-10-23 17:46:15 +08:00
package serve
import (
"context"
"github.com/loveuer/nf"
"github.com/loveuer/nf/nft/log"
"uauth/internal/opt"
"uauth/internal/serve/handler"
"uauth/pkg/middleware/auth"
"uauth/tool"
2024-10-23 17:46:15 +08:00
)
func Run(ctx context.Context) error {
app := nf.New()
api := app.Group(opt.Cfg.Svc.Prefix)
api.Get("/registry/user", handler.UserRegistryPage)
api.Post("/registry/user", handler.UserRegistryAction)
api.Post("/registry/client", handler.ClientRegistry)
api.Get("/login", handler.LoginPage)
api.Post("/login", handler.LoginAction)
api.Get("/authorize", auth.New(&auth.Config{NextOnError: true}), handler.Authorize)
api.Post("/approve", auth.New(), handler.Approve)
api.Post("/token", handler.HandleToken)
api.Get("/after", auth.New(), func(c *nf.Ctx) error {
return c.SendString("hello world")
})
log.Info("Starting server on: %s", opt.Cfg.Svc.Address)
go func() {
<-ctx.Done()
_ = app.Shutdown(tool.Timeout(2))
}()
return app.Run(opt.Cfg.Svc.Address)
}