Skip to content

Commit 896ea03

Browse files
committed
apihandler updated
1 parent 864813d commit 896ea03

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

api/service.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func New(ctx context.Context, cfg *Config, nq notification.Queue) (*Service, err
7575
cancel: cancel,
7676
cfg: cfg,
7777
nq: nq,
78-
handler: apihandler.NewHandler(true, nil),
78+
handler: apihandler.NewHandler(true),
7979
}
8080
// demo stuff
8181
if cfg.DemoMode {
@@ -87,11 +87,13 @@ func New(ctx context.Context, cfg *Config, nq notification.Queue) (*Service, err
8787
}
8888
_ = srv.handler.Get(DemoInboxPath, srv.demoInboxHandler)
8989
}
90+
// create the rate limiter
91+
rl := apihandler.NewRateLimiter(internalCtx, 100, time.Minute)
9092
// register the routes and handlers
91-
_ = srv.handler.Post(AppsPath, srv.generateAppIDHandler)
92-
_ = srv.handler.Post(TokensPath, srv.requestTokenHandler)
93-
_ = srv.handler.Put(TokensPath, srv.verifyTokenHandler)
94-
_ = srv.handler.Get(HealthCheckPath, srv.healthCheckHandler)
93+
_ = srv.handler.Post(AppsPath, rl.Middleware(srv.generateAppIDHandler))
94+
_ = srv.handler.Post(TokensPath, rl.Middleware(srv.requestTokenHandler))
95+
_ = srv.handler.Put(TokensPath, rl.Middleware(srv.verifyTokenHandler))
96+
_ = srv.handler.Get(HealthCheckPath, rl.Middleware(srv.healthCheckHandler))
9597
// build the http server
9698
srv.httpServer = &http.Server{
9799
Addr: fmt.Sprintf("%s:%d", cfg.Server, cfg.ServerPort),

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ module github.com/simpleauthlink/authapi
22

33
go 1.24
44

5-
require github.com/lucasmenendez/apihandler v0.0.8
6-
7-
require golang.org/x/time v0.11.0 // indirect
5+
require github.com/lucasmenendez/apihandler v0.0.9

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
github.com/lucasmenendez/apihandler v0.0.8 h1:xHBNqdg+/eKpmjSvcQIkfIWxhsBcQa5TpwRzU00KugU=
2-
github.com/lucasmenendez/apihandler v0.0.8/go.mod h1:u19tqauhQwxXbR2rw9//dCdM7oNNqzzPbByHh7R1imU=
3-
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
4-
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
1+
github.com/lucasmenendez/apihandler v0.0.9 h1:zn/e5Sszi+GFLXNxUONm21M5uq1Fg/9cDN0BoVCvK8A=
2+
github.com/lucasmenendez/apihandler v0.0.9/go.mod h1:YZdczL55/HFLSgM4PrEsl+ynxiPXDBeGpagK31Tpe8Q=

0 commit comments

Comments
 (0)