Template Golang service and libraries.
Clone scratch
git clone https://github.com/levinishka/scratch.gitYou can either compile scratch by yourself:
using make
cd scratch
make buildmanual
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 WindowsOr use precompiled binaries in cmd/bin folder:
scratchfor Linuxscratch.exefor Windows
Check help
./cmd/bin/scratch -helpScratch creates template for Golang service:
- create service from scratch
- use
-projectparameter to specify new project's path: last element in a path will be new project's name - use
-repoparameter 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/levinishka
# initialize go modules
cd /absolute/path/to/testProject
go mod init github.com/levinishka/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/levinishka/testProject.git
git push -u origin masterScratch contains some useful libraries which you can import and use:
configsimply reads config file in JSON format and unmarshal it to a structureloggerprovides preconfigured zap-loggerrouterprovides mux router with pprof handlers addedserverprovides http server with graceful shutdownmetricsprovides prometheus http server with basic service metrics
To import any of these packages use "github.com/levinishka/scratch/pkg/PACKAGE"