The BEST Tool to Structure Golang Projects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
go project structure and project layout are a very Hot Topic in the go Community because there isn't really a one clear answer one clear guide on how you can spin up and structure new projects there's videos uh obviously by myself by Anthony GG goang Dojo that explain you know and suggest ways of how you can structure your project there's also a very popular uh repository goang standards project layout with 46,000 Stars which is see as kind of like the answer and the rule book of how to structure your go project with lots of great you know pieces of information with explanations of every folder and every directory however Russ Cox who was on the core goang team actually made an issue on this exact same project layout back in April 9th of 2021 saying the read mey makes clear that this is not official but even the claim it is a set of common historical and emerging project layout patterns in ecosystem is not accurate for example the vast majority of packages in the go ecosystem do not put the importable package in a PKG subdirectory more generally what is described here is just a very complex and go repos tend to be much simpler so this is kind of from the one of the main people who helped build go saying hey yeah this go project is nice but it's really not the way you should do things so that puts a lot of things into perspective and again we're going back into the topic of no one really has a clear answer of how to do things which is why I want to discuss a project that I had built with the help of the great Community called go blueprint it's at 2,000 Stars so this is also kind of a celebratory video looking at the success and the community feedback of this project it's been very well received so I appreciate all of that but essentially go blueprint is the ultimate goaling blueprint Library gold blueprint is a CLI tool that allows users to spin up a go project with a corresponding structure seamlessly and if you don't really know what that means there's actually a website called go- blueprint. Dev and here you can actually pick what you want in your go project so if you want a database we have options for MySQL post SQL light in mongodb there's a few Frameworks that we kind of allow Chi Echo fiber Jin gorilla HTTP routers and we actually even have an advanced flag which I'll show later on in this video of how you can actually have htx support with temple cic work flows using GitHub actions and even a web socket implementation and down below there's a UI that shows you the project structure so let's say we can name this like test project and then let's say we want for our database postgress and you want Chi and it actually shows you the command to write in your C after you have go blueprint downloaded and what the project structure will look like all right so made my terminal here a little bit bigger and the first thing I would like you to do is paste the go install command to get the latest version of go blueprint so at the time of recording the latest version is 0.5.2 updated about 3 weeks ago again from the time of recording so after successfully downloading go blueprint it actually going to bind to your path so now you have the command go blueprint available so what you can do is go- blueprint create and if you do this it's actually going to start a CI interactive project that will walk you through the steps of what you want now what's the name of your project let's just say hello YouTube and then we can pick what framework do you want to use in your go project we give the standard Library Chi Jin fiber gorilla HTP rou and Echo I personally like Chi so let's go ahead and click Chi and then what database driver do you want to use in your go project with a few options here even reddis let's go ahead with postgress click yes and it's going to prepare the project and as you can see if you open up this we now have our CMD directory with our main.go let me minimize this it has our Inon directory with our database logic here in database. go it has a server with our routes defined using Chi and it has a bunch of other good things it even comes with a test folder an air toel for hot reloading and just an example. EnV file that hosts everything you need for you know your local development using go blueprint and a Nifty thing is if you are going to use the database flag we actually will give you a Docker compose which you can do Docker compose up it it will spin up a local database instance using Docker this is in particular using postgress and then you can actually connect with main.go to your database and I almost forgot to mention we actually also include a make file and this make file has a lot of cool things you can do make Docker run so go ahead and let's see that Docker run so SE into the project and then you can do something like make Docker run and this is actually going to pull up pull the image for you and it's going to run a local postgress instance using Docker and while this is going to be important you can see here now we have our Docker instance running we can actually make a new terminal and then we can do a make build which is going to build our application if you just want to run you can do make run and now that you have the actual Docker instance running you can actually run the make run command and it's going to run the instance and now you have a working go server running that's connected to your postest database so that's a really good kind of basic implementation but now I want to kind of explore the advanced flag and the advanced flag is pretty similar to the casual or the regular flow we just went through so if I go again go blueprint and just to show I have nothing in this directory I deleted the last project we spun up you can do go blueprint go- blueprint create you can do the advanced flag and now you can see that you are in advanced mode and it's the setup is going to be primarily the same but there's going to be an option at the end that asks you if you want HTM X do you want cicd actions or even want websockets so what's the name of your project let's go Advanced hello YouTube let's just go with just Chi again let's do postgress and then which Advanced feature do you want HTM X Temple go project workflow or a websocket endpoint let's go ahead with the web socket endpoint and you're going to go ahead and prepare all that for us may take a little bit more time and there you go and actually give us a tip repeat the equivalent blueprint with the following non- intera command so this again a feature that we have that if you don't want to go through this entire CLI it can actually short form the direct command which will spin up this entire project for you yeah and here you can see the a main difference in the routes that go we now have this web socket Handler with a few specific functions to manage the websocket you got an endpoint to see the actual Handler so a lot of cool things this project this open source project offers for people who are interested in learning go but don't necessarily know on how to structure a project or just need a little bit of like a a template like create react app or a create T3 app equivalent in the go world and if you have any questions about how any of this Works more in detail we actually have a docs. go- blueprint. deev website which highlights all of the kind of installation the actual UI everything that goes forward with how the go blueprint is made and the drivers the Frameworks that we choose all that is explained in detail in the docs uh links for all this will be in the description down below so with all that being said make sure you go visit go blueprint on GitHub give it a starts greatly appreciated let me know what you all think of this do you like it have you used it are there any issues you have a PR do you want to implement but it's been a lot of fun getting this project to 2,000 Stars big shout out to everyone who worked on this Brian and EJ and everyone else who put up many many different PRS and all the people gave feedback much appreciated but yeah let me know what you guys think if you like this kind of video comment like And subscribe for more but as always stay coding bro and you got to PO it
Info
Channel: Melkey
Views: 20,914
Rating: undefined out of 5
Keywords: software engineer, computer programming, coding, learn to code, cloud, how to code, golang, how to structure go projects, how to learn go, how to program in go, how to become a programmer, theprimetime, anthonygg, golang problems, how to find a job with golang, leetcode, golang project, golang project structure, github open source
Id: 1ZbQS6pOlSQ
Channel Id: undefined
Length: 7min 58sec (478 seconds)
Published: Tue May 28 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.