jub0bs/cors: a better CORS middleware library for Go

submited by
Style Pass
2024-04-27 18:30:09

I’ve just released jub0bs/cors, a new CORS middleware library for Go, perhaps the best one yet. It has some advantages over the more popular rs/cors library, including

If you’re already convinced and wish to migrate your code to jub0bs/cors without further ado, skip to the migration guide further down this post.

rs/cors deserves credit for being the most popular CORS middleware library for Go. Its development, still ongoing, spans close to ten years and, to this day, many open-source projects depend on it. But is it perfect? No library is, of course, but I believe Go developers deserve the best. In my opinion, rs/cors suffers from some shortcomings that jub0bs/cors addresses; allow me to detail just a few of them.

If you consult the documentation of rs/cors, you’ll quickly realise that the library provides no fewer than four ways of specifying which Web origins should be allowed by the desired CORS middleware:

Not only is such a proliferation of redundant options overwhelming but, as mentioned in an earlier post, some of them are deceptively easy to misuse. In comparison, jub0bs/cors provides a single way of configuring any specific aspect of your desired CORS middleware:

Leave a Comment