func (startup *Startup) LoadQuestions() *Startup {
if startup.Errors != nil {
return startup
}
if len(engine.QuestionSet) <= 0 {
for i := 1; i <= 100; i++ {
question := engine.NewQuestion(i, "test question #"+strconv.Itoa(i))
engine.QuestionSet = append(engine.QuestionSet, *question)
}
}
return startup
}
func (startup *Startup) LoadQuestions() {
const lim = 100 // use constants instead of the magic values and choose a better name than `lim` I don't know the context so I couldn't choose a better name ๐ข . You can also decide if this needs to go global, be exported, add it to Startup struct, etc...
if startup.Errors != nil || len(engine.QuestionSet) == 0 {
return
}
for i := 1; i <= lim; i++ {
q := engine.NewQuestion(i, "test question #"+strconv.Itoa(i))
engine.QuestionSet = append(engine.QuestionSet, *q)
}
}
-
In datastore/entities instead of having multiple files, I think it's better to have them all in datastore/entities/entities.go
And as the package name is called entities
so you better drop the EntitySuffix
from the structs' names.
Instead of type AnswerEntity struct{}
, let it be type Answer struct{}
Put in mind that when you use this from outside the package you will write entities.AnswerEntity
you will find that entity is written twice, while entities. entities.Answer
is clean enough.
-
I see you are already applying some good practices, like sorting and grouping the imports, and others ๐ Good work ๐ .
-
There are other parts with areas of improvement. But these are the points I noticed from a glance.
If you find it helpful, I will try to give more feedback when I get some free time.
-
Pro Bro tips:
- Check this youtube channel, there are a couple of videos where the guy clones a repo, and refactor it. I have learned a lot from this guy.
- Explore some of the standard libraries. They have great stuff, and I have learned a couple of useful patterns while checking them, you can also get some good practices from them.
- Write more documentation, maybe update the README file with some instructions on how to run the project locally.
Also check this
- Dude, you are missing a lot of fun by not writing unit tests!
There's a couple of plugins to help you generate a skeleton for testing a function. They almost do all the work, and you will have to only fill a table by some data/structs.
Give a try to writing unit tests and even better if you work in TDD, like solid programmers (I am not one of them yet, ed3ily).
A very popular way is Table Driven Tests
. You can check it on some of the standard libraries like net/http
.
-
A recommendation:
From the parts I have checked, I didn't see any usage of channels. Which is fine, but if you want a simple task to use/learn channels, check how you can do a graceful shutdown, so that when the user terminates the program by ctrl+c, the program stop taking any actions from the user but keeps the system up till it shutdowns all running services successfully. Or maybe to save the state of your game or whatever is in engine.ExitTheGame()
.
And maybe rename ExitTheGame
to Shutdown
, Exit
or Close
.