include an example cmd
This commit is contained in:
9
build.sh
9
build.sh
@@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CGO_ENABLED=0
|
||||
export GO111MODULE=off
|
||||
|
||||
echo go build -trimpath \
|
||||
-ldflags="all=-s -w -buildid= -X main.version=$(cat VERSION) -X main.buildtime=$(date +%FT%T%z)" \
|
||||
-o pathway \
|
||||
src/*.go
|
||||
16
cmd/Dockerfile
Normal file
16
cmd/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM golang:alpine AS builder
|
||||
RUN apk --no-cache --no-progress add upx
|
||||
WORKDIR /go/build
|
||||
|
||||
COPY . .
|
||||
RUN echo Building && \
|
||||
go get -u && \
|
||||
env CGO_ENABLED=0 go build -trimpath -ldflags="all=-s -w -buildid= -X main.version=v$(cat VERSION) -X main.buildtime=$(date +%FT%T%z)" -o pathway && \
|
||||
echo Compressing && \
|
||||
upx pathway > /dev/null
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /go/build/pathway /pathway
|
||||
|
||||
EXPOSE 8080
|
||||
CMD ["/pathway"]
|
||||
1
cmd/VERSION
Normal file
1
cmd/VERSION
Normal file
@@ -0,0 +1 @@
|
||||
3.0
|
||||
3
cmd/build.sh
Executable file
3
cmd/build.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
export CGO_ENABLED=0
|
||||
go build -trimpath -ldflags="all=-s -w -buildid= -X main.version=v$(cat VERSION) -X main.buildtime=$(date +%FT%T%z)" -o pathway
|
||||
7
cmd/go.mod
Normal file
7
cmd/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module main
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
git.nxdomain.nl/mattijs/pathway v0.1.2
|
||||
)
|
||||
2
cmd/go.sum
Normal file
2
cmd/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
git.nxdomain.nl/mattijs/pathway v0.1.2 h1:EXt0JaDlS4gPvQgGcyslYaLgRC2/AZPC+/8VDba3+bY=
|
||||
git.nxdomain.nl/mattijs/pathway v0.1.2/go.mod h1:3FllmtSFlVdPPdXmtL+N7V0qdaTtYB/zLyM8uQr+50o=
|
||||
50
cmd/main.go
Normal file
50
cmd/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.nxdomain.nl/mattijs/pathway"
|
||||
)
|
||||
|
||||
var (
|
||||
// variables to set during build-time
|
||||
debugging = ""
|
||||
version = "0.0-undefined"
|
||||
buildtime = "0000-00-00T00:00:00+0000"
|
||||
)
|
||||
|
||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("ok"))
|
||||
}
|
||||
|
||||
func emptyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func main() {
|
||||
info("pathway version:%s buildtime:%s", version, buildtime)
|
||||
|
||||
paths := pathway.New()
|
||||
|
||||
http.HandleFunc("/health", okHandler)
|
||||
http.HandleFunc("/favicon.ico", emptyHandler)
|
||||
http.HandleFunc("/robots.txt", emptyHandler)
|
||||
http.HandleFunc("/", paths.ServeHTTP)
|
||||
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
info("%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func info(msg string, args ...interface{}) {
|
||||
log.Printf("INFO | "+msg, args...)
|
||||
}
|
||||
|
||||
func debug(msg string, args ...interface{}) {
|
||||
if len(debugging) > 0 {
|
||||
log.Printf("DEBUG | "+msg, args...)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user