greenlight
Описание
Example REST API
Языки
- Go95,7%
- Makefile3,4%
- Shell0,5%
- Dockerfile0,4%
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
3 года назад
README.md
REST API
- Routing
- Validation
- Migration
- Models
- Rate Limiter
- Logger
- Graceful Shutdown
- Background Tasks
- Tokens
- Permissions
- Cors
- Metrics (expvar, httpsnoop)
- Makefile
Personal education via book "Lets`s Go Further"
File and folder names
- The
directory will contain our compiled application binaries, ready for deployment to a production server.bin - The
directory will contain the application-specific code for our Greenlight API application. This will include the code for running the server, reading and writing HTTP requests, and managing authentication.cmd/api - The
directory will contain various ancillary packages used by our API. It will contain the code for interacting with our database, doing data validation, sending emails and so on. Basically, any code which isn’t application-specific and can potentially be reused will live in here. Our Go code underinternalwill import the packages in thecmd/apidirectory (but never the other way around).internal - The
directory will contain the SQL migration files for our database. The remote directory will contain the configuration files and setup scripts for our production server.migrations - The
file will declare our project dependencies, versions and module path.go.mod - The
will contain recipes for automating common administrative tasks — like auditing our Go code, building binaries, and executing database migrations.Makefile
How to use
Install
Download dependency
Install the package
Install migration tools (macOS)
Migration
Creating migration
Up
Run or build project
Run
Build
Other
Print makefile help messages
Quality audit
Audit tools:
command to format all .go files in the project directory, according to the Go standard.go fmt ./...command to check allgo vet ./...files in the project directory. Runs a variety of analyzers which carry out static analysis of your code and warn you about things which might be wrong but won’t be picked up by the compiler..gocommand to run all tests in the project directory.go test -race -vet=off ./...- Third-party
tool to carry out some additional static analysis checks.staticcheck
Vendor tools:
command will make sure the go.mod and go.sum files list all the necessary dependencies for our project (and no unnecessary ones).go mod tidycommand will verify that the dependencies stored in your module cache (located on your machine at $GOPATH/pkg/mod) match the cryptographic hashes in the go.sum file.go mod verifycommand will then copy the necessary source code from your module cache into a new vendor directory in your project root.go mod vendor