Golang REST API from scratch with Go Fiber, Docker & Postgres | Tutorial
Вставка
- Опубліковано 26 лип 2024
- In this tutorial, we will learn how to create a simple trivia REST API from scratch, using Go and Docker. At the end of the tutorial, we will have a little Go Fiber app connected to a Postgres database.
📎 Text tutorials
- divrhino.com - divrhino.com/articles/rest-ap...
- dev.to - dev.to/divrhino/build-a-rest-...
- Code repo - github.com/divrhino/divrhino-...
🦏 Other great tutorials
- Introduction to interactive Git Rebase - • Interactive git rebase...
- Create a dad joke CLI app - • Golang Cobra CLI tool ...
⌛ Timestamps
00:00 - Introduction
00:11 - Prerequisites
00:26 - Dockerfile and docker-compose.yml
03:33 - Installing and managing dependencies
08:28 - Adding a Postgres service
16:11 - Routes and endpoints
This is the first video I've watched where everything about Dockerfiles, docker-compose, and all of these topics finally clicked for me!
Aw, that makes me happy to know! Thank you ✨✨
Okay, that's a good one. Absolutely informative and concise.
Glad you enjoyed it! Thanks for taking the time to leave a kind comment 🙏✨
This is truly excellent, nobody is doing this in this way in just 20 or so minutes.. great work hope to see more in the future :)
Thank you for the kind words! Glad to have you here ✨
In case anyone else is having the issue where Air is not reloading on a Windows machine, inside the .air.toml file you must set " poll=true " for the changes to be picked up in real time. Great video though!
Thank you for leaving this comment! I’m sure others will find it very useful 🙏✨
Bro your comment saved my life thanks alot
Legend!
This is some incredibly high quality content. I would have LOVED something like this when I was starting out. Really good clear presentation, good video structure, and wonderful brisk pace. Nice work!
I appreciate your kind and encouraging comment. Thank you! 🙌
Absolutely loved this video and I'm amazed at the quality. Thank you for making the serious they are perfect for learning Golang. The format is perfect and you are definitely gifted at teaching
Thank you! I appreciate the kind words and feedback. I hope your learning journey is going well 🙏
Probably the most clear and best Go tutorial I've found on UA-cam until now. Thanks for this video.
Also, you have a new subscriber now
Thanks for your support! I appreciate you 🙏✨
This is presented so clearly! Thank you!
Thank you for watching!
your go tutorials are the best and simplest to understand! can't wait to see more go tutorials in the future~
Aw, thank you for the encouragement!
@@DivRhino yw~ also, would it be fine to ask for suggestions on other go tutorials? in particular, i would like yo see a rest api tutorial that uses gorilla mux, since it is a very popular go library for making near-vanilla golang rest apis. also, making a TUI application using charm bubbletea, in which i'ce heard they are a great library for making cool TUI applications~ just some suggestions, thankss
@@cindrmon Thanks for the suggestions. I've played with bubbletea a couple of times in the past, so I can definitely consider making a video about it.
I'm a little hesitant to make a video about mux as there are many good ones out there already.
I appreciate your feedback.
Exceptional, well-structured, and clearly presented. Thank you.
Thank you for being here and taking the time to leave those kind words! ✨🙏
This was exactly what I needed. Thank you so much!
Good tutorial
Glad you found it useful! Thanks for letting me know 🙌
Thank you for cheering us up, seriously, learning can be difficult sometimes.
Yes, I agree, sometimes learning can be difficult. But don’t give up! Keep coding, you can do it 🙏
Excellent presentation - no adjective - no adverb - straight to the point with facts and monotone narrative presentation... Thank you for sharing your experience
Thank you for your support! Happy to have you 🙌
My love! Thank you for the clearest explanation. OMG this is the best!
Thank you so much for your lovely comment! I appreciate you watching 🙌✨
one of the great videos I have ever seen
What a nice thing to say! Thanks for watching, I appreciate your kind words ✨🙏
@@DivRhino keep up the good work expecting more videos 😄😄
Very clear and precise instructions, also the flow is perfectly paced. Please make more content like this. I just subscribed.
Thanks for stopping by and taking the time to leave a comment! I appreciate it! ✨
amazing content, simple, high quality, got yourself a new subscriber. keep them coming!! BTW, lo ve the illustrations
Aw! Thank you for taking the time to leave such a nice comment. Happy to have you here!
Thank you for this 🙏🎉 I really appreciate your tutorials ❤
And I appreciate you being here! I’m glad to have you 😊
This is extremely well done! The instructions are clear and concise. Great job!
Thank you so much for watching!
I’ve just finished your video “Learn to Code by NOT Doing What Everyone Else Does”. Great advice. Looking forward to seeing your channel grow 🙏✨
@@DivRhino Glad you like it, thanks! I'll be going through all of your videos. It's taking me a while to get comfortable with docker. =\
@@handmadegamesdev I hope you find the videos useful ☺
you are indeed gifted at teaching. although i have some problems with my computer, this video helped me understand working with docker better. Thank you so much, you definetely don't have enough credit for what you do.
What a thoughtful and encouraging comment 🥰 thank you, I appreciate you being here 🙏
Very well made tutorial, thank you! It has helped me a lot!
I’m so glad to hear that! Thank you for your comment ✨🙏
this is 🔥, very nicely presented
thank you for this tutorial
Thank you for watching, I appreciate you being here!
Explained concepts so well! Keep it up!
Thank you for the encouragement! ✨❤️
This is an amazing...very clear explanation. Please keep making more videos.
Thank you for your kind comment! ✨🙏
Amazing tutorial! Thank you for your time & efforts! Btw, your cover pages for videos are beautiful, love the way you design your videos!
Thank you for leaving such a kind and encouraging comment! I appreciate you being here ✨✨
Thank you for this! Really great tutorials!
Thank you for being here! I appreciate you leaving a comment ✨
This tutorial is scary good!! Thank you!
Thank you for your scary nice comment! Glad you enjoyed it ✨✨
I know how to use docker but i didn't know this kind of magic is possible with it! Air is amazing.
Thanks for such an awesome and clear tutorial.
Thank you for the lovely comment! I’m so glad the video was useful! 🙌
Thank you for great tutorial
Thank you for watching! 🙏
We’ll done. Thank you
Thank you for your continued support, 🙏
very good. Subscribed!
Thanks for being here!
Lovely. Thank you
Thank you for watching! 🙏✨
Excellent!
Thank you for being here! ✨
Good tutorial. Thanks 🙏
Thank you for watching! Glad to have you ✨✨
Great tutorial!
Thank you for your encouraging comment! 🙏
Excellent job.
Thank you for watching! I appreciate the comment ✨🙏
excellent video.
Appreciate the comment! Thanks for being here ✨🙏
Decided on learning Go so will be visiting your channel often, could you please zoom in a bit
Thank you for the feedback, I’ll make sure to zoom in for all future videos. I’m glad you’re here, I hope you find something useful 🙏✨
Thanks for this tutorial it helped me to understand how to use docker with golang💫💫
And thank you for watching! So glad you found the content useful 🙏
Thank you so much❤
And thank you for watching 😍🙏
Subbed. Great content
Just a suggestion would be to make the text size a bit larger so it's easily visible in the video
Thank you for being here! And thanks for the feedback. I’ll make the text bigger next time. 🙏
Amazing, Following closely
Thank you for taking the time to leave a comment. I appreciate you being here 🙏
Thank you !
And thank you for watching!
Hey Div Rhino! Long time. wb
Hey Big Squeak! Thank you 🥰
Thank you
Thank YOU for being here! 🙏
this is great
Thank you for watching! 🙏
this is great, one suggestion is zoom in more into the editor
Thanks for the feedback. I’ll keep this in mind for all future videos 🙏🙏
lovely
Thank you 🙏
15:12 log.Fatal() is like .Println() followed by os.Exit(1) so no need of os.Exit(2)
Cool. Thanks 🙏
great video, i'm very appreciated with your dediation that you put into making these videos. And it can be more wonderful if there is any solution for not hot reloading while using windows ?
Hello there, thanks for leaving a comment. Several Windows users have reported similar issues with hot reloading when using docker. Here's a link to a potential workaround I found in the air repository:
github.com/cosmtrek/air/issues/190#issuecomment-999254716
Good tutorial, for the next one try to zoom to the desktop.
Thank you for the feedback 🙏
Should I run this command (docket compose build) whenever I updating docker-compose.yml or Dockerfile?
Thanks for your question. If you’re adding new steps to your Dockerfile, you should run the build command. Images are static once they are built and they do not automatically update themselves when new instructions are added. So every time you add something new to the Dockerfile, you’ll want to rebuild.
docker-compose is a tool that allows you to work with multiple Dockerfiles in the one project. You don’t usually need to rebuild an image when you change the config there. But sometimes you may need to restart your server.
I hope that helps 🙏✨
at 4:17 the go.mod file doesnt appear on my project board... i can see it with "ls" but i cant see anything i create in the container
Hi there! I'm sorry to hear you're having trouble with this. Are you by any chance using a Windows machine?
I can't connect to the db, := failed to connect to `host=localhost user=postgres database=`: dial error (dial tcp [::1]:5432: connect: cannot assig432: connect: cannot assign requested address), i created a new one, but doesnt worth...
I have a go project and I was making a docker image. It build successfully but when I tried to run it, .env file was not actually copied in the docker image. How can we copy the file name starting with dot.
Have you added a COPY instruction to your Dockerfile to copy over the .env file?
I have an issue "too many open files" when run docker compose up, can you help me! Thanks
Hi there! Thanks for your comment. I'm sorry to hear that you're having trouble. I found an answer on stackoverflow that may help you out:
stackoverflow.com/a/43265189
This is an amazing tutorial but I have a question. I'd like to change run command with an environment variable in docker-compose.yml is that possible?
Thanks for your question!
There are some suggestions in this StackOverflow thread:
stackoverflow.com/questions/40447029/docker-compose-environment-variable-for-command
air is not hot reloading, my vscode has the auto save feature, I tried disabling it but still is not working. Any ideas?
Hello there, are you on a Windows machine? I have seen other people online having issues with using the air package in Docker on a Windows machine. I am not sure how to use docker on Windows, unfortunately.
@@DivRhino yes I am on windows :( any alternatives?
@@manuelillanes1635 I found this open issue in the Github repo and it looks like someone there has come up with a solution.
Give it a try, maybe?
github.com/cosmtrek/air/issues/190#issuecomment-999254716
DB CONNECTION DIDN'T WORK - failed to initialize database, got error failed to connect to `host=db user=test database=test`: failed SASL auth (FATAL: password authentication failed for user "test" (SQLSTATE 28P01))
Sorry to see that this isn’t working for you. Without seeing your code, it would be difficult to see where the issue is occurring. I have linked the text tutorial and the finished code in the video description. It may help to compare your code with that to see if you can spot the differences.
Same here, any solutions?
Did you find a solution? I'm having the same issue.
@@manuelillanes1635 I solved it removing volume and running prune to clean all local data related to volumes.
Hey.... hot reload it not working in docker windows 11 :(
Hello there, unfortunately this seems to be an issue that others have also faced when using air with docker-compose on a Windows machine. 😥
how to check database ?
Hey there, thanks for your question. You can use a database client like Postico, Navicat or DBeaver to check your database in a GUI.
You can also use psql if you prefer to work in the terminal.
how worck withot GORM?????
If you don’t want to use an ORM like GORM, you can write SQL.
You should make the fonts bigger, it is hard to read.
👍✨
please increase font size in the video for your blind homies
Thank you for the feedback! Yes, unfortunately many people struggled with the small font size, sorry about that. I will make it bigger for all future videos. 🙏🙏
this is need to install golang in linux first?
Hello! You do not need to have Golang installed first. But you do need to have Docker installed and running to be able to follow the tutorial.
@@DivRhino thanks for the reply, so we can configure for go specific version from dockerfile right?
@@muhamadrifqi5709 Yes, that's right. Once you have docker installed on your machine, you will use the Dockerfile to specify which Golang version you want to install.
Can you do a urfave2 tutorial?
Hello Marvin, good to see you again. Thanks for leaving a comment. Do you mean urfave/cli?
@@DivRhino oh you remember me. I’m still learning go and need help with api lol. Yes urfave. Cli
That will be a big help. Thank
use a larger font. i need my eyes
Okay
Very well explained. Could you please increase the font size of your IDE ? It's hard to see on the mobile.
Thank you for watching! And I apologise for the small IDE text size. I'll keep mobile in mind for future tutorials. I appreciate the feedback 🙏
@@DivRhino thank you