Melky, what do you advise, I just started learning Go as I am new to software dev world, but some what seem confusing sometimes. Topic like Pointers; I am struggling to really understand it deeply, and a few others. Can you advice on howto go about it - recommend materials that can easily break it down for me. I am really interested in learning getting as far as building API's, Micro-services. I know that for a newbie, it seem like a daunting task; i do believe i can achieve it. I am not totally new to IT world, I have worked as a network engineer, and now looking to become a software engineer; Specifically a back-end or full stack. I do have a bit of the basic knowledge of variables, functions, struct, boolean, integer, float etc. i know basic python programming, html, css , docker, i use vagrant as IAC for my private test environment, Linux, basic knowledge of Git & Github, cloud services - aws cloud services, Splunk enterprise software installlation, monitoring and for onboarding data. I will appreciate your sincere advice? Thank you very much.
I have been a C# dev for over 15 years and wanted to try something else so a few days ago i picked up a GO course. This video has been a great addition to the other things i have. Thanks.
3 days ago I started my journey as a go developer. I wanted to learn something new and since I can't find work with my current knowledge of js I decided give a GO haha. This type of content is invaluable for me, thanks Melkey.
Hi, excellent vid Melkey. We can say that "internal" folder would be the High-Level modules, the code that organization CARES about, the business logic itself. For "pkg" would be the "Low-level modules" the code that the organization does not care about.
I see a lot of projects put a test file right next to the source file / package it's testing, i.e. no tests directory. Not sure I have a strong opinion on one or the other.
just started on go recently and struggling with structuring my project. watched a couple videos on that but seems like opinions are quite contradicting. anyway, great walkthrough, helps a lot
I've been coding in go for a while now, and I haven't found a good way to structure complex projects. For example, the lack of sub-packages, means that go code is insanely flat. And that means there is no obvious path to try to decipher the relationship between the packages, and the relationship between the entities in the packages and across packages. So, I often find myself having to hold the entire code deciphered and in my mind simultaneously, and unless I do that, I don't feel confident that I understand anything at all. Even within a package folder, either there is one giant file, or a bunch of file that I don't know which one should be opened first. Do you have an example of a complex go project that you can point to as being really well structured?
I see an advantage (there might be better approaches too): - if you want to ignore tests while building final go application container image. This reduces your final code base you are delivering. Just use test files for dev & testing phase. But for easy human consumption when looking at code base, test folder should follow the same structure as main code base, so that it’s easy to relate the relationships between folders and test files to the main code base folders and code files. Maybe someone here can provide more insights.
When I create go project. I always follow MVC like PHP framework folders. - routes -> routes.go - models -> post.go - databases -> database.go - controllers -> post_controllers.go, etc - views -> - layouts -> layout.html - pages -> home.html, about,html, etc - middlewares -> auth.go main.go go.mod I dont know its good or bad. But it make easier for me to trace something and so familiar with other projects with different languages.
It sucks because you're grouping by technical concerns. It's better to group by a feature because it's more cohesive and functionality related to "post" isn't scattered all over the project. Your project structure should tell what the application is about.
@@matthewrosseeI will do with inherit in all codes. Sometimes we need nested feature. So I will include in same folder but tell what about of this file. Ex. models -> post_comment.go controllers -> post_comment_controllers.go pages -> post_comment.html
@matthewrossee you have a point but what if your application has only one feature? Then all files would end up in one folder creating a total mess I think such grouping is much better suited for non-microservice project
Not good, because directory=package in Golang, and that means you are grouping code that should be in the same package into different packages and that can create all kind of unnecessary complexity like import cycles and then interfaces needed *just* to resolve import cycles. Think this rule of thumb: If you were to extract any given functionality to use in another app, what files would you need? All those files should then be kept in the same directory/package.
I see an advantage (there might be better approaches too): - if you want to ignore tests while building final go application container image. This reduces your final code base you are delivering. But for easy human consumption when looking at code base, test folder should follow the same structure as main code base, so that it’s easy to relate the relationships between folders and test files to the main code base folders and code files. Maybe someone can add more insights here.
I know you from Prime reacting to your meme videos. :D Just started learning Go after Rust and Python. Looked into Haskell and Zig first. Zig is still not at version 1.0 and Haskell is, well it's Haskell. So I go with Go for now. And the project layout was one of the first things I wondered. This and probably your other videos will help me for sure.
Thank you so much. For last few years I was programming in ruby using rails framework where layout is defined by framework and I was really struggling with figuring out what layout to use.
So this might be a very noob question. Am still a beginner in go coming from a Laravel world (YES I CODE IN PHP). where would you place your middle ware, database related files like configuration,queries and your HTML pages (of course with its assets). so far I have been trying to build a simple crud project and its working well but its terrible in terms of structure and maintenance for a serious project is a nightmare. your guide will be very much appropriated you earned my sub by the way Much love from TANZANIA
Great video, I have learnt a lot. One question, how to create multiple folders with mkdir command on windows powershell? The method you have used on linux does not work.
The layout of opened file is like the one in focus mode. But you have ribbons in that too. I need that one. pls share or just make a video on your dev setup(i know it's pretty classic one but pls its needed.)
1. Nice video 2. I may be dumb, but the first link you put in the right top corner, just takes me to " more from Melkey", which I think you did not intended. I'll put my thinking cap on and find that video, but I wanted to say this maybe it's a bug?!
Yes, there is no need to create directories your project does not need as Go doesn't have as strict of project structure compared to other languages. Of course, there are a few exceptions, but the case you described is not one such.
@@MelkeyDev Just why would one use workspaces in the first place, do I actually need them or not, what is there general purpose of them, that sort of thing 👍
@@pjc825 Workspaces (the Go workspaces) are used when you are potentially working in a Monolith, or a project structure that has multiple non-go sub dirs. For example, you can have your React code in the client folder, while your Go code is in another.
wow, happy see some nice educative golang content. i would love yo see some real world api project with best practices. Just like you would do for some clinet
The biggest annoyance for me has been maintaining go versions and updates. Theres no inbuilt go update latest. you have to know the latest version number and manually manage that, then manually manage env vars which is also gross, I shouldn't have to be touching that imo.
There absolutely is a best way, if you define “best” as “by convention, we’re going to structure the dirs and this way and name the files in this way”. AKA idiomatic.
i can't actually explain why but i like Go. the syntax feels a bit ... i dunno it's sort of like moving from speaking to English to German... everything seems to be in a slightly different order. but i like it
Thank you for video! I have a question related to tests. How can I keep my tests in a separate folder if I want to test not exported (private) function within my package? Anyway, it would be nice to see how you'd recommend organise your tests :) Thanks!
I don't know about separating folders but in principle you should not be invoking private functions. Unit testing should only interface with the public API and treat it's internal calls as a black box.
I honestly agree with you. I have only used internal in my projects (the demo shows that) but the convention for a lot of people was to include pkg as well
This "standard" layout sucks, it's a convoluted mess. Ask yourself this question: Am I developing a library/tool or an application? For application development, there's no "standard" layout, start with the simplest flat project structure and go from there.
Ey Melkey, great video I have been starting up golang for a basic backend with htmx. I am working on building a docker setup around it with a databse and eventually an extra node container for scss Could you perhaps show how you would make a docker setup ( perhaps even with live reload) ? Thnx! Keep on making these golang videos, i accpreciate them a lot!
@@MelkeyDev I have visited your twitch several times couple of years ago. Still love the introduction i got to Obsidian from you. But in all honesty, i like your way of presenting. If you can create a golang series, i will be sure to set the notifications. I like golang, but somehow the content either is: "build this demo/tutorial with me", or loose examples. Most articles on the web ( at least which i have found ) are the same. I am missing the coherence/practical concepts. For example this video. Short, practical, great reusability My request for the docker/golang/mysql is imo also something to benefit for whatever project a dev is going to make.
Recommended this channel and then I hear keep tests in a separate folder. Keep e2e and integration there only. Don't make people search that nest for unit tests..
GO CONTENT IS AWESOME!
I HOPE YOU ALL ENJOY IT.
MAKE SURE TO COMMENT AND SUBSCRIBE- it really means the world
Melky, what do you advise, I just started learning Go as I am new to software dev world, but some what seem confusing sometimes. Topic like Pointers; I am struggling to really understand it deeply, and a few others. Can you advice on howto go about it - recommend materials that can easily break it down for me. I am really interested in learning getting as far as building API's, Micro-services. I know that for a newbie, it seem like a daunting task; i do believe i can achieve it. I am not totally new to IT world, I have worked as a network engineer, and now looking to become a software engineer; Specifically a back-end or full stack. I do have a bit of the basic knowledge of variables, functions, struct, boolean, integer, float etc. i know basic python programming, html, css , docker, i use vagrant as IAC for my private test environment, Linux, basic knowledge of Git & Github, cloud services - aws cloud services, Splunk enterprise software installlation, monitoring and for onboarding data.
I will appreciate your sincere advice? Thank you very much.
And if you could recommend a good trainer that can help with other programming language(JS, Java..etc) along with Go, I will be most grateful
I have been a C# dev for over 15 years and wanted to try something else so a few days ago i picked up a GO course. This video has been a great addition to the other things i have. Thanks.
Well structured video without any water, thanks for your work Melkey!
Absolutely, hope you enjoy it !
Absolute lifesaver.. I was struggling with getting local imports to work after a tutorial refactored code into subdirectories. thank you for this!
My pleasure boss - glad you enjoyed
ok, have to admit - this was useful. I just started going deeper in Go and was missing the point of long import statements. Genuine thank you
Excellent!
3 days ago I started my journey as a go developer. I wanted to learn something new and since I can't find work with my current knowledge of js I decided give a GO haha. This type of content is invaluable for me, thanks Melkey.
Wonderful!
Hi, excellent vid Melkey. We can say that "internal" folder would be the High-Level modules, the code that organization CARES about, the business logic itself. For "pkg" would be the "Low-level modules" the code that the organization does not care about.
The chase is cut at 3:52
I see a lot of projects put a test file right next to the source file / package it's testing, i.e. no tests directory. Not sure I have a strong opinion on one or the other.
just started on go recently and struggling with structuring my project. watched a couple videos on that but seems like opinions are quite contradicting. anyway, great walkthrough, helps a lot
Love Go! let's goo Melkey!!
WOOOHOOO!
I've been coding in go for a while now, and I haven't found a good way to structure complex projects. For example, the lack of sub-packages, means that go code is insanely flat. And that means there is no obvious path to try to decipher the relationship between the packages, and the relationship between the entities in the packages and across packages. So, I often find myself having to hold the entire code deciphered and in my mind simultaneously, and unless I do that, I don't feel confident that I understand anything at all. Even within a package folder, either there is one giant file, or a bunch of file that I don't know which one should be opened first. Do you have an example of a complex go project that you can point to as being really well structured?
Greatest Go content on RUclips GLOBALLY
Continuing this GO TRAIN
GO IS AWESOME!!
I hope you enjoy it.
Make sure to like, comment for MORE GO CONTENT!
You are an imitator and fake of this channel??? Using same icon and name, but are not linked in the official channels list of channels.
Enjoying the content Melkey! I don’t code in Go at all but watching these makes it feel like I could do it tomorrow
Thanks for the descriptioN!
Youre welcome
started learning GO great share Melkey
What if we create a cmd/main.go instead of nesting it within another folder?
Hey bro give me tip how you change your terminal look can you make video because I like your terminal look which is very fancy
Wait... what? Tests in a separate folder? 😳
Mmm first time I see this recommendation, in Go we tend to have the test files next to the code we’re testing.
@@GustavoDiaz93 yeah
@@GustavoDiaz93- Apples and oranges. Units tests in the same directory, integration tests in a ./test directory.
I see an advantage (there might be better approaches too):
- if you want to ignore tests while building final go application container image. This reduces your final code base you are delivering. Just use test files for dev & testing phase.
But for easy human consumption when looking at code base, test folder should follow the same structure as main code base, so that it’s easy to relate the relationships between folders and test files to the main code base folders and code files.
Maybe someone here can provide more insights.
@@gearboxworksYeah
Can you make a video on or share resources for Unit Testing in Go? Specifically, code coverage reports on a Windows machine.
When I create go project. I always follow MVC like PHP framework folders.
- routes -> routes.go
- models -> post.go
- databases -> database.go
- controllers -> post_controllers.go, etc
- views ->
- layouts -> layout.html
- pages -> home.html, about,html, etc
- middlewares -> auth.go
main.go
go.mod
I dont know its good or bad. But it make easier for me to trace something and so familiar with other projects with different languages.
I'd do the same too
It sucks because you're grouping by technical concerns. It's better to group by a feature because it's more cohesive and functionality related to "post" isn't scattered all over the project. Your project structure should tell what the application is about.
@@matthewrosseeI will do with inherit in all codes. Sometimes we need nested feature. So I will include in same folder but tell what about of this file.
Ex.
models -> post_comment.go
controllers -> post_comment_controllers.go
pages -> post_comment.html
@matthewrossee you have a point but what if your application has only one feature? Then all files would end up in one folder creating a total mess
I think such grouping is much better suited for non-microservice project
Not good, because directory=package in Golang, and that means you are grouping code that should be in the same package into different packages and that can create all kind of unnecessary complexity like import cycles and then interfaces needed *just* to resolve import cycles.
Think this rule of thumb: If you were to extract any given functionality to use in another app, what files would you need? All those files should then be kept in the same directory/package.
Can you explain why you prefer to keep tests in a separate folder instead of next to the files they are intended to test? Just curious.
I see an advantage (there might be better approaches too):
- if you want to ignore tests while building final go application container image. This reduces your final code base you are delivering.
But for easy human consumption when looking at code base, test folder should follow the same structure as main code base, so that it’s easy to relate the relationships between folders and test files to the main code base folders and code files.
Maybe someone can add more insights here.
what is your guake theme?
This is why more people need experience with battle-tested monolithic frameworks like Rails or Django
Why
2:57 felt personally attacked
Hey what about the embed package? I don't think it's possible to embed static files outside of cmd directory or handlers.
it says adjust this project/package1/package2/package3 to project/package1, project/package2, project/package3
I know you from Prime reacting to your meme videos. :D
Just started learning Go after Rust and Python. Looked into Haskell and Zig first. Zig is still not at version 1.0 and Haskell is, well it's Haskell. So I go with Go for now. And the project layout was one of the first things I wondered. This and probably your other videos will help me for sure.
Welcome aboard!
Thank you so much. For last few years I was programming in ruby using rails framework where layout is defined by framework and I was really struggling with figuring out what layout to use.
So this might be a very noob question. Am still a beginner in go coming from a Laravel world (YES I CODE IN PHP). where would you place your middle ware, database related files like configuration,queries and your HTML pages (of course with its assets).
so far I have been trying to build a simple crud project and its working well but its terrible in terms of structure and maintenance for a serious project is a nightmare. your guide will be very much appropriated you earned my sub by the way Much love from TANZANIA
The go guy
I started switching to go we need more tutorial and projects 😂
OKAY!
What do you want to see?
@@MelkeyDev my an entire crash course of web api creation with go MySQL (with auth too)
Or a simple project 😁
I charge like 50% extra amount when I have to work on a project with this structure.
Great video, I have learnt a lot.
One question, how to create multiple folders with mkdir command on windows powershell? The method you have used on linux does not work.
I am not sure - I dont develop on Windows. I don't recommend it
This video was so good I got promoted to cto instantly
Auto billionaire
Wow man. You just demistified a lot for me. Thank you
AYe - thats awesome!
In Go, why functions name should be in PascalCase, why lib/dependency called package
whoa 10k subs already, way to go
🎉
The layout of opened file is like the one in focus mode. But you have ribbons in that too.
I need that one. pls share or just make a video on your dev setup(i know it's pretty classic one but pls its needed.)
just disable vscode activity bar, or enter focus mode and key Ctrl + Shift + E
Do we gitignore the bin directory? Considering that the contains the output build, we wouldn’t wanna track that in version control right?
this doesn't look like ocaml?
This is CSS
1. Nice video
2. I may be dumb, but the first link you put in the right top corner, just takes me to " more from Melkey", which I think you did not intended. I'll put my thinking cap on and find that video, but I wanted to say this maybe it's a bug?!
Oh my.
I am SO sorry.
ruclips.net/video/OCotIc2Ah_0/видео.html&t
This is the video. Thank you for catching that!
@@MelkeyDev I’m something of scientist, and I found it myself. View it, liked it. Thank you sir! Cheers!
Why the hate on nesting packages?
Thanks for making such awesome content, what’s your prefer way to deploy go apps, can we have a video on that if possible
Coming soon!
Dope vid as always super helpful
Appreciate it!
Do you have any suggestions for handling a go monorepo?
It is typically the same structure, just with more sub directories within the /internal
can i delete my test folder if i do not use it?
Yes, there is no need to create directories your project does not need as Go doesn't have as strict of project structure compared to other languages. Of course, there are a few exceptions, but the case you described is not one such.
I have a question, like in JS/nodejs we have a folder thats specific to a project called "node_modules", don't we have something like it in golang?
The "vendor" folder?
No provided code repo?
Can you please create a video discussing Workspaces and there uses. Thanks for the great content 💯😃👍
Yeah - for sure But what do you mean? Can you be more specific?
@@MelkeyDev Just why would one use workspaces in the first place, do I actually need them or not, what is there general purpose of them, that sort of thing 👍
@@pjc825 Workspaces (the Go workspaces) are used when you are potentially working in a Monolith, or a project structure that has multiple non-go sub dirs. For example, you can have your React code in the client folder, while your Go code is in another.
Is golang useful for data science? I know python has all the libraries but its slow. Could golang fill in the gaps of python?
Great question.
I personally dont think so.
I think Python will be the data science language for a while.
Or Julia
very useful. Thanks man
wow, happy see some nice educative golang content. i would love yo see some real world api project with best practices. Just like you would do for some clinet
Many many thanks
The biggest annoyance for me has been maintaining go versions and updates. Theres no inbuilt go update latest. you have to know the latest version number and manually manage that, then manually manage env vars which is also gross, I shouldn't have to be touching that imo.
Keep up the Golang videos!
I have watched this video couple of times and "you guys don't write tests 😂" always get me rolling
Amazing content !
Maybe it's a useless question but is it better to use Gin or Go the hard way to build a full Rest API ?
i mean, you can definitely use Gin but I think using Go built in lib is nice!
@@MelkeyDev Yeah it's definitely what I did, builtin lib and no ORM to learn the basics of the language 😃 Thank's for the answer 😀
amazing!
thanks
No problem
There is no a “best” way to structure your projects.
THERE ABSOLUTELY IS
but there are many terrible ways to structure codebases. Gotta keep the WTFs/min low.
We have a new videos series idea .
How to not structure your go projects
There is but its project dependent.
There absolutely is a best way, if you define “best” as “by convention, we’re going to structure the dirs and this way and name the files in this way”. AKA idiomatic.
Great Video! I learned a lot. But why does all the module need to have the github prefix ?
They dont! Just if you want to make them public its a common pattern to do it like that
Just to clarify, we do test.
In production.
Tell my PM I said Hi
i can't actually explain why but i like Go. the syntax feels a bit ... i dunno it's sort of like moving from speaking to English to German... everything seems to be in a slightly different order.
but i like it
Thank you for video!
I have a question related to tests. How can I keep my tests in a separate folder if I want to test not exported (private) function within my package?
Anyway, it would be nice to see how you'd recommend organise your tests :)
Thanks!
I don't know about separating folders but in principle you should not be invoking private functions. Unit testing should only interface with the public API and treat it's internal calls as a black box.
And if I do not use github ...?
I agree with everything except the pkg directory. For me it creates an unnecessary indirection.
I honestly agree with you.
I have only used internal in my projects (the demo shows that) but the convention for a lot of people was to include pkg as well
Heyy Melkey, wonderful video. Very helpful. Would like to create a realistic REST api targeting prod making use of this structure with you 😺
This "standard" layout sucks, it's a convoluted mess. Ask yourself this question: Am I developing a library/tool or an application? For application development, there's no "standard" layout, start with the simplest flat project structure and go from there.
👆
Love you melkey
I love you too thank you
Writing Go for a living. I am jelly.
You can do it too!
nice job
GOPATH vs go module really make me confused
Ey Melkey, great video
I have been starting up golang for a basic backend with htmx.
I am working on building a docker setup around it with a databse and eventually an extra node container for scss
Could you perhaps show how you would make a docker setup ( perhaps even with live reload) ?
Thnx!
Keep on making these golang videos, i accpreciate them a lot!
Air is really good I do recommend
Sounds great!
I will do that. Docker + Go + Air coming right up
@@MelkeyDev I have visited your twitch several times couple of years ago.
Still love the introduction i got to Obsidian from you.
But in all honesty, i like your way of presenting. If you can create a golang series, i will be sure to set the notifications. I like golang, but somehow the content either is: "build this demo/tutorial with me", or loose examples.
Most articles on the web ( at least which i have found ) are the same.
I am missing the coherence/practical concepts.
For example this video. Short, practical, great reusability
My request for the docker/golang/mysql is imo also something to benefit for whatever project a dev is going to make.
Recovering Rust developer here.
so it's unconventional to have main.go at the actual root of the project?
😅 I need to learn Go. I think Backend dev is adding Go to their courses.
Go is the BEST
Maybe it is only down to the guys, because I am really keen on testing!! 10:53 #GirlsInTech #WeGotPower
Ackshually, on Linux theyr'e called directories not folders
lmfao get out of here
Recommended this channel and then I hear keep tests in a separate folder. Keep e2e and integration there only. Don't make people search that nest for unit tests..
"I know you do not create test"
that's not me. i created the folder test
then delete it after 5 seconds.
Why is the one tag neovim 😂
All these kids talking about Pokemon Go need to Pokemon Go write some Go
Personally I don’t like having a test directory, the tests should be near the source code with a _test name
Unit tests should be near the code, integration tests should be in their own directory.
Use Arch btw
nice,,, but, plz proceed with more hands on.... then it would be better for the audience. Ty
Go 1.22 have router wildcards \m/
Oh HELL yes i didnt know this
@@MelkeyDev I mean.. Go, not Docker.. xD
More go content
HTMX +SVELTE+GO booom make it happen
All you have to do is click the big blue button then booom!!! you are hoocked 😅
Man please zoom in 😂
You don't know me, my company and i always force to create tests every fk time.
I didn't recognize you with the mustache.
"recovering rust developers" 🤣🤣🤣
Wait what, do you actually test??? Lol
Ok in a serious note, you should make a video on go testing
I will! Thank you
Thanks Mr. VS C*de user.
4:00 for the actual point (typical bro-tubing bro-grammer taking forever to get to the point)
I almost killed myself while trying to arrange my golang project
Hey windows is pretty nice ok
psch
half asleep still, been trying to write something witty as comment...I got nothing. I failed myself.
Hi dad
Hey son
3:50
what the f is "test"? this is the firs time I am hearing this word.
4:10