40 lines
972 B
Go
40 lines
972 B
Go
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"
|
|
)
|
|
|
|
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)
|
|
}
|