How I Structure New Projects In Golang

  Рет қаралды 65,571

Anthony GG

Anthony GG

Күн бұрын

Пікірлер
@anthonygg_
@anthonygg_ Жыл бұрын
► Join my Discord community for free education 👉 discord.com/invite/Ac7CWREe58 ► Exclusive Lessons, Mentorship, And Videos 👉 www.patreon.com/anthonygg_ ► 50% OFF on my Golang course 👉 fulltimegodev.com Thanks for watching
@apoorvgupta9680
@apoorvgupta9680 Жыл бұрын
what is @ 7:44 ? in make file
@omgItsGreg
@omgItsGreg Жыл бұрын
God I wish I had your mindset... you just stick to whatever works best for you.. I always look around and doubt my choices, thinking there is a better way of doing it, and then getting stuck on simple things.
@anthonygg_
@anthonygg_ Жыл бұрын
I always keep things simple, but, always eager to steal other patterns and utilize them when they make sense.
@jhjacobs81
@jhjacobs81 Жыл бұрын
You’re not alone :( and always there’s the next best framework to try, exhausting 😂
@quandaledingle9127
@quandaledingle9127 11 ай бұрын
Your biggest critic is going to be yourself
Жыл бұрын
Please, record a video about unit tests in golang, the best practices, how to mock things, how to achieve 100% coverage when we have things like database or external calls. Which kind of tests (unit, integration, e2e, etc.) real projects used to write in golang's universe? It's a content that is hard to find in a unique video. Thanks for your great job.
@manfrombritain6816
@manfrombritain6816 10 ай бұрын
this is the real shit. people focusing on coding tutorials... coding is the simple part. proper structure, testing, integration, devops... this is harder to learn imo. especially before doing it on the job
@RogueAfterlife
@RogueAfterlife 10 ай бұрын
Consider the case of testing log writes to standard output vs writes to a file. Unit testing ensures the output from the logger is what I expect whereas integration tests ensure the log line was written. These illustrate fundamentally different testing scenarios. I don't think mocks are useful in unit testing. Tests written in Go are for Go code. Although it might be tempting to use Go's testing framework for integration tests; writing tests concerning external systems is non-trivial because, the scope of the test expands combinatorially to what ever the dependency outputs. If I'm writing tests for my SQL schema, for example, I would write a separate program to test just that and maybe that program would be written in Go!
@vickylance
@vickylance 8 ай бұрын
@@manfrombritain6816 We use pact testing along with unit testing which is way much better than writing integration tests
@themaridv2000
@themaridv2000 7 ай бұрын
Yeees, please!
@Steliosgiannatos
@Steliosgiannatos 3 ай бұрын
Very refreshing to see an actual working project how it works on a structure level. I also like your approach, there is no perfect solution just compromises on different things!
@vcothur7
@vcothur7 Жыл бұрын
I have been searching for a good structure for my go backend that I have for my website, and you decided to post this. Thank you!
@francesctravesa
@francesctravesa 11 ай бұрын
So all the types are public? not a little bit of encapsulation with some information hiding? like smart creators to make sure the structs are always in a valid state? Some rich domain then at least? and when you want use some inverse dependency injection and clean architecture? I think there must be a smart way to implement all of these best practices with go?
@anthonygg_
@anthonygg_ 11 ай бұрын
Stop thinking. Start pressing buttons. You are behind.
@Jackbeti
@Jackbeti Жыл бұрын
Hey Anthony. Why do you think most organizational projects prefer clean architecture over hexagonal architecture? If possible, could you provide an example project implementing hexagonal architecture?
@viveksingh9223
@viveksingh9223 9 ай бұрын
Can you tell me what theme you are using?
@anthonygg_
@anthonygg_ 9 ай бұрын
Gruvbox
@Insomn3s
@Insomn3s Жыл бұрын
Your videos are priceless as an example of "practical developer approach"
@ta5alof297
@ta5alof297 11 ай бұрын
You don't need a separate schema between migration and SQLC. I'm using goose for migrations and SQLC supports it out of the box.. 1 directory for migrations which contains the schema changes.
@shravan2891
@shravan2891 10 ай бұрын
why didn't you use this structure in you fulltimegodev course
@anthonygg_
@anthonygg_ 10 ай бұрын
Because we are free.
@iliassglitch
@iliassglitch Жыл бұрын
Thank you so much for these videos Anthony.
@rezaklink401
@rezaklink401 11 күн бұрын
Your channel is amazing, the people who get to work with you are seriously lucky my brother 💪
@anthonygg_
@anthonygg_ 9 күн бұрын
Thank you
@garbagechannel6514
@garbagechannel6514 Жыл бұрын
I noticed everything is very flat. Im used to having subfolders in my project coming from C#. It's a bit harder to do in Go because namespaces are not a thing. So should it be flat and end up with a ton of files in a module, as well as many modules or would you say its ok to have nested folders?
@anthonygg_
@anthonygg_ Жыл бұрын
The problem in Go with a lot of nested folders is circular dependencies.
@garbagechannel6514
@garbagechannel6514 Жыл бұрын
@@anthonygg_ yes, i already ran into that :P i suppose i just have to get used to a flatter structure with Go
@anthonygg_
@anthonygg_ Жыл бұрын
@@garbagechannel6514I also learned that the hard way 😂😢
@Programming-lr1nb
@Programming-lr1nb Жыл бұрын
"Is it a way to go? Pfft. I have no fucking clue" is my new life credo
@charlesbcraig
@charlesbcraig Жыл бұрын
AGG: if you have a performance issue, congratulations you’ve made it Me: 😁 AGG: But most of you won’t Me: 😭
@Simple_OG
@Simple_OG 7 ай бұрын
Anthonyy what theme are you using it lokks so cool
@anthonygg_
@anthonygg_ 7 ай бұрын
Gruvbox
Жыл бұрын
Thank you for great video. I really like your approach with simplicity. I'm just learning Go for my hobby projects. And you are helping me so much. (Btw at work we are using C#)
@tirumalraot
@tirumalraot Жыл бұрын
4:36 "Which in your case, in most of the cases it never be!" That actually hurts
@JohnSchuhr
@JohnSchuhr Жыл бұрын
Yeah, I felt it too - 😂
@kazimir9576
@kazimir9576 Жыл бұрын
yeah in 04:00 u are right, ppl very often tend to overcode, over complicate everything just because they think its how it must be done, "book way". and spend 1 week on doing smth that for business does not matter. They need to understand its a business, and if you spend a lot of time just because you want smth make 5ms faster, try to tell the business how much money it cost for them to gain 5ms faster api call for some profile update etc. ;)
@ekallivrousis
@ekallivrousis 10 ай бұрын
Hey Anthony, thank you for this video, the way you describe things is just so real if that makes sense. Im new to the Go world and project structure is always a huge mind blocker for me. Do you happen to have a public repo of the above structure? I wanted to go through it more, i really like how clean it is the only thing i dont think i follow is the global db instance. Now i know you said this in video and its just all in how it works for you and your team. I personally only use go for personal projects and i rely on the test files to make sure i dont break as much as i can. That includes the database. I setup tests to confirm that basically im getting data back from the database. Is this still possible with a global database?
@anthonygg_
@anthonygg_ 10 ай бұрын
Better not to is a better practice
@Ярослав-о5б6т
@Ярослав-о5б6т Жыл бұрын
Great video! Antony tell me the name of the vscode theme please
@ibraim3197
@ibraim3197 Жыл бұрын
You are wrong about performance. It doesn't always come with a large user base, it's also can be a consequence of inefficient DB-layer (N+1 query etc) or algorithms
@joef7884
@joef7884 Жыл бұрын
You're right, but in the specific context of "which framework should I use" which is what he was talking about, generally each framework isn't going to make one of those mistakes; it will still be up to you the developer to use them wisely with good algorithms and queries.
@fernandoacorreia
@fernandoacorreia 7 ай бұрын
He was talking about the relative performance of different web frameworks. He is correct.
@lancemarchetti8673
@lancemarchetti8673 11 ай бұрын
I have an idea for a new method of digital Steganography whereby a lager image can be hidden in a smaller one without changing the filesize or quality of the host image. Will Golang work better to build this app in Windows, or should I battle it out with JS and html? . I'm totally new to programming so it feels like I've just thrown myself into the deep end.... lol
@ZenonCreations
@ZenonCreations 6 ай бұрын
dont you use DTOs in go lang backend development?
@virility
@virility Жыл бұрын
hey anthony, what laptop do you use?
@anthonygg_
@anthonygg_ Жыл бұрын
I use a desktop. Custom build
@virility
@virility Жыл бұрын
@@anthonygg_ what about when you r traveling? Do u carry ur desktop around you when you travel?
@anthonygg_
@anthonygg_ Жыл бұрын
I have a macbook (old one)
@eyob7232
@eyob7232 Жыл бұрын
I highly disagree with global variables, I believe creating a singleton and passing it as a parameter is a better choice. I agree with you having a dedicated folder for queries, and data related stuff, but I would call that folder repository or sth like that, data is a bit too general, just my 2 cents.
@anthonygg_
@anthonygg_ Жыл бұрын
Data is indeed general. But repository sounds so cringe. The global db, yeah, sometimes we need to close our eyes.
@ekeminios
@ekeminios Жыл бұрын
Thanks for sharing Anthony! Well explained and detailed.
@comedyclub333
@comedyclub333 Жыл бұрын
Also, on the performance argument: As you said, performance doesn't matter (most of the time). If performance is your bottleneck (as in really being an issue) you probably did something horribly wrong when deploying your app. No framework swap is going to change that. I mean, many people (and also big companies) use python, one of the slowest languages known. Because you save a lot of money when developing the app and if performance is an issue you just throw the money you saved onto your deployment infrastructure to make it work.
@caiomartins8255
@caiomartins8255 4 ай бұрын
Excellent video, thanks. Btw What is his vs code theme ?
@d_andreev
@d_andreev Жыл бұрын
Nice initial project structure! Btw, how are you testing business logic inside the pkg folder? Are you using some kind of dependency injection?
@varyous_ch
@varyous_ch Жыл бұрын
Could you show an example of a microservices structure with Docker/k8s? Just curios how would you do it :)
@frankfix247
@frankfix247 8 ай бұрын
Drop the plenum naming in packages and the infamous util package. This is according to the Golang docs.
@anthonygg_
@anthonygg_ 8 ай бұрын
Ok franky
@frankfix247
@frankfix247 8 ай бұрын
@@anthonygg_ It wasn't meant to be sarcastic. Keep up the good work!
@dejanduh2645
@dejanduh2645 Жыл бұрын
Is there a link to this project or this project structure? Looks very clean
@mrlectus
@mrlectus Жыл бұрын
My OCD says I need everything to be organized and properly structured
@ralphlorenzo9473
@ralphlorenzo9473 Жыл бұрын
What do you think of the new routing as of version 1.22?
@karolkotula9279
@karolkotula9279 Жыл бұрын
Hi Anthony. Really great stuff here! It's of excellent quality. Can you please start swearing in your native language? :D I guess it would be even more fun to watch your vids :) THANK YOU !!!
@anthonygg_
@anthonygg_ Жыл бұрын
Ok I will try that
@TrzyTukany
@TrzyTukany Жыл бұрын
Only using your native, you can be truly "authentic" :) Like delicate seasoning in your food (for thought) :D
@zzej
@zzej Жыл бұрын
wait.... how can golang render svelte? that would be awesome. or is it svelte as an SPA?
@nivethan_me
@nivethan_me Жыл бұрын
front-end with Svelte and backend with Golang i guess.
@sheraztariq8973
@sheraztariq8973 7 ай бұрын
use ent for database and kudos for good explanation, i was having hard time for structuring my project
@jalbers3150
@jalbers3150 Жыл бұрын
Would love to see how/where you deploy all this. Do you do managed db’s and stuff like that for production?
@rw_panic0_0
@rw_panic0_0 Жыл бұрын
what means "handlers" if your program works with not only http, but with websockets and kafka? Are these kafka handlers, http or websocket handlers? What if your types are not just structs but full domain models with methods interfaces etc? What if I have a lot of types, finding a type will become a problem. For a man who just got into the codebase there are no clear difference between "data" and "types". Util folder have to probably be split up into encryptuitl etc. I don't think this is a scalable project structure. However I agree that going with DDD or hex arch is a bad idea, your structure works PERFECTLY good for small projects. But I personally find splitting program into packages (multiple "feature-sliced" packages which have their own types, data, and util) and being explicit about your naming (types, util, handlers are pretty vague) is most important thing, because being vague and putting similar functionality in different places is the thing that makes project structure unscalable.
@anthonygg_
@anthonygg_ Жыл бұрын
Like I mentioned in the video, this is how it is right now, but probably subject to change in the future. Happy to share that later
@Dsouza10082
@Dsouza10082 Жыл бұрын
Amazing as always.
@collapser_team
@collapser_team Жыл бұрын
Can you share this project, please?
@anthonygg_
@anthonygg_ Жыл бұрын
I cant or I go to jail
@collapser_team
@collapser_team Жыл бұрын
just a template without NDA stuff (and you have already showed the content oops)@@anthonygg_
@dejanduh2645
@dejanduh2645 Жыл бұрын
Is there a link to the source code?
@Benony91
@Benony91 10 ай бұрын
17:46 `AumMax50Million = “10-15mil”` is this a bug?
@WaldirBorbaJunior
@WaldirBorbaJunior Жыл бұрын
Wow... blazing amaze, could you please share your start project ?
@AbdulRehman-pb5od
@AbdulRehman-pb5od Жыл бұрын
I use fiber only bcz they have best documentation I have ever came through.
@manpt123
@manpt123 Жыл бұрын
I still often ask myself if I am writing golang in standard way😂 thank you for the video 🎉
@kurtlee138
@kurtlee138 10 ай бұрын
didnt know the rock makes programming videos
@anthonygg_
@anthonygg_ 10 ай бұрын
Years of wrestling and testosteron abuse made me look for something more subtle.
@salihbozkaya9357
@salihbozkaya9357 Жыл бұрын
Dad, where did you been all those times.missed you
@D3FKONMusik123
@D3FKONMusik123 Жыл бұрын
Hey Anthony. Your videos have a lot of value, but they are usually structured so poorly and runs for so long that it's hard to follow for more than a couple of mins. But really appreciate all the value
@anthonygg_
@anthonygg_ Жыл бұрын
Correct this channel is not for the weak. Sorry my man.
@D3FKONMusik123
@D3FKONMusik123 Жыл бұрын
@@anthonygg_ That makes a lot of sense. Congrats!
@ScienceForToday-lm7nb
@ScienceForToday-lm7nb 10 ай бұрын
Thank you for this video.
@woodmanmade
@woodmanmade Жыл бұрын
"Models belong on the catwalk" 🤣
@sjzz
@sjzz 8 ай бұрын
I just follow my JS folder pattern controllers, service, routes, middleware etc
@Mari_Selalu_Berbuat_Kebaikan
@Mari_Selalu_Berbuat_Kebaikan 10 ай бұрын
Let's always do alot of good ❤️
@bandr-dev
@bandr-dev Жыл бұрын
"a drop pkg in cmd that drops all the tables with a sql command" HUHHHHHH???? How is any of those folders in the cmd folder good organization
@深夜酒吧
@深夜酒吧 Жыл бұрын
leave a mark here, so remind me watch it later on
@anthonygg_
@anthonygg_ Жыл бұрын
Reminding you to watch
@iamsupriyo
@iamsupriyo Жыл бұрын
Bro came back
@pattyspanker8955
@pattyspanker8955 Жыл бұрын
Remind me to remind user he has a reminder to watch this video
@dencasio6141
@dencasio6141 Жыл бұрын
util?
@fluctura
@fluctura Жыл бұрын
Data is where your data belongs to. For example seed data. Model is where you save what model/shape your data has. So yeah.. that I think was the original idea behing that common sense project layout Nowadays your data is stored on S3 or whatever.. but if we are splitting hairs, why not putting your db and migrations into data folder as well? 😅 its data too 😮😂
@XxMissingDataxX
@XxMissingDataxX Жыл бұрын
Very nice
@yarbersheer8559
@yarbersheer8559 9 ай бұрын
Man, just use goose for migrations)
@anthonygg_
@anthonygg_ 9 ай бұрын
Facts
@MrMu2sS
@MrMu2sS 10 ай бұрын
French devs will cry in ddd
@krq999
@krq999 Жыл бұрын
Can you post something related to sql databases? Generators, creating records, relations etc
@ibrahimkoz1983
@ibrahimkoz1983 8 ай бұрын
This structuring is away from the best practices and the philosophy of packages. You should not organize your based on technical details. Packages should be organised based on layers, not for grouping.
@anthonygg_
@anthonygg_ 8 ай бұрын
True. But how many revenue does your company make?
@ibrahimkoz1983
@ibrahimkoz1983 8 ай бұрын
@@anthonygg_ disappointed. I was following you for a long time, learnt a lot from you. You replied with a fallacy :/
@anthonygg_
@anthonygg_ 8 ай бұрын
I just said you are right.
@arielsashcov99
@arielsashcov99 Жыл бұрын
Exactly what I was searching for
@Buiscit1738
@Buiscit1738 Жыл бұрын
dopamine!
@luciancristianpop2735
@luciancristianpop2735 Жыл бұрын
In the first minute you're asking for the thumbs up and subscription, no matter the content, this is rude.
@anthonygg_
@anthonygg_ Жыл бұрын
But was it worth it?
@whtkeys8190
@whtkeys8190 Жыл бұрын
Really bad bro
@DoktorKumpel
@DoktorKumpel 10 ай бұрын
I thought with go build you have to specify each package. how come you only specify cmd/api/main.go?
@RubberGopher
@RubberGopher 3 ай бұрын
My comment makes the assumption that module mode is enabled. So "go run" will look for "go.mod" in the current directory or any parent directory and uses that to discover the module and its name. It can then discover the location of all the imports for the module with the help of the module information. As you import a module and/or any of the module's packages, it will discover all the files in those packages and you can simply import and use whatever is exported in the package. In this case, where he just points to ./cmd/api/main.go, will cause it to not find other files in ./cmd/api so adding additional files that main.go relies on will cause an error. The better approach is to just point to the main package and not the file, i.e "go run ./cmd/api" and it will discover all the files in it and it will build regardless whether there is only one or many files, as long as it's able to find "main.main()". The filename "main.go" has no meaning other than being helpful to humans for get a hint of what it contains. Having a main.go in other packages (not main) is not helpful unless there is something called main in there too. Giving your files good names is as important to you as naming variables and packages. If you don't know what to name a file, just seek inspiration from the name of the package or the name of whatever type or function you have in the file. If you have main.go in the root of your module, you can just do "go run ." and it will be happy.
@MCDyma
@MCDyma Жыл бұрын
And again you are in GoWeekly #​480 - OCTOBER 17, 2023 Congratulations
@anthonygg_
@anthonygg_ Жыл бұрын
Ha thanks 🙏
Golang And Svelte  - Swapping To Server Side Rendering
1:27:49
Anthony GG
Рет қаралды 7 М.
How To Structure Your Golang (API) Projects!?
20:28
Anthony GG
Рет қаралды 50 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Mastering Dependency Injection In Golang
14:29
Anthony GG
Рет қаралды 53 М.
How To Build And Structure A Microservice In Golang?!
23:03
Anthony GG
Рет қаралды 55 М.
How to start a SOLID Golang backend project
7:51
Bits of Mandal
Рет қаралды 5 М.
This Is The BEST Way To Structure Your GO Projects
11:08
Melkey
Рет қаралды 84 М.
3 Golang Tips For Beginners I Wish I Knew Sooner
13:18
Anthony GG
Рет қаралды 50 М.
Structure Your Golang Service With Layers Like This
7:59
Anthony GG
Рет қаралды 15 М.
FULL Introduction To HTMX Using Golang
2:02:31
ThePrimeagen
Рет қаралды 403 М.
The standard library now has all you need for advanced routing in Go.
13:52
Rob Pike: What Golang Got Right & Wrong
29:23
ThePrimeTime
Рет қаралды 153 М.