The TRUTH About Golang Backend Frameworks

Melkey
5 Sept 202306:30

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

00:00

🤔 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.

05:03

📚 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

Go, often referred to as Golang, is an open-source programming language developed by Google. It is statically typed, compiled, and syntactically similar to C. In the context of the video, Go is used for backend API development, highlighting its suitability for concurrent processes and network services.

💡Framework

A framework in software development provides a foundational structure, including a set of functionalities, that allows developers to build applications more efficiently. In the video, the speaker discusses various Go frameworks, emphasizing the need to choose the right one for backend API development.

💡API

API stands for Application Programming Interface, which is a set of rules and protocols for building and interacting with software applications. The video focuses on using Go frameworks to build backend services for APIs, which are crucial for front-end/back-end communication.

💡Cobra

Cobra is a Go library used for creating powerful modern CLI (Command Line Interface) applications. It is mentioned in the video as an example of a tool for CLI applications, not directly related to backend API development.

💡Chi

Chi is a lightweight, idiomatic and composable router for building Go HTTP services. The video uses Chi as an example of a Go framework that provides routing capabilities, which is a fundamental aspect of building web services and APIs.

💡Gin

Gin is a web framework written in Go, featuring a Martini-like API with much better performance. It is highlighted in the video as an example of a framework that offers performance improvements for web applications.

💡Fiber

Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. The video mentions Fiber to illustrate the variety of frameworks available in Go, each with its own approach to handling HTTP requests.

💡Echo

Echo is a high-performance, extensible, and minimalist Go web framework. It is used in the video to demonstrate the pattern of defining routes and middleware, which is common across many Go frameworks.

💡Standard Library

The Go standard library is a collection of packages that come with the Go distribution and provide core functionalities. The video encourages using the standard library for Go development, suggesting that it is often sufficient for building robust applications without additional frameworks.

💡HTTP Router

HTTP Router is a Go library by Julian Schmidt that provides a way to route HTTP requests. The video recommends HTTP Router as an example of a library that is close to the standard library, emphasizing its simplicity and effectiveness for routing in web applications.

💡Middleware

Middleware in web development is a function that has the ability to intercept and process HTTP requests and responses between the client and the server. The video discusses middleware in the context of defining routes in various Go frameworks, showcasing how it can be used to handle common tasks like logging or authentication.

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

play00:00

if you are coding in go you have

play00:02

probably asked yourself what go

play00:05

framework should I use now I want to be

play00:07

specific and focus on Frameworks that

play00:09

people would typically use when they're

play00:11

building a go backend for their API and

play00:14

not so much Frameworks they would use

play00:15

for creating something like acli which

play00:17

if you haven't heard already Cobra and

play00:19

charm are great options so go use them

play00:22

it doesn't take a whole lot of effort to

play00:23

do one quick Google search on what go

play00:26

framework to use to see a whole bunch of

play00:28

lists pop up and then you get yourself

play00:30

into what I like to call the JavaScript

play00:33

problem the JavaScript problem is when

play00:36

there's too many options of what tool

play00:39

Library framework to use without

play00:41

actually knowing which one you truly

play00:43

need and want for your applications in

play00:46

JavaScript is react view svelte solid

play00:50

Astro next I mean it's JavaScript the

play00:53

ecosystem is evolving and changing every

play00:55

single day but in go I mean there's also

play00:58

a lot of options there's gin there's Qi

play01:01

there's fiber there's Echo there's

play01:03

Vulpix that's a Pokemon I

play01:06

try to trick you

play01:08

the very best which framework is right

play01:11

for them well that's the actual thing

play01:13

there is no right framework in go so you

play01:17

can see here I'm on go Chi and if I just

play01:20

read the first bit of the readme QI is a

play01:22

lightweight idiomatic and composable

play01:25

router for building go HTTP Services if

play01:30

I flip to go Jin Jin is a web framework

play01:33

writ and go it features a martini lick

play01:37

API with performance that is up to 40

play01:39

times faster thanks to http router if

play01:43

you check out go fiber fiber is an

play01:46

Express inspired web framework built on

play01:49

top of fast HTTP the fastest HTTP engine

play01:53

for go and if we check go Echo we can do

play01:55

some of the featured overviews optimized

play01:57

HP router with smartly prioritized

play01:59

routes build robust and scalable restful

play02:02

apis have you noticed a pattern you see

play02:05

a lot of these libraries in go these

play02:07

Frameworks are essentially doing the

play02:10

same thing they are just rappers on top

play02:13

of the standard library that go offers

play02:16

and this isn't necessary that's a sad

play02:18

thing and I'm not saying all of these

play02:19

are the exact same but when you are

play02:22

focusing on just creating routes or

play02:24

middleware or anything like that you can

play02:26

pick any of them here we're back on go

play02:28

Chi and you can see this example as easy

play02:30

as you have your import so there's Qi

play02:32

there's a standard HTTP library and

play02:34

they're in your function main you create

play02:36

your new router using Chi Library you

play02:38

create the middleware and you're

play02:40

designing a route here this get route

play02:42

with a response that just says welcome

play02:44

looks super simple wow Qi is great all

play02:47

right let's flip on to Jen for a second

play02:49

gin you have your import net HTTP and

play02:52

Jin okay awesome so you create gin dot

play02:55

default and oh oh you define your route

play02:58

that has a response okay cool this is

play03:01

great this is awesome how about we check

play03:03

out fiber for a second you have your

play03:04

import fiber and oh oh app fiber.new and

play03:08

you define

play03:10

this looks almost exactly the same you

play03:12

have to get route that just says hello

play03:14

world okay well how about we check out

play03:15

Echo for real quickly just you know just

play03:18

to check out how different can it be and

play03:19

oh you create your new Echo instance

play03:22

okay middleware or all right and you you

play03:25

get route

play03:27

with a response that says hello world

play03:29

you can see that all of them followed

play03:32

the same pattern and yes Jin and Chi may

play03:35

have things that provide more use case

play03:38

in a fully fleshed out library and

play03:41

framework to use but at the end of the

play03:43

day you create the instant you define

play03:46

your get or post route and you pass it a

play03:48

function or literally a Json payload and

play03:50

it just does what you tell it to the

play03:52

Handler respond to the route how you

play03:55

define it and it looks the exact same

play03:57

way for every single one and just to

play04:00

Showcase another example one that I

play04:02

personally recommend is HTTP router by

play04:04

Julian Schmidt because this is the

play04:08

closest to the standard library that you

play04:09

can get between all the examples I

play04:11

previously showed you can see here

play04:13

Define two handlers index and hello you

play04:15

define your routes by instantiating HTTP

play04:17

router from the library you pull in and

play04:19

then you have a two dot get map method

play04:22

on these two routes declared and they

play04:23

will pass the function of the Handler

play04:25

and so what I really want to kind of

play04:26

convey and what I always talk about when

play04:29

I explain go to someone is that you have

play04:31

to separate your thinking of go from

play04:33

JavaScript if you're coming from that

play04:34

world or any other world because go you

play04:37

can truly do everything with the

play04:40

standard Library go isn't that program

play04:42

language where you should be picky and

play04:44

really pulling resources or deciding

play04:47

which framework is right for you of

play04:49

course you can use particular use cases

play04:51

that you can read about and really

play04:52

discover that huh this really solved the

play04:54

problem I have I'm going to use and

play04:56

that's pretty perfectly fine but if

play04:58

you're spending time spinning your

play04:59

wheels on deciding from all the frames

play05:02

that you see from a best framework to

play05:04

use in 2023 list you're wasting your

play05:06

time what I recommend to everyone who's

play05:08

starting with go is essentially try to

play05:10

do things using just the standard

play05:12

Library don't start importing modules or

play05:16

Frameworks if you don't need them

play05:17

they're all the same but why am I

play05:19

recommending HTTP router milk didn't you

play05:21

just say try to make it yourself and

play05:23

that's a valid point but like I said

play05:24

earlier HTTP router is the closest one

play05:27

to the standard library and that is why

play05:30

I personally like it you don't need to

play05:33

bring anything new it's simply just a

play05:36

router that gives you everything you

play05:37

need to fully pass in any Handler you

play05:40

decide to create and there's other

play05:42

libraries and Frameworks they can use in

play05:43

the go ecosystem richest people always

play05:46

developing new things to use if you want

play05:48

to use something for sending emails or

play05:50

specifically handling you know crypto

play05:52

hashes or jaw tokens or anything like

play05:55

that there's something that there for

play05:57

you but use a standard Library explore

play05:59

the standard Library first you'll be

play06:02

surprised on how well and defined those

play06:04

things come stock in the go ecosystem so

play06:07

with that guys I gotta leave you with

play06:09

two things out of all of the Frameworks

play06:10

I just decided and listed which one have

play06:12

you used for your go application and if

play06:14

you if you used one I challenge you to

play06:16

use the standard Library remove that

play06:19

framework from your app and just try

play06:21

replicating it with the standard library

play06:23

and let me know if you're successful or

play06:25

not and two

play06:28

you gotta power it

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
Go FrameworksAPI BackendWeb DevelopmentPerformanceCobraChiGinFiberEchoStandard LibraryHTTP Router
Benötigen Sie eine Zusammenfassung auf Englisch?