DEV Community

Ega Prasetya
Ega Prasetya

Posted on

6 3

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!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️