👉 Join the Discord community for blockchain, distributed systems, Golang, and Rust education: discord.gg/bDy8t4b3Rz 👉 Support me on Patreon for even more exclusive videos, vlogs, and tutorials: www.patreon.com/anthonygg_ The code can be found on GitHub: github.com/anthdm/gobank Thanks for watching
That is the best tutorial I have seen in my life, this is actually what happens and how we build applications. All tutorials that I have watched all examples were already preprogrammed, and the professor never shows how it is real process of building application. I really loved these 5 Go videos.
About the "_" (underscore) in imports - Generally used when you want to load a library and run its scripts without having anything to do with what it returns. Great series of tutorials. You are amazing!
In a few hours, I followed the first two videos today. I tried to take my time to fully understand and it's really incredible how much we did in two videos! You're a killer Anthony!
Thx for the video man, really helping to absorb the experience for my go development. When starting on a new language the best way to learn how to do things is to see how other people does, and not try to push my own way of thinking coming from other languages.
I'm quite new to golang, but have programmed in a lot of languages during time, starting with pascal, C and assembler all the way back in the late 80'ties. I'm starting to like golang, as it reminds me a bit about the "old" stuff, but with all the annoying stuff filtered away and some of the new stuff put in instead. I like way you explain it, as it doesn't seem to be a rehearsed thing you did before, and just copy/paste it. That make the video more interesting, as it's more real world kind of doing it. That makes it more fun and not just like a bunch of overheads thrown in your face 🙂 So, thanks for the good work :-)
Tip: If you create a type serial on your postgresql table, it actualy create a sequence to that column and the default value will be aways a nextval(''table_name_column_name_seq'), is really good for ID's and sequencials, but in this example for a balance, every time you insert a account if you not specify balance = 0, the balance will be the nextval of the sequence xD Thanks for this video btw, you are helping me alot :D
The problem was not with w.Header().Set() or .....Add() it was with you had to call w.WriteHeader(status) after setting content type. Great content. Thanks.
Thank you for sharing those things! I'm not good at English, but I've finished making this project with your video! Actually, I don't grasp how the framework works under the hood so far. These days, I'm trying to read the framework or library code to understand how it works under the hood. Thank you, Anthony. It's a really nice lecture I've ever seen before, To learn how to make a REST API Server with Go! I wish that If I were good at English, I'll make the lecture like this!
You are really magic person. Thanks Anthony. I wish I could be a premium member and could buy your course. Anyhow, really really appreciate your efforts. I'm learning a lot.
we are importing the postgres driver like this because we are using the api provided by golang so the package job is to register the postgres driver to the go standard sql api
"you are a package slave, you don't know shit" *googles SQL create table command* haha love this series, you've got a great teaching style I'm learning a lot. BTW, I've got an annie pro 60% and the backtick is FN+esc on there
Yooh Anthony, amazing video and content like always!! By the way the thing ` in the 60% key board you get by using Fn + ESC, at least thats in mine a 60% US Layout and I use the USA international for the language lol Cheers and thank for the video!!
Anthony is funny as hell.... "Don't be package slave , lets say the world explode and there are no packages anymore then you screwed". ... so so true i could not stop laughing. ..... kiakiakia kiakiakia. .... love u man
the issue for the headers not being set wasn't changing it to add , the issue was we can only set the headers once , in our function , any subsequent changes aren't displayed . So moving it to the top , made it work
15:36 What about using a migration tool to create your database structures? I use the Soda CLI and Fizz DSL from the Gobuffalo project with great success. Migrations are easy-peasy after the initial hurdle of learning the DSL. Edit: _I already know how to write the queries in plain SQL, so if the objective is to learn SQL while you're also learning Go this might not be a good idea..._
Great learning experience. Any non-web based projects you recommend to get confidence in golang? I am picking up some Python book and trying to solve problems in Go. Many golang books don't have exercises..
Not sure if this will be answered later but how do you differentiate between handleGetAccount and handleGetAccountById? Because the thing that kind of routes the endpoints to the function is the handleAccount function and there you say: If the method is r.GET, it should return handleGetAccount. Wouldn't that mean handleGetAccountByID is never used?
I didnt find out why u just used pointer for accounts, I saw ur video about pointers but now what is benefit of pointer recivers ? I think u can use value reciver
the underline is actually to tell the compiler that you are not using the lib itself, just its side effetcs, under the hood the db.Sql uses the driver to connect with the postgres, we do not explict use it on our code xD
I know this is ultra noob but I'm commenting here incase somebody runs into this issue. Doing this exercise on windows and I constantly kept getting this error " pq: password authentication failed for user "postgres" ". Turns out I already had postgres (not through docker) running on port 5432 for another project and that was being accessed when I tried connecting to the docker postgres instance and hence the incorrect password.
Isn't there a difference between new(Account) and &Account that the &account is a pointer on the stack? and new on the heap? That's a difference in C/C++ anyways and you may the be referencing a pointer that went out of scope. So I would opt for new from my C++ background. Or use & only for objects that are created in pain and pass around that pointer.
The problem with JSON was not because of Add or Set but because of the order of the functions calls. "WriteHeader SENDS an HTTP response header with the provided status code" - description from stdlib. So by the moment you set the header application/json, response is sent as I understand
@@anthonygg_ I was talking about the struct PostgresStore, btw yes understood thank you. Creating that struct you can gracefully handle the db connection in the NewPostgressStore func, and then of course you will be able to have several different stores such as MongoStore. Btw I really appreciate your coding style (even though i'm still learning) and your teaching style!
2 ปีที่แล้ว +1
Hey Anthony, for the backtick try the following combination: Alt + 96
Hi, quick question would it be fine to modify Server struct like port, usersStore, transactionsStore, secrets. Can we break single store in multiple beacuse if we have 20 methods on interface it will be difficult to test it ?
Now we should all get idiomatic with Postgres 🐘 Anyway your presentation style makes me want just to get down to doing things and not seek the nonexistent perfect!
May I ask why you name all your packages as "main"? Isn't it more easy to understand code and maintain it using different package names so that you can know which code comes from those? Just learning the lang.
he talks about it in the first part, I would add that it's far easier to split in modules once you have a good idea of the parts that your application is gonna involve, not before
if anyone is not getting the right format of the response in post or in your localhost browser, try putting double quotes for the types like this ID int `json:"id"` FirstName string `json:"firstName"` LastName string `json:"lastName"` Number int64 `json:"number"` Balance int64 `json:"balance"` CreatedAt time.Time `json:"createdAt"` like this,the current version of Go does not support the old formatting method, use this format whenever declaring types. Cheers
Never actually showed how to get the new ID out of the database, or return the newly created account via the API. Feels like you lost heart in this. Shame
Love the stuff your teaching, but damn it's unbearable watching you. Just spamming keyboard to look fast, making more typos than actually right ones, like slow down man..
working through your examples, but having a problem with packages in different files, my normal structure... go.mod go.sum main.go I normally dump all code into main.go, but I'd like to maybe create a api packages and a types package and utils package As I understand that would mean a api, types and utils sub directory under cmd and I then do import of "api" "types" and "utils" issue, when done like this then the code in main.go that's trying to call the func's in api, types and utils errs out saying it can't find... please helpppp
👉 Join the Discord community for blockchain, distributed systems, Golang, and Rust education:
discord.gg/bDy8t4b3Rz
👉 Support me on Patreon for even more exclusive videos, vlogs, and tutorials:
www.patreon.com/anthonygg_
The code can be found on GitHub: github.com/anthdm/gobank
Thanks for watching
Hey,
In case you haven't found how to type ` on 60% kb, it's: fn + esc.
The tutorial is second to none, thank you for that.
That is the best tutorial I have seen in my life, this is actually what happens and how we build applications. All tutorials that I have watched all examples were already preprogrammed, and the professor never shows how it is real process of building application. I really loved these 5 Go videos.
About the "_" (underscore) in imports - Generally used when you want to load a library and run its scripts without having anything to do with what it returns.
Great series of tutorials. You are amazing!
You are a very energetic teacher. Thank you for your videos 🔥
Your welcome!
I love the way you teach. You keep the vibe as casual as possible that I enjoy the lesson till I finish this video. Keep it up man
Ty
In a few hours, I followed the first two videos today. I tried to take my time to fully understand and it's really incredible how much we did in two videos!
You're a killer Anthony!
This is one of the best tutorials in GO back-end.
Thx for the video man, really helping to absorb the experience for my go development.
When starting on a new language the best way to learn how to do things is to see how other people does, and not try to push my own way of thinking coming from other languages.
I can see a uniqueness in your videos. thank you for the videos.
I'm quite new to golang, but have programmed in a lot of languages during time, starting with pascal, C and assembler all the way back in the late 80'ties.
I'm starting to like golang, as it reminds me a bit about the "old" stuff, but with all the annoying stuff filtered away and some of the new stuff put in instead.
I like way you explain it, as it doesn't seem to be a rehearsed thing you did before, and just copy/paste it. That make the video more interesting, as it's more real world kind of doing it.
That makes it more fun and not just like a bunch of overheads thrown in your face 🙂
So, thanks for the good work :-)
Tip: If you create a type serial on your postgresql table, it actualy create a sequence to that column and the default value will be aways a nextval(''table_name_column_name_seq'), is really good for ID's and sequencials, but in this example for a balance, every time you insert a account if you not specify balance = 0, the balance will be the nextval of the sequence xD
Thanks for this video btw, you are helping me alot :D
The problem was not with w.Header().Set() or .....Add() it was with you had to call w.WriteHeader(status) after setting content type.
Great content. Thanks.
Thank you for sharing those things! I'm not good at English, but I've finished making this project with your video!
Actually, I don't grasp how the framework works under the hood so far. These days, I'm trying to read the framework or library code to understand how it works under the hood. Thank you, Anthony. It's a really nice lecture I've ever seen before, To learn how to make a REST API Server with Go!
I wish that If I were good at English, I'll make the lecture like this!
This man so fun, I love your videos. Thanks
great series, love the minimal use of frameworks/libraries
Thanks Anthony. Great video!
Thanks a lot for making this series, I've enjoyed it and it's helped reinforce some things for me (between drinking many margaritas)
🍸
great tutorial, love the energy and style! subscribed hope you got the autocomplete fixed eventually in this series 💀
Awesome Video Anthony!!
Get it work, make it better, then make it work faster 🙇♂🙇♂, loved the series, Thanks @Anthony
Buddy i've learnt lotta things from you ty! btw, it's an interesting rule. first make it to work then make it better ultimitly make it fast.
Thanks again Anthony, great video!!
🤝
Thank you 🙏.
_ package -> the underscore following the package is for side effect only with out calling any method from it.
Great content!
You are really magic person. Thanks Anthony. I wish I could be a premium member and could buy your course.
Anyhow, really really appreciate your efforts. I'm learning a lot.
we are importing the postgres driver like this because we are using the api provided by golang so the package job is to register the postgres driver to the go standard sql api
"you are a package slave, you don't know shit"
*googles SQL create table command*
haha love this series, you've got a great teaching style I'm learning a lot. BTW, I've got an annie pro 60% and the backtick is FN+esc on there
LMAO 🤣
Good exercise
Very helpful series, great job!
I actually liked it at 35:50 .. love goes out to Bobb Ross and all his fans ❤
Yooh Anthony, amazing video and content like always!! By the way the thing ` in the 60% key board you get by using Fn + ESC, at least thats in mine a 60% US Layout and I use the USA international for the language lol
Cheers and thank for the video!!
Wow thanks! Searching for this for a long time.
Anthony is funny as hell.... "Don't be package slave , lets say the world explode and there are no packages anymore then you screwed". ... so so true
i could not stop laughing. ..... kiakiakia kiakiakia. .... love u man
The `` symbol is located (american layout) above the tab key, below the ESC and left of the 1 key.
the issue for the headers not being set wasn't changing it to add , the issue was we can only set the headers once , in our function , any subsequent changes aren't displayed . So moving it to the top , made it work
I love when you made typo and say "what's going on here" 🤣
btw thankyou so much for the tutorials!
15:36 What about using a migration tool to create your database structures? I use the Soda CLI and Fizz DSL from the Gobuffalo project with great success. Migrations are easy-peasy after the initial hurdle of learning the DSL.
Edit: _I already know how to write the queries in plain SQL, so if the objective is to learn SQL while you're also learning Go this might not be a good idea..._
Thanks man. Impressive stuff.
you're so funny man, such a joy learning from you
Great learning experience.
Any non-web based projects you recommend to get confidence in golang? I am picking up some Python book and trying to solve problems in Go. Many golang books don't have exercises..
Thanks a lot......
You are as awesome as your contents....
Thanks again....
Thanks, Antony!
Not sure if this will be answered later but how do you differentiate between handleGetAccount and handleGetAccountById?
Because the thing that kind of routes the endpoints to the function is the handleAccount function and there you say: If the method is r.GET, it should return handleGetAccount. Wouldn't that mean handleGetAccountByID is never used?
I didnt find out why u just used pointer for accounts,
I saw ur video about pointers but now what is benefit of pointer recivers ? I think u can use value reciver
the underline is actually to tell the compiler that you are not using the lib itself, just its side effetcs, under the hood the db.Sql uses the driver to connect with the postgres, we do not explict use it on our code xD
Thank you!
I know this is ultra noob but I'm commenting here incase somebody runs into this issue. Doing this exercise on windows and I constantly kept getting this error " pq: password authentication failed for user "postgres" ". Turns out I already had postgres (not through docker) running on port 5432 for another project and that was being accessed when I tried connecting to the docker postgres instance and hence the incorrect password.
Thank you, i forgot i got installed postgres in this machine, jesus haha
bro this is a lifesaver. I uninstalled my local postgres and I think will start using a dockerized postgres from now
Isn't there a difference between new(Account) and &Account that the &account is a pointer on the stack? and new on the heap?
That's a difference in C/C++ anyways and you may the be referencing a pointer that went out of scope. So I would opt for new from my C++ background. Or use & only for objects that are created in pain and pass around that pointer.
The problem with JSON was not because of Add or Set but because of the order of the functions calls. "WriteHeader SENDS an HTTP response header with the provided status code" - description from stdlib. So by the moment you set the header application/json, response is sent as I understand
Thanks Anthony
Hello Anthony, Please how can i fix my response form text to jSON ? how did you fix it, you didnt tell us in the tutorial
I don't understand a thing, why did you incapsulated db into PostgresStore type? The entire project would have worked anyway using directly db, no?
Not sure what you mean. But its probably for interface stuff later on. So you can also have a mongodb store. Something like that
@@anthonygg_ I was talking about the struct PostgresStore, btw yes understood thank you. Creating that struct you can gracefully handle the db connection in the NewPostgressStore func, and then of course you will be able to have several different stores such as MongoStore. Btw I really appreciate your coding style (even though i'm still learning) and your teaching style!
Hey Anthony, for the backtick try the following combination: Alt + 96
Hey man. Figured the tick out 🤣 fn esc on my keyboard. Thanks though!
for me, it is cmd+fn1+esc Im so scare every time I have to type this character LOL
The backtick (`)is supposed to be the button right of the +/= button. If it's not there, it's the button left of the !/1 key.
Have you done a part three with the JWT stuff
How do you tab all the lines above at 23:51
Hi, quick question would it be fine to modify Server struct like port, usersStore, transactionsStore, secrets. Can we break single store in multiple beacuse if we have 20 methods on interface it will be difficult to test it ?
The Storage here is more known as a repository. Data access layer. Postgres is in no way abstracted here when you write "Postgres" in the code.
Can we use fmt.SprintF() instead of `` ?
For create tables, you could consider db migration.
Now we should all get idiomatic with Postgres 🐘 Anyway your presentation style makes me want just to get down to doing things and not seek the nonexistent perfect!
The conventions for create apis are: methods (post, get) domain/accounts and (get, put, delete, patch) domain/accounts/{id}
Why you use lib/pq? This library is deprecated and now jackc/pgx is prefer.
Aight!
` should be some modifier key and esc key on 60% us layout acording to google.
Fabulous
May I ask why you name all your packages as "main"? Isn't it more easy to understand code and maintain it using different package names so that you can know which code comes from those? Just learning the lang.
he talks about it in the first part, I would add that it's far easier to split in modules once you have a good idea of the parts that your application is gonna involve, not before
Looks like gorilla mux has been archived, will you be doing a new series on a new mux?
Not sure. Maybe :)
Great tutorial. I know it's your setup but red/pink on black is too hard to see. I hope you'll change for video/user-friendly screen. Thanks!
if anyone is not getting the right format of the response in post or in your localhost browser, try putting double quotes for the types like this
ID int `json:"id"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Number int64 `json:"number"`
Balance int64 `json:"balance"`
CreatedAt time.Time `json:"createdAt"`
like this,the current version of Go does not support the old formatting method, use this format whenever declaring types. Cheers
it's time to put an end to package slavery!
shift + escape or fn + escape
That white backgroung in your postman is killing my eyes. Since i switched to dark backgrounds I'm such a crybaby.
when doing rows.next() dont forget to add rows.Close()!!!
Dayum, true true. Thanks for reminding me
This programming language is a struct hell )
this is save foor sql injection !!!!
For the blind homies T_T
Never actually showed how to get the new ID out of the database, or return the newly created account via the API. Feels like you lost heart in this. Shame
Love the stuff your teaching, but damn it's unbearable watching you. Just spamming keyboard to look fast, making more typos than actually right ones, like slow down man..
working through your examples, but having a problem with packages in different files, my normal structure...
go.mod
go.sum
main.go
I normally dump all code into main.go, but I'd like to maybe create a api packages and a types package and utils package
As I understand that would mean a api, types and utils sub directory under cmd and I then do import of "api" "types" and "utils"
issue, when done like this then the code in main.go that's trying to call the func's in api, types and utils errs out saying it can't find...
please helpppp
Keep it simple and dont use folders.
@@anthonygg_ tried that also. will try again.
... in the absence of folders, what do I import still the file name as the package name.
@@anthonygg_ ... moved to same directory, left them as package main.
tried importing the filename but as soon as I save it's removed by vscode ?
@@georgelza if in same package just call them by name without prefix