from go-template
This commit is contained in:
0
.dockerignore
Normal file
0
.dockerignore
Normal file
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
app
|
||||
*.swp
|
||||
*.test
|
||||
*.out
|
||||
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@@ -0,0 +1 @@
|
||||
golang 1.19
|
||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM golang:1.19 AS build
|
||||
WORKDIR /go/src/app
|
||||
COPY . .
|
||||
ENV CGO_ENABLED=0 GOOS=linux
|
||||
RUN go build -v -o app .
|
||||
|
||||
FROM alpine:latest
|
||||
WORKDIR /root/
|
||||
COPY --from=build /go/src/app/app .
|
||||
CMD ["./app"]
|
||||
50
Makefile
Normal file
50
Makefile
Normal file
@@ -0,0 +1,50 @@
|
||||
PACKAGES := $(shell go list ./...)
|
||||
|
||||
all: help
|
||||
|
||||
.PHONY: help
|
||||
help: Makefile
|
||||
@echo
|
||||
@echo " Choose a make command to run"
|
||||
@echo
|
||||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
|
||||
@echo
|
||||
|
||||
## vet: vet code
|
||||
.PHONY: vet
|
||||
vet:
|
||||
go vet $(PACKAGES)
|
||||
|
||||
## test: run unit tests
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -race -cover $(PACKAGES)
|
||||
|
||||
## build: build a binary
|
||||
.PHONY: build
|
||||
build: test
|
||||
go build -o ./app -v
|
||||
|
||||
## autobuild: auto build when source files change
|
||||
.PHONY: autobuild
|
||||
autobuild:
|
||||
# curl -sf https://gobinaries.com/cespare/reflex | sh
|
||||
reflex -g '*.go' -- sh -c 'echo "\n\n\n\n\n\n" && make build'
|
||||
|
||||
## dockerbuild: build project into a docker container image
|
||||
.PHONY: dockerbuild
|
||||
dockerbuild: test
|
||||
docker-compose build
|
||||
|
||||
## start: build and run local project
|
||||
.PHONY: start
|
||||
start: build
|
||||
clear
|
||||
@echo ""
|
||||
./app
|
||||
|
||||
## deploy: build code into a container and deploy it to the cloud dev environment
|
||||
.PHONY: deploy
|
||||
deploy: build
|
||||
./deploy.sh
|
||||
|
||||
19
README.md
Normal file
19
README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# go-template
|
||||
|
||||
Quick starter template for new go projects
|
||||
|
||||
```sh
|
||||
go mod init app
|
||||
```
|
||||
|
||||
```
|
||||
Choose a make command to run
|
||||
|
||||
vet vet code
|
||||
test run unit tests
|
||||
build build a binary
|
||||
autobuild auto build when source files change
|
||||
dockerbuild build project into a docker container image
|
||||
start build and run local project
|
||||
deploy build code into a container and deploy it to the cloud dev environment
|
||||
```
|
||||
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
image: app:0.1.0
|
||||
environment:
|
||||
FOO: bar
|
||||
30
main.go
Normal file
30
main.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
//exit process immediately upon sigterm
|
||||
handleSigTerms()
|
||||
|
||||
//run
|
||||
if err := run(os.Args, os.Stdout); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSigTerms() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
fmt.Println("received SIGTERM, exiting")
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user