- using
chi
for the http router, which is lightweight and Designed for composable APIs - using
sqlc
to generate type-safe code from SQL - using
go-migrate
for database migrations - using
air
to live reload Go apps for dev
There are a lot of config that can be set, please check ./config
.
the most necessary one could be
export DATABASE_URL="root:password@/cricket_db?parseTime=true"
Warning
the user:password is only used for development
docker compose up
it will start a mysql server and do migrations, but at this point, the tables are still empty
you can run the following command to seed the table
go run cmd/load_csv_to_db/main.go
or
make import-csv
Openapi-generator generated documentation
or
access http://localhost:8080/docs/
make docs
using 'Authorization: BEARER T' request header, Token can generate by using the following tool.
Secret can be configured through env varaible JWT_SECRET
, by default its value is secret
See https://github.com/goware/jwtutil for utility to help you generate JWT tokens.
go install github.com/goware/jwtutil
jwtutil -secret=secret -encode -claims='{"user_id":111}'
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMTF9._cLJn0xFS0Mdr_4L_8XF8-8tv7bHyOQJXyWaNsSqlEs
curl http://localhost:8080/api/v1/players/most_runs\?careerEndYear\=2010 -H 'Authorization: BEARER eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMTF9._cLJn0xFS0Mdr_4L_8XF8-8tv7bHyOQJXyWaNsSqlEs'
{"name":"Mohammad Yousuf (Asia/PAK)","runs":9720}
First of all you must run services
docker compose up
Then you can import data by using make:
make import-csv
It is made by making requests to api service, which is using the dev database.
make test_db # it will create a cricket_db_test
# before running test, make sure the DATABASE_URL is pointing to the test_db
export DATABASE_URL="root:password@/cricket_db_test?parseTime=true"
go test ./...
./scripts/load_csv_data_to_mysql.sh