Why The Golang 1.22 HTTP Router Is Not Great

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's good ladies and gentlemen in this video I'm going to give you my own unsalted opinion about goang 1.22 actually the we are a couple of months into this version patch whatever you want to call it and I want to especially talk about the MX right this basically everybody was the new MX are amazing we don't need third party libraries and unfortunately guys I think it's still not good right it's still not good let's go let's let's dive into that right so basically what they also did is the um encapsulation of the uh four Loop stuff you know what I mean I cannot even uh say it right that's a good thing that they did right that was a very nasty stuff and they fixed that uh but yeah so basically what can we do let's make a router I call it router you can call it MX so it's going to be I think it's HTTP new serve M right just like that and we can do something like a router. handle Funk and now we can do something like in the beginning we could do get and do uh handle Funk here now we can do something crazy like uh now we have a decent rou now we can do for example user and then we can do something like ID right and then actually we could do handle get a user by ID here right so what I'm going to do I'm going to copy this thing and make sure we can have this function W HTTP response um man this phone it's huge for the blind homies and it's going to be an uh point to an HTTP request right just like that uh there's already a big problem here right now actually to be honest let's start with the begin right Anthony keep yourself keep the focus on I know you're basically it's morning energetic HD and all that stuff keep Focus so the thing is that um the most important thing is this thing right now we don't need uh another third party router because now we can actually access this ID and I think that's very nice and we can do that by uh R pad value is it something like that I right let's do this underscore Sid for the compiler right satisfying the compiler that's good I think that's amazing but the problem is um that what I'm missing and I have no clue why they don't do it I have no no no clue because I think a lot of people have uh put feedback into this and I'm going to I'm going to tell you why the first thing that is so annoying and is so important in my opinion and of course opinions are opinions and sometimes people can basically talk me off my opinions but handlers that do not return an error here this is I cannot live with that man they need to return an error and let me know in the comments what you think about that right I think the Handler always needs to return an error why because it gives you the opportunity to write your code cleaner it also gives you the opportunity to had custom errors and Central based on your custom errors uh you can centralize your error handling and everything is just way better because if now if there is a problem let's say we're GNA have an error here uh we need to do if R is not mil and then we need to do some Shenanigans shenan guns right and now we need to return here which makes no sense and we're going to copy this all over the place right here and here and it's just annoying right so what you could do is uh if if there is an error here right uh you can just do this error and then you just if the is not n you just return the arror return errors and you don't need to care about it anymore because you could add your own error because error is an interface so you can add your own error type and you can handle it somewhere else right uh but we can't right now because they don't they still don't do it why they don't do it well I think it's all about the goang promise that uh the backward compatibility right let us be honest goang is great because you can actually use code from 10 years ago it's still going to work you know what I mean it's crazy right everything is just compatible uh and that's good in a sense but it's always it's also blocking and it's actually a decision right you need to choose that's life right sometimes you cannot have it all um but they cannot they cannot use an arrow here because if they do that this actually this thing look at that this this this thing is going to change right this Handler Funk uh is going to change here the Handler interface I think it is um and nothing is going to work anymore right it's not going to be backwards compatible so they need to have something else how could we solve that instead of handle Funk they could do handle Funk a they could whatever they could do a lot of other stuff with that uh but they don't right I have no clue why the next problem I have with this with this stuff uh because people say we don't need we don't need to use third part libraries like for example Chi Echo Fiers uh Jin well I think we do I still think we do because there is no such thing as grouping right there's no such thing as grouping uh where you can have for example I don't know like an API or an out group where you have uh for example router use you know this the stuff right every single framework use the same thing and you're going to have middleware one middleware two middleware three and then you're going to have an admin thingy here for example admin and we're going to use I don't know admin middle 4 and so on and so on I think it's just amazing and I think Chi does it very very well um with these nested routes and where you can add these middle I think it's amazing to be honest every framework handles it well right fiber Echo G G they actually Bas they do all the same thing in my opinion right um so that's a problem but you could say Anthony yeah but you just use a standal library and yeah of course yeah we can we can write everything ourselves that's true that's true um but guys sometimes I mean this basic stuff this is actually really basic stuff right this is not like rocket science uh having the option I mean if they're going to Brack about oh we have this new router this new M stuff at least add some more functionality to do it guys I don't know what the hell is going on people are basically bagging for this people are crying for this every single framework is using it why don't you implement it probably backwards compatibility but hey that's not how you're going to make a language great right um anyway that's basically what I'm thinking so people say yeah do we need do we need to stop using third party libraries for uh these uh API servers or whatever I don't think so right uh I'm using at uh for a lot of my projects right now because I think it's simple it's compatible um it does not return an arrow in the handers I know but you can easily wrap it um and that's annoying right I think for examp I think fiber is returning Arrow I think fiber is the only one uh does Echo return I don't know if Echo returns errors but I think it does I think it does but I I'm pretty sure fiber Returns the Handler of fiber returns erors and I think I love it um well I don't think I love it I love it 100% let me know what you think about the arrow stuff I think it's just mandatory and nobody can basically change my mind on this thing so what do I think 1 122 a lot of hype for no reason at all to be honest because this is nice but still um not enough for me to change um to stop using third party party stuff third party Library stuff in my opinion and I also don't think we need to see go as the programming language where using third party libraries is a is a is a crime time right because that's what I hear a lot in my community like hey I want to build this project but I'm afraid of using this library because people are complaining on Reddit and classic Reddit don't listen to them they are all broke so basically um it's it's it's good to use a third party library right it's it's fine it's perfectly fine of course don't overuse it uh but especially for these things it's very critical stuff I would definitely still use a third party library right that's basically my take on 122 this video is basically I don't know what it is I just want to make it because people are uh keep asking me about this so now you know right let me know in the comments what you think about that uh of course it's an improvement but it's still not there where I like it to be all right thanks for watching see you in the next video or live stream take care
Info
Channel: Anthony GG
Views: 14,902
Rating: undefined out of 5
Keywords: golang, programming, golang 1.22, golang 1.22 router, golang http, golang http handler, golang tutorial, learn golang, golang for beginners, golang course, golang tutorials, golang beginner tutorial, golang programming, golang concurrency, why learn golang, go tutorial, go programming, golang introduction, vim, vscode, http, software engineering
Id: agX6Ba2ODlw
Channel Id: undefined
Length: 8min 18sec (498 seconds)
Published: Tue Mar 26 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.