The TRUTH About Golang Backend Frameworks
Summary
TLDRThe script discusses the dilemma of choosing a Go framework for building backend APIs, comparing it to the 'JavaScript problem' of too many options. It reviews frameworks like Gin, Chi, Fiber, Echo, and HTTP router, highlighting their similarities and suggesting that often, the standard library suffices. The speaker advocates starting with Go's standard library and only using external libraries for specific use cases, recommending HTTP router for its simplicity and closeness to the standard library.
Takeaways
- 🔍 Choosing a Go framework can be overwhelming due to the multitude of options available.
- 🤔 The 'JavaScript problem' refers to having too many tools or frameworks to choose from without a clear need.
- 📚 Popular Go frameworks for backend API development include Gin, Qi, Fiber, Echo, and others.
- 🧩 Many Go frameworks are essentially wrappers around the standard library, offering similar functionalities.
- 🚀 Gin is noted for its high performance, up to 40 times faster thanks to http router.
- 🌐 Echo is highlighted for its optimized HTTP router with smartly prioritized routes.
- 🛠️ Qi is described as lightweight, idiomatic, and composable for building HTTP services.
- 🌟 The presenter recommends starting with the standard library and not relying on external frameworks unless necessary.
- 🔄 There's no 'right' framework in Go; it's more about personal preference and specific use cases.
- 🔄 HTTP router by Julian Schmidt is recommended for its simplicity and closeness to the standard library.
Q & A
What is the 'JavaScript problem' mentioned in the script?
-The 'JavaScript problem' refers to the overwhelming number of options for tools, libraries, and frameworks available, which can make it difficult to choose the right one for a specific application.
Why does the speaker suggest that there is no 'right' Go framework?
-The speaker suggests that there is no 'right' Go framework because many of the frameworks essentially do the same thing, acting as wrappers on top of the standard library, and thus the choice often comes down to personal preference rather than necessity.
What are some of the Go frameworks mentioned in the script?
-Some of the Go frameworks mentioned are Gin, Qi, Fiber, Echo, and Go Chi.
What does the speaker recommend for someone new to Go?
-The speaker recommends starting with the standard library and not importing modules or frameworks unless they are necessary.
Why does the speaker recommend the HTTP router by Julian Schmidt?
-The speaker recommends HTTP router by Julian Schmidt because it is the closest to the standard library and requires minimal additional resources, providing just the router functionality needed.
What is the main similarity the speaker points out among the Go frameworks?
-The main similarity is that all the frameworks follow a similar pattern of creating instances, defining routes, and passing handlers or JSON payloads.
What is the speaker's stance on using frameworks for creating routes or middleware in Go?
-The speaker believes that using frameworks for creating routes or middleware in Go is not necessary since these functionalities can be achieved with the standard library alone.
What is the 'Pokemon' reference in the script about?
-The 'Pokemon' reference is a humorous way the speaker uses to indicate that there are so many Go frameworks that they can be confusing, similar to the vast number of Pokemon.
What is the challenge the speaker issues to the audience at the end of the script?
-The challenge is for the audience to try to replicate their application's functionality using only the standard library, after removing any frameworks they were using.
What is the main takeaway from the script regarding Go frameworks?
-The main takeaway is that one should not get caught up in choosing the 'best' framework but instead focus on using the standard library and only introduce frameworks for specific use cases where they provide clear benefits.
Outlines
🤔 Choosing the Right Go Framework for Your API
This paragraph discusses the dilemma of selecting a Go framework for building a backend API. It emphasizes the need to focus on frameworks suitable for API development rather than CLI tools. The author highlights the popularity of Cobra and Gin but warns against the 'JavaScript problem,' where an abundance of options can lead to confusion. The paragraph then compares several Go frameworks like Chi, Gin, Fiber, Echo, and Vulpix (a playful reference to a Pokémon), noting that many of these are essentially wrappers around the standard library. The author suggests that there's no 'right' framework and that the choice should be based on specific use cases rather than general popularity.
📚 Leveraging the Standard Library in Go
The second paragraph offers advice for newcomers to Go, suggesting that they should rely on the standard library as much as possible before introducing external modules or frameworks. The author recommends the HTTP router by Julian Schmidt for its simplicity and closeness to the standard library. The paragraph encourages exploring the standard library first, as it often provides robust solutions out-of-the-box. The author also acknowledges the existence of specialized libraries for tasks like email sending or handling JWTs but emphasizes the importance of understanding and utilizing the standard library before seeking external dependencies.
Mindmap
Keywords
💡Go
💡Framework
💡API
💡Cobra
💡Chi
💡Gin
💡Fiber
💡Echo
💡Standard Library
💡HTTP Router
💡Middleware
Highlights
The dilemma of choosing a Go framework for building a backend API.
Cobra and Charm are recommended for creating CLIs in Go.
The 'JavaScript problem' of having too many options without knowing the true need.
Go frameworks like Gin, Qi, Fiber, Echo, and Vulpix are compared.
Qi is described as a lightweight, idiomatic, and composable router.
Gin offers a Martini-like API with performance improvements.
Fiber is an Express-inspired framework built on FastHTTP.
Echo is optimized for building RESTful APIs.
Frameworks are essentially wrappers on top of the standard library.
Creating routes and middleware can be done with any framework.
HTTP router by Julian Schmidt is recommended for its simplicity and closeness to the standard library.
Frameworks follow a similar pattern for defining routes and handlers.
The importance of separating Go from JavaScript or other languages' mindsets.
Recommendation to start with the standard library before importing modules or frameworks.
Challenge to use the standard library to replicate framework functionality.
Encouragement to explore the standard library for built-in solutions.
The conclusion that there is no 'right' framework in Go, and the importance of choosing based on specific use cases.
Transcripts
if you are coding in go you have
probably asked yourself what go
framework should I use now I want to be
specific and focus on Frameworks that
people would typically use when they're
building a go backend for their API and
not so much Frameworks they would use
for creating something like acli which
if you haven't heard already Cobra and
charm are great options so go use them
it doesn't take a whole lot of effort to
do one quick Google search on what go
framework to use to see a whole bunch of
lists pop up and then you get yourself
into what I like to call the JavaScript
problem the JavaScript problem is when
there's too many options of what tool
Library framework to use without
actually knowing which one you truly
need and want for your applications in
JavaScript is react view svelte solid
Astro next I mean it's JavaScript the
ecosystem is evolving and changing every
single day but in go I mean there's also
a lot of options there's gin there's Qi
there's fiber there's Echo there's
Vulpix that's a Pokemon I
try to trick you
the very best which framework is right
for them well that's the actual thing
there is no right framework in go so you
can see here I'm on go Chi and if I just
read the first bit of the readme QI is a
lightweight idiomatic and composable
router for building go HTTP Services if
I flip to go Jin Jin is a web framework
writ and go it features a martini lick
API with performance that is up to 40
times faster thanks to http router if
you check out go fiber fiber is an
Express inspired web framework built on
top of fast HTTP the fastest HTTP engine
for go and if we check go Echo we can do
some of the featured overviews optimized
HP router with smartly prioritized
routes build robust and scalable restful
apis have you noticed a pattern you see
a lot of these libraries in go these
Frameworks are essentially doing the
same thing they are just rappers on top
of the standard library that go offers
and this isn't necessary that's a sad
thing and I'm not saying all of these
are the exact same but when you are
focusing on just creating routes or
middleware or anything like that you can
pick any of them here we're back on go
Chi and you can see this example as easy
as you have your import so there's Qi
there's a standard HTTP library and
they're in your function main you create
your new router using Chi Library you
create the middleware and you're
designing a route here this get route
with a response that just says welcome
looks super simple wow Qi is great all
right let's flip on to Jen for a second
gin you have your import net HTTP and
Jin okay awesome so you create gin dot
default and oh oh you define your route
that has a response okay cool this is
great this is awesome how about we check
out fiber for a second you have your
import fiber and oh oh app fiber.new and
you define
this looks almost exactly the same you
have to get route that just says hello
world okay well how about we check out
Echo for real quickly just you know just
to check out how different can it be and
oh you create your new Echo instance
okay middleware or all right and you you
get route
with a response that says hello world
you can see that all of them followed
the same pattern and yes Jin and Chi may
have things that provide more use case
in a fully fleshed out library and
framework to use but at the end of the
day you create the instant you define
your get or post route and you pass it a
function or literally a Json payload and
it just does what you tell it to the
Handler respond to the route how you
define it and it looks the exact same
way for every single one and just to
Showcase another example one that I
personally recommend is HTTP router by
Julian Schmidt because this is the
closest to the standard library that you
can get between all the examples I
previously showed you can see here
Define two handlers index and hello you
define your routes by instantiating HTTP
router from the library you pull in and
then you have a two dot get map method
on these two routes declared and they
will pass the function of the Handler
and so what I really want to kind of
convey and what I always talk about when
I explain go to someone is that you have
to separate your thinking of go from
JavaScript if you're coming from that
world or any other world because go you
can truly do everything with the
standard Library go isn't that program
language where you should be picky and
really pulling resources or deciding
which framework is right for you of
course you can use particular use cases
that you can read about and really
discover that huh this really solved the
problem I have I'm going to use and
that's pretty perfectly fine but if
you're spending time spinning your
wheels on deciding from all the frames
that you see from a best framework to
use in 2023 list you're wasting your
time what I recommend to everyone who's
starting with go is essentially try to
do things using just the standard
Library don't start importing modules or
Frameworks if you don't need them
they're all the same but why am I
recommending HTTP router milk didn't you
just say try to make it yourself and
that's a valid point but like I said
earlier HTTP router is the closest one
to the standard library and that is why
I personally like it you don't need to
bring anything new it's simply just a
router that gives you everything you
need to fully pass in any Handler you
decide to create and there's other
libraries and Frameworks they can use in
the go ecosystem richest people always
developing new things to use if you want
to use something for sending emails or
specifically handling you know crypto
hashes or jaw tokens or anything like
that there's something that there for
you but use a standard Library explore
the standard Library first you'll be
surprised on how well and defined those
things come stock in the go ecosystem so
with that guys I gotta leave you with
two things out of all of the Frameworks
I just decided and listed which one have
you used for your go application and if
you if you used one I challenge you to
use the standard Library remove that
framework from your app and just try
replicating it with the standard library
and let me know if you're successful or
not and two
you gotta power it
浏览更多相关视频
5.0 / 5 (0 votes)