DEV Community

Ega Prasetya
Ega Prasetya

Posted on

Echo Go - Middleware

Middleware is a block code when we call it before or after http request in proccess. Middleware usually made per functions, example: Middleware authentication, logging, and gzip compression, etc.

Custom Middleware

Middleware making in go is very simple, just used method .Use() belong object echo for middleware registrations.

Ok so create new folder project main.go, and follow this code

Alt Text

Next, create two middleware, middlewareOne & middlewareTwo, it displays log.

Alt Text

Registration two middlewares in above, this is example code.

Alt Text

Testing

Alt Text

Finally! Grats.

Top comments (2)

Collapse
 
nathandaly profile image
Nathan Daly

Started using Echo to build a Chatkit, I'm liking it and this is handy thanks :)

Collapse
 
egaprsty profile image
Ega Prasetya

I'll save it, but I'll finish the echo series first. Thx for support bro!