Which Go Framework is the best?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what is going on guys so I have been talking about go and back-end development for a while but I have yet to really go over which framework I use and why there are a variety of different options these days from mux to Gin to fiber to just rolling your own custom HTTP server using the built-in HTTP packages but the one that I always use and the one that's become by far my favorite is fiber so I'm going to break down fiber show you why I use it in some pretty absurd benchmarks that make it in my opinion the Clear Choice for any new uh back-end project you're starting to go I think the best place to start is going to be just an example of a basic hello world in all the different Frameworks that I mentioned earlier so the first one is going to be Fiverr so this is my favorite as I've said and the syntax is extremely similar to express and they actually say in the documentation it's an Express inspired framework which personally I like because I come from a background of nexjs and express and node and all that stuff I know a lot of people don't like the node ecosystem as much but personally I find it very intuitive and I really like this way of setting up my router setting up my roots setting up my middleware it if it works and express the general concept will still work here which I think is pretty great then we have mux so mux has a similar syntax it's a little different because we don't have to pass in you get we use handle Funk instead so you then have to declare what method you're using elsewhere and then the way you send stuff back is a little different it's w dot right and then you're sending back a byte array instead of sending just having a send string or send Json or whatever um a little less intuitive but still very easy to set up and very um very easy to use very easy to work with um then we have Jin Jin is by far the most popular of all the things I'm going to mention today and this also has that sort of an Express inspired framework of the router.sum method and then you pass in the root and then you pass in the Handler function so very similar there the C gen context and the C fiber context very similar to each other so the two are very comparable the big place where they sort of break apart is in the middlewares and well they don't break apart in the fact that you can implement middlewares but they break apart in the fact that um fiber has a lot of really great just pre-implemented middlewares for you that make your life really easy jyn does as well but I like the way fiber does it better personally and then we get into just the basic server which is just http.handle function and then passing all this stuff in if you notice mux is very very similar to this because rap box is a pretty light abstraction on all on the basic HTTP package and then you're setting this up then you listen in server 3000 so you can't build out a full API so that this does not use any packages or import anything and it will you build a full API this way but personally I wouldn't recommend it a lot of the features and niceties that you get from these Frameworks are really just not worth passing up especially with how absurd fiverr's performance can get so the first thing you'll see when we get into the documentation this is very subjective and is not a reason to pick a framework or a language over another but I do like their documentation a lot it's very nice but again not a reason to pick it it's just a nice bonus that it has and in the fiber world one of the most interesting things we can take a look at is their benchmarks okay so when we're looking at the the when we look at this Benchmark page you can see that the performance difference that you get well first of all this top number up here those six million requests per second with a latency of two milliseconds versus 367 000 for 351 milliseconds that is fiber versus Express that is Go versus typescript or JavaScript go is a much much more performant language the typescript it is not even close now that's not to say the typescript is bad or you shouldn't be using it for back-end development scales really well with serverless it's extremely easy to write extremely fast to write and it integrates really well with the front ends these sort of meta Frameworks of nexjs and remix and nux and all this those are phenomenal ways to build apps I'm not dogging on those or anything but when you need heavy performance and very heavy compute on your server particularly when concurrency is involved fiber and go absolutely the way to go we have fiber and then the fiber pre-fork at around 6 million and then all the way down here we have gin all the way down at 600 000. so in all of these benchmarks you're going to notice that fiber absolutely blows gin out of the water and as you'll see from all these different benchmarkings fiber is insanely fast way faster than basically any other framework and that's because it's built on top of fast HTTP which is one of the fastest ways exhp calls and go so makes the framework really fast it still maintains a really nice writability and readability by being Express inspired and using a lot of these nice design patterns that most of us are familiar with so then getting into another thing that this has going for and I think that is the built-in middleware if you look at this tab on their documentation you can see we have Base golf cache compressed etc etc these are all built-in middlewares that that fiber will provide for you and it covers a lot of common use cases you're going to run into and it's going to make your life a lot easier when you need to go in and actually implement this stuff so for example if you need to deal with cores which most people will it just has this built-in so similar to express Express you can just add the course package this it's actually built in it just has this built-in middleware of course and you just have to make sure that your app is using it or then like another good example is like a rate limiter you don't want people to be able to spam your server into the ground so you can put this guy on here and then just live it or not new will prevent spamming it'll prevent ddoses it's great it makes um this is often something that's really a pain to implement but fiber just does it for you so there's a lot of different things in here I won't go through all of them but you get the sort of idea that these builts and middlewares are just excellent and then implementing your own custom metal Wares is just as easy as it would be an Express or any other framework or language it just feels really natural and easy yeah the way the handle routing is really nice it's exactly how you would expect it to work grouping Works how you'd expect it to work and then sort of the last thing that I kind of want to go over in the docs is like these hooks that you can do so what these hooks are is they're basically just functions that will execute every time a certain condition or event is met so like for example with the hooks what we're doing here is we're setting the name of this route to index and then what it'll do is it'll go here we have two hooks to find one of these will take in the they'll be executed in order as you can see down here so this first one is just going to take in the name because since we have this Fiverr root and we have a name for it we can pass in the name here read name is this and that'll print out this first part of this line right here and then this second hook will fire which will also be called on name and then that will just pass in the method and it'll print out method of whatever so add user method get and then that's a nice logging solution or you could do some side effect logic or however you want to handle it it's a nice feature to have and there are tons of other hooks on here on Fork on list and on shutdown etc etc so that's sort of the general gist of it it's not the most in-depth thing but it kind of just comes down to Fiverr is the fastest it's got the most elegant syntax in my opinion it's very similar to express very easy to work with very comfortable if you've ever done any back end development before you'll feel right at all within minutes and yeah
Info
Channel: Davis Media
Views: 24,661
Rating: undefined out of 5
Keywords: Go, GoLang
Id: Tppz2dDGXGk
Channel Id: undefined
Length: 6min 52sec (412 seconds)
Published: Tue Nov 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.