fixed bad import

This commit is contained in:
2026-01-11 23:35:05 +11:00
parent 423a9ee26d
commit 3726ad738a
3 changed files with 39 additions and 24 deletions

View File

@@ -1,8 +1,8 @@
# hwsauth
# HWSAuth
[![Go Reference](https://pkg.go.dev/badge/git.haelnorr.com/h/golib/hwsauth.svg)](https://pkg.go.dev/git.haelnorr.com/h/golib/hwsauth)
JWT-based authentication middleware for the [hws](https://git.haelnorr.com/h/golib/hws) web framework.
JWT-based authentication middleware for the [HWS](https://git.haelnorr.com/h/golib/hws) web framework.
## Features
@@ -65,8 +65,9 @@ func main() {
return user, err
}
// Create HWS server
server := hws.NewServer(":8080", logger)
// Create server
serverCfg, _ := hws.ConfigFromEnv()
server, _ := hws.NewServer(serverCfg)
// Create authenticator
auth, _ := hwsauth.NewAuthenticator[User, *sql.Tx](
@@ -78,17 +79,28 @@ func main() {
errorPageFunc,
)
// Define routes
routes := []hws.Route{
{
Path: "/dashboard",
Method: hws.MethodGET,
Handler: auth.LoginReq(http.HandlerFunc(dashboardHandler)),
},
}
server.AddRoutes(routes...)
// Add authentication middleware
server.AddMiddleware(auth.Authenticate())
// Optionally ignore public paths
auth.IgnorePaths("/", "/login", "/register", "/static")
// Protect routes
protectedHandler := auth.LoginReq(http.HandlerFunc(dashboardHandler))
server.AddRoute("GET", "/dashboard", protectedHandler)
server.Start()
// Start server
ctx := context.Background()
server.Start(ctx)
<-server.Ready()
}
```