Summer provide a CLI tool to help you initialize the project.
go install github.com/NYCU-SDC/summer/cmd/summer@latest
To verify the installation, run:
summer -v
summer -b main init
You may choose any other branch with -b flag.
Then, summer will ask for the project name. The project name will be used as the module name in go.mod. You can still edit it.
Summer will create a file structure like bellow:
.
├── cmd/
│ └── main.go
├── internal
└── scripts/
└── create_full_schema.sh
main.go
will containe a minimal server example.
create_full_schema.sh
is a recommended helper script if you would like to use sqlc
for SQL generation. The usage will be described in later section.
First install the dependencies:
go mod tidy
Then start the server:
go run ./cmd/main.go
Finally try it out. Use any api testing tool and hit the following endpoint:
localhost:8080/healthz
You will recive a greeting from the local server!
The create_full_schema.sh
is use to collect all schema.sql
in internal
folder and output, merge them all to ./internal/database/full_schema.sql
.
This is a recommeded tool if you want to use sqlc for SQL generation. Edit the shell script if you wish to use different output file or change other behaviors.
Run the script from the project root:
./ scripts/create_full_schema.sql
If you encounter any problem like permission denied
, it might be cause by a missing x bit in the file mode and cause it unexecutable. To fix this run:
chmod -x /path/to/the_script
And try again.