Has anyone tried this tutorial about gin + golang ? I tried learning gin and golang via this, but my code ended up in a lot of problems with this. Also, in my limited understanding of golang, this tutorial kind of has a lot of unformal things like using file names like handlers.article.go instead of handlers/article.go and probably declaring the package to handlers. All of the files are packaged under main.
Am I missing something, I’d like to know if someone has completed this tutorial.
First of all, I don’t recommend beginners to start with gin directly, even though it is highly recommended by many people.
I personally recommend learning from the standard library’s http to understand the design structure, processing logic, etc. When you have basically mastered the standard library’s http, you will find it easy to get started with those third-party libraries.
As for this tutorial, after a quick look, it doesn’t seem to be very nutritious.
Yeah. Also, I do not believe in all the thing with mastering and all. I like to try figure out everything on the go. And I have decent understanding of structure and processing logs, I am coming here after trying to work on a big enough go code-base (did do some PR’s though). My seniors just wanted me to do this tutorial so that I can have even better understanding of our codebase which heavily utilises gin.
Well, I think you’re de-railing in the wrong direction. I wanted to know thoughts about that tutorial. The topic wasn’t very very very specific to “Gin” at the first place. It was whether anyone else had felt the same thing about the tutorial like I did.
Anyways, I’d like to wait and see if anyone can share anything helpful or brief about the tutorial
Well, it seems to be my problem.
I am not interested enough to read the tutorial you mentioned in full. But after a quick review, the tutorial gives me the same feeling as I said before. However, such public tutorials cannot be judged too strictly.
Yeah agreed. I noticed the issues after 2-3 pages itself of the gitbook. I had thrown myself straight into the codebase for some tasks, so I had to fiddle with things and while doing that I kind of understood the whole structure a codebase needs to have to run a backend properly. And I noticed this tutorial does not follow the structure at all.
I tried distributing the codebase into different packages (handlers, models and testing) but the undefined errors kept going on. Probably, i’ll try to debug em or just ask me manager to give me another task straight
I skimmed the codebase and agree that things like handlers.articles.go are a bit odd. It’s also not very idiomatic to have common_test.go. I think they were trying to break things into separate files while keeping the package structure flat. Notice there’s no go.mod? Because this project predates go modules (the initial commit is June 14, 2016!). So, I think this was a way to keep things flat/simple before modules existed (and certain idioms were less rooted in the community back then) and it is since outdated.
If you’re stuck on something, talk to the senior devs who assigned you to go through that tutorial. I’m sure they had a specific reason in mind. If you’re struggling, ask for help (it’s their job and it’s vastly preferred when junior developers ask for help rather than thrash around on their own for too long!). It might be something like: one of the modules that you are maintaining is 11 years old and predates Go Modules as well and thus they want you to know how their legacy code looks, etc.
Thank you @Dean_Davidson for the explanation. Right, I also suspected that its probably a very old tutorial.
Yes, I will report the same to my senior. Its less likely that we have an old project. Because our company and the project itself is just 5 years old. Now, I’m curious why I was specifically given this tutorial to build understanding of Go and Gin to understand our codebase better.
@Dean_Davidson Can you suggest any good tutorials for building familiarity with backend focused golang and gin tutorials ? I talked to him and he said that he just randomly gave this and just wants me to build familiarity and fluency with the language and framework for better understanding. Any other tutorial would be fine too.
As @peakedshout mentioned, the examples in the official documentation are pretty exhaustive. Also there’s a getting started guide on go.dev but it’s more basic. You’re going to mostly learn by building stuff, so I would just pick something you want to build and build it.
Yup, I checked that tutorial out and also found a previous thread where you suggested it. And I think its too basic and does not excite me :(. Most probably, I will confront with my senior to start building something to build more understanding of the codebase.
One more question for you, how do you learn or study about a codebase ? Is there any specific approach you have. I got to work on a tiny feature last to last week on our go codebase. How I went for it was: I pin the task on my screen, building a pseudo algorithm and basically give structure to what I want. Start search in the codebase for relevant methods/functions to search for anything which is already made with ripgrep or neovim telescope, so that I don’t repeat it, and understand if the feature I am writing goes into the Handlers, controllers or repository of the codebase and just start writing it.
I’m not sure what you mean.
If you mean how to learn a brand new code base. Then my approach is to first understand what it is, then what methods there are (some code bases have tutorial code), and then try to call it to build your own demo code.
If you mean to learn more about the code base, I think there is nothing more rewarding than writing a replacement yourself. (Like most of my programming knowledge, I learned it because I wanted to do something)
If you are working on a decently large codebase where you don’t have to rewrite your own, that is when developing the understanding of your current codebase comes into play. I was a naive non-programmer before I started and while writing that tiny feature I learnt some things about the codebase. We are a Software Service hence, there are a lot of function/method calls, db writes and etc happening every second, so any of that calls could be helpful.
I think my question was quite simple but yeah probably it confused the reader because of the explanation I did after the question.
If you are learning application services, the easiest way is to read the source code from the entry point.
If you are learning tool libraries, the easiest way is to read the source code from the exported global methods and structures.
This is a method for global learning. If you want to understand it in a targeted way, you may need to locate the source code you need and read it.
This is my personal learning method. Of course, the most enjoyable way is to learn through demo code.
It really depends. The more experience you get, the more you will be able to just poke around the code and understand what it all is doing. But it is hard with a large project, even if you have experience, to grok everything about it.
Example: if you wanted to poke around the code in julienschmidt/httprouter I bet you could understand 80% of what it does in a relatively small amount of time. But what if you wanted to understand all the code in this project?
I do a lot of integrations with various cloud platforms. Read through this godoc. That’s just one service and on just one cloud provider. Where I’m going with this is: with large projects/platforms like this, you pretty much have to rely on the docs. And usually the large players like this have excellent docs with good examples to follow.
So, I rely on a mix of documentation and spelunking the code. It really depends on what I’m working on and the packages I’m consuming. In your case, if you are unsure about where to start, I’d ask the senior developer who is assigning these tasks to you. Nobody is going to fault you for asking for direction (in fact, it’s a good habit to ask for help when you are stuck!). They WILL fault you for not asking and then not producing anything though.
Cool, understood. Pretty much the same approach I think.
We dumped the Go + Gin thing and started planning for another improvement which actually excites me to work on :). Its again a combination of some database code and writing some Go API’s. Most probably, the upcoming week is going to be fun. We will be planning everything first and go slow with it.