DEV Community


Echo Go - Middleware

egaprsty profile image Ega Prasetya ・1 min read

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


Alt Text

Finally! Grats.

Discussion (2)

Editor guide
nathandaly profile image
Nathan Daly

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

egaprsty profile image
Ega Prasetya Author

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