├── .vscode └── settings.json ├── .gitignore ├── Dockerfile ├── Makefile ├── go.mod ├── api ├── echo.go ├── hello.go ├── book_test.go └── book.go ├── .github └── workflows │ └── go.yml ├── microservice.go ├── marathon.sh ├── go.sum ├── LICENSE ├── k8s-deployment.yml └── README.adoc /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .wercker/ 2 | .vscode/ 3 | .idea/ 4 | cloud-native-go 5 | .dccache -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.7.3-alpine 2 | 3 | ENV SOURCES /go/src/github.com/lreimer/cloud-native-go/ 4 | 5 | COPY . ${SOURCES} 6 | 7 | RUN cd ${SOURCES} && CGO_ENABLED=0 go install -a 8 | 9 | ENTRYPOINT cloud-native-go 10 | EXPOSE 8080 -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME = cloud-native-go:1.1.0 2 | 3 | default: build 4 | 5 | docker: 6 | docker build -t $(NAME) . 7 | 8 | build: 9 | CGO_ENABLED=0 go build -v ./... 10 | 11 | install: 12 | CGO_ENABLED=0 go install -v ./... 13 | 14 | clean: 15 | rm cloud-native-go -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/lreimer/cloud-native-go 2 | 3 | go 1.17 4 | 5 | require github.com/stretchr/testify v1.7.1 6 | 7 | require ( 8 | github.com/davecgh/go-spew v1.1.0 // indirect 9 | github.com/pmezard/go-difflib v1.0.0 // indirect 10 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /api/echo.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // EchoHandleFunc to be used as http.HandleFunc for ECHO API 9 | func EchoHandleFunc(w http.ResponseWriter, r *http.Request) { 10 | message := r.URL.Query()["message"][0] 11 | 12 | w.Header().Add("Content-Type", "text/plain") 13 | fmt.Fprintf(w, message) 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v3 18 | with: 19 | go-version: 1.17 20 | 21 | - name: Build 22 | run: CGO_ENABLED=0 go build -v ./... 23 | 24 | - name: Test 25 | run: go test -v ./... 26 | -------------------------------------------------------------------------------- /api/hello.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | ) 7 | 8 | // Hello response structure 9 | type Hello struct { 10 | Message string 11 | } 12 | 13 | // HelloHandleFunc to be used as http.HandleFunc for Hello API 14 | func HelloHandleFunc(w http.ResponseWriter, r *http.Request) { 15 | 16 | m := Hello{"Welcome to Cloud Native Go."} 17 | b, err := json.Marshal(m) 18 | 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | w.Header().Add("Content-Type", "application/json; charset=utf-8") 24 | w.Write(b) 25 | } 26 | -------------------------------------------------------------------------------- /microservice.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | 8 | "github.com/lreimer/cloud-native-go/api" 9 | ) 10 | 11 | func main() { 12 | http.HandleFunc("/", index) 13 | http.HandleFunc("/api/echo", api.EchoHandleFunc) 14 | http.HandleFunc("/api/hello", api.HelloHandleFunc) 15 | 16 | http.HandleFunc("/api/books", api.BooksHandleFunc) 17 | http.HandleFunc("/api/books/", api.BookHandleFunc) 18 | 19 | http.ListenAndServe(port(), nil) 20 | } 21 | 22 | func port() string { 23 | port := os.Getenv("PORT") 24 | if len(port) == 0 { 25 | port = "8080" 26 | } 27 | return ":" + port 28 | } 29 | 30 | func index(w http.ResponseWriter, r *http.Request) { 31 | w.WriteHeader(http.StatusOK) 32 | fmt.Fprintf(w, "Welcome to Cloud Native Go.") 33 | } 34 | -------------------------------------------------------------------------------- /marathon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cat > $APP_NAME.json <