├── .github └── workflows │ └── go.yml ├── .gitignore ├── Dockerfile ├── README.md ├── go.mod ├── go.sum ├── main.go └── releases ├── api-linux64 └── api-osx-amd64 /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: CICD 2 | 3 | on: 4 | push: 5 | tags: 6 | - '1.*.*' 7 | pull_request: 8 | branches: 9 | - master 10 | # schedule: 11 | # - cron: "0 0 * * *" 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - name: Set env 20 | run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV 21 | 22 | - name: Set up Go 23 | uses: actions/setup-go@v2 24 | with: 25 | go-version: 1.19 26 | 27 | - name: Build 28 | run: | 29 | sed -i 's/TOKEN_VERSION/${{ env.RELEASE_VERSION }}/g' main.go 30 | go get -v -t -d ./... 31 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api 32 | tar -czf release-${{ env.RELEASE_VERSION }}.linux-amd64.tar.gz api 33 | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o api 34 | tar -czf release-${{ env.RELEASE_VERSION }}.linux-arm64.tar.gz api 35 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o api 36 | tar -czf release-${{ env.RELEASE_VERSION }}.darwin-amd64.tar.gz api 37 | ls -la 38 | 39 | - name: Upload Artifact 40 | uses: actions/upload-artifact@v2 41 | with: 42 | name: release-${{ env.RELEASE_VERSION }} 43 | path: | 44 | release-${{ env.RELEASE_VERSION }}.linux-amd64.tar.gz 45 | release-${{ env.RELEASE_VERSION }}.linux-arm64.tar.gz 46 | release-${{ env.RELEASE_VERSION }}.darwin-amd64.tar.gz 47 | 48 | # Create Release v1 49 | - name: Make Release 50 | uses: softprops/action-gh-release@v0.1.5 51 | if: startsWith(github.ref, 'refs/tags/') 52 | with: 53 | name: release-${{ env.RELEASE_VERSION }} 54 | files: | 55 | release-${{ env.RELEASE_VERSION }}.linux-amd64.tar.gz 56 | release-${{ env.RELEASE_VERSION }}.linux-arm64.tar.gz 57 | release-${{ env.RELEASE_VERSION }}.darwin-amd64.tar.gz 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | api 2 | .DS_Store -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | MAINTAINER Jeremy Cook 4 | 5 | COPY api . 6 | 7 | EXPOSE 8080 8 | 9 | CMD ["./api"] 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Build Status](https://github.com/cloudacademy/voteapp-api-go/actions/workflows/go.yml/badge.svg) 2 | ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/cloudacademy/voteapp-api-go) 3 | 4 | # Background 5 | Provides a CRUD based API written in Go. The API is designed to read and write into a MongoDB backend database. 6 | 7 | # API endpoints 8 | The API provides the following endpoints: 9 | ``` 10 | GET /ok 11 | GET /cpu 12 | GET /version 13 | GET /languages 14 | GET /languages/{name} 15 | GET /languages/{name}/vote 16 | POST /languages/{name} 17 | DELETE /languages/{name} 18 | ``` 19 | 20 | # API GETs with curl and jq 21 | The API can be used to perform GETs with **curl** and **jq** like so: 22 | ``` 23 | curl -s http://localhost:8080/languages | jq . 24 | curl -s http://localhost:8080/languages/{name} | jq . 25 | curl -s http://localhost:8080/languages/{name}/vote | jq . 26 | ``` 27 | 28 | # API POSTs with curl 29 | The API can be used to perform POSTs with **curl** like so: 30 | ``` 31 | curl http://localhost:8080/languages/{name} \ 32 | --header "Content-Type: application/json" \ 33 | --request POST \ 34 | --data-binary @- <