This is a learning project I'm willing to grow up adding new feature every day each with some well-know library, a framework or a concept. My aim is to drive a train.
-
Run the project:
PORT=1600 go run cmd/web/main.go
-
Open this url in your browser: http:/127.0.0.1:1600/
Created a web application with Gin using it's routers and templates. JSON unmarshalling and HTTP requests also has been covered.
Created a Domain/IP database with gorm. Domains are resolved on-the-fly and are stored into the database. Gin's HTTP args and POST params are covered too.
Configured logging with zap. Tuned up logging to both file and stdout, with Caller and Stacktrace options.
Context with timeout is used to limit ipinfo fetching time with an interval of 1 second. Timeout error is handeled correctly and dislayed to a user.
Learned how to deal with the Cobra. I'm using positional and keyword arguments with hierarchical command logic and validation:
> dailygo
Dailygo — a golang learning project.
Usage:
dailygo [command]
Available Commands:
completion Generate the autocompletion script
help Help about any command
info Print geoinfo of an IP address
initdb Init a new database
runserver Run the dailygo web server
Flags:
-h, --help help for dailygo
Use "dailygo [command] --help" for more info
Learned how to deal with the protobuf. Return IP geoinfo in a protobuf format at /api/info/pb/
.
Memo:
- Write a proto file in
proto/ipinfo/ipinfo.proto
- Run
protoc --go_out=. proto/ipinfo/ipinfo.proto
- Import it and use it. Gin has a special method for it!