Write a Custom Middleware
January ships with built-in middleware package, which is initialised in theinit.january.go file.Adding a middleware to your application is 2 simple steps:
- Write the Middleware
- Wire it to the January Router
CORS middle.
1. Writing a Middleware
Create a file namedcors.go in the middleware package and add a method called Cors with a receiver m *Middleware
middleware/cors.go
middleware/cors.go
2. Wiring to the January Router
In theinit.january.go file, add the middle just below the apply middleware comment:
init.january.go
Try it out
Run the application withmake start