Template Golang service and libraries.
Clone scratch
git clone https://github.com/causelovem/scratch.git
You can either compile scratch by yourself:
using make
cd scratch
make build
manual
cd scratch
go build -o cmd/bin/scratch cmd/scratch/main.go # for Linux
GOOS=windows GOARCH=amd64 go build -o cmd/bin/scratch.exe cmd/scratch/main.go # for Windows
Or use precompiled binaries in cmd/bin
folder:
scratch
for Linuxscratch.exe
for Windows
Check help
./cmd/bin/scratch -help
Scratch creates template for Golang service:
- create service from scratch
- use
-project
parameter to specify new project's path: last element in a path will be new project's name - use
-repo
parameter to specify git repository path of new project
- use
- initialize go modules
- write your own logic using template service
- test it
- initialize git and push
- ???
- PROFIT
Creates new project with name testProject
# create project from scratch
chmod a+x ./cmd/bin/scratch
./cmd/bin/scratch -project /absolute/path/to/testProject -repo github.com/causelovem
# initialize go modules
cd /absolute/path/to/testProject
go mod init github.com/causelovem/testProject
go mod tidy
# write logic and then test service
make lint
make test
make build
make test-run
# initialize git and push
git init
git add --all
git commit -m "Initial Commit"
git remote add origin github.com/causelovem/testProject.git
git push -u origin master
Scratch contains some useful libraries which you can import and use:
config
simply reads config file in JSON format and unmarshal it to a structurelogger
provides preconfigured zap-loggerrouter
provides mux router with pprof handlers addedserver
provides http server with graceful shutdownmetrics
provides prometheus http server with basic service metrics
To import any of these packages use "github.com/causelovem/scratch/pkg/PACKAGE"