├── .DS_Store ├── .dccache ├── .github └── workflows │ ├── codeql-analysis.yml │ └── testing.yml ├── DockerHub └── push-to-dockerhub.md ├── Dockerfile ├── Dockerfile-old ├── Kubernetes └── gokubernetes.yaml ├── README.md ├── azure-pipelines.yml ├── cloudnative-build-pack-instructions.md ├── go.mod ├── instructions.md ├── main ├── main.exe └── main.go /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdminTurnedDevOps/GoWebAPI/2957a8a3a72581671e3fe8e859a22ba1091ee00c/.DS_Store -------------------------------------------------------------------------------- /.dccache: -------------------------------------------------------------------------------- 1 | {"/Users/michael/gitrepos/GoWebAPI/main.go":[928,1672924401009.026,"f301f4bdbd4c4859d5a6b22862f53ca22cec71f6b638f45aaa1451b4636dd74a"]} -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | 21 | jobs: 22 | analyze: 23 | name: Analyze 24 | runs-on: ubuntu-latest 25 | 26 | strategy: 27 | fail-fast: false 28 | matrix: 29 | language: [ 'go' ] 30 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 31 | # Learn more: 32 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 33 | 34 | steps: 35 | - name: Checkout repository 36 | uses: actions/checkout@v2 37 | 38 | # Initializes the CodeQL tools for scanning. 39 | - name: Initialize CodeQL 40 | uses: github/codeql-action/init@v1 41 | with: 42 | languages: ${{ matrix.language }} 43 | # If you wish to specify custom queries, you can do so here or in a config file. 44 | # By default, queries listed here will override any specified in a config file. 45 | # Prefix the list here with "+" to use these queries and those in the config file. 46 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 47 | 48 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 49 | # If this step fails, then you should remove it and run the build manually (see below) 50 | - name: Autobuild 51 | uses: github/codeql-action/autobuild@v1 52 | 53 | # ℹ️ Command-line programs to run using the OS shell. 54 | # 📚 https://git.io/JvXDl 55 | 56 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 57 | # and modify them (or add more) to build your code if your project 58 | # uses a compiled language 59 | 60 | #- run: | 61 | # make bootstrap 62 | # make release 63 | 64 | - name: Perform CodeQL Analysis 65 | uses: github/codeql-action/analyze@v1 66 | -------------------------------------------------------------------------------- /.github/workflows/testing.yml: -------------------------------------------------------------------------------- 1 | name: 'Go Web App Testing' 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | deploy: 11 | name: GoWebAPI Test 12 | runs-on: ubuntu-latest 13 | 14 | defaults: 15 | run: 16 | shell: bash 17 | 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v4 21 | 22 | - name: Set up Snyk CLI to check for security issues 23 | uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb 24 | 25 | - name: Snyk Auth 26 | run: snyk auth ${{ secrets.snykToken }} 27 | 28 | - name: Snyk SCA Go 29 | run: snyk test --org=${{ secrets.snykOrg }} 30 | 31 | - name: Snyk SAST 32 | run: snyk code test --org=${{ secrets.snykOrg }} 33 | 34 | - name: Build a Docker image to test for vulnerabilities 35 | run: docker build -t gowebapi . 36 | - name: Snyk Container monitor 37 | run: snyk container test gowebapi --file=Dockerfile 38 | 39 | -------------------------------------------------------------------------------- /DockerHub/push-to-dockerhub.md: -------------------------------------------------------------------------------- 1 | # Log into Dockerhub 2 | docker login --username=yourhubusername (you will be prompted for your password) 3 | 4 | # Tag the Docker image 5 | docker tag golangwebapi adminturneddevops/golangwebapi:latest 6 | 7 | # Push the Docker image to DockerHub 8 | docker push adminturneddevops/golangwebapi:latest -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.22-alpine 2 | 3 | RUN mkdir /app 4 | 5 | ADD . /app 6 | 7 | WORKDIR /app 8 | 9 | RUN go build -o main . 10 | 11 | EXPOSE 8080 12 | 13 | CMD [ "/app/main" ] -------------------------------------------------------------------------------- /Dockerfile-old: -------------------------------------------------------------------------------- 1 | FROM golang:latest 2 | 3 | RUN mkdir /build 4 | WORKDIR /build 5 | 6 | RUN export GO111MODULE=on 7 | #RUN go get github.com/AdminTurnedDevOps/GoWebAPI/app 8 | RUN cd /build && git clone https://github.com/AdminTurnedDevOps/GoWebAPI.git 9 | 10 | #RUN cd /build/GoWebAPI/app && go build 11 | 12 | EXPOSE 8080 13 | 14 | ENTRYPOINT [ "/build/GoWebAPI/main" ] -------------------------------------------------------------------------------- /Kubernetes/gokubernetes.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: gowebapi 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: gowebapi 9 | replicas: 2 10 | template: 11 | metadata: 12 | labels: 13 | app: gowebapi 14 | spec: 15 | containers: 16 | - name: gowebapi 17 | image: adminturneddevops/gowebapi:latest 18 | ports: 19 | - containerPort: 8080 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: gowebapi 25 | spec: 26 | selector: 27 | app: gowebapi 28 | ports: 29 | - protocol: TCP 30 | port: 8080 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoWebAPI 2 | Example Go web API 3 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | 4 | pool: 5 | vmImage: 'ubuntu-latest' 6 | 7 | steps: 8 | - task: CopyFiles@2 9 | inputs: 10 | Contents: '**' 11 | TargetFolder: '$(Build.ArtifactStagingDirectory)' 12 | 13 | - task: PublishBuildArtifacts@1 14 | inputs: 15 | PathtoPublish: '$(Build.ArtifactStagingDirectory)' 16 | ArtifactName: 'drop' 17 | 18 | - task: GoTool@0 19 | inputs: 20 | version: '1.15' 21 | 22 | - task: Go@0 23 | inputs: 24 | command: 'build' 25 | workingDirectory: '$(Build.ArtifactStagingDirectory)/main' -------------------------------------------------------------------------------- /cloudnative-build-pack-instructions.md: -------------------------------------------------------------------------------- 1 | `pack build gocloudpack --builder gcr.io/buildpacks/builder:v1 --path .` 2 | 3 | The `--builder` is the base image. If you leave that flag off, it'll give recommendations -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /instructions.md: -------------------------------------------------------------------------------- 1 | Run the following commands: 2 | 3 | 1. docker build -t golangwebapi . 4 | 2. docker run -p 8080:8080 -tid golangwebapi -------------------------------------------------------------------------------- /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdminTurnedDevOps/GoWebAPI/2957a8a3a72581671e3fe8e859a22ba1091ee00c/main -------------------------------------------------------------------------------- /main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdminTurnedDevOps/GoWebAPI/2957a8a3a72581671e3fe8e859a22ba1091ee00c/main.exe -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | ) 9 | 10 | type whoami struct { 11 | Name string 12 | Title string 13 | State string 14 | } 15 | 16 | func main() { 17 | request1() 18 | } 19 | 20 | func whoAmI(response http.ResponseWriter, r *http.Request) { 21 | who := []whoami{ 22 | whoami{Name: "Michael Levan", 23 | Title: "Kubernetes Engineer", 24 | State: "NJ", 25 | }, 26 | } 27 | 28 | json.NewEncoder(response).Encode(who) 29 | 30 | fmt.Println("Endpoint Hit", who) 31 | } 32 | 33 | func homePage(response http.ResponseWriter, r *http.Request) { 34 | fmt.Fprintf(response, "Welcome to the Go Web API!") 35 | fmt.Println("Endpoint Hit: homePage") 36 | } 37 | 38 | func aboutMe(response http.ResponseWriter, r *http.Request) { 39 | who := "MichaelLevan" 40 | 41 | fmt.Fprintf(response, "A little bit about Michael Levan...") 42 | fmt.Println("Endpoint Hit: ", who) 43 | } 44 | 45 | func request1() { 46 | http.HandleFunc("/", homePage) 47 | http.HandleFunc("/aboutme", aboutMe) 48 | http.HandleFunc("/whoami", whoAmI) 49 | 50 | log.Fatal(http.ListenAndServe(":8080", nil)) 51 | } 52 | --------------------------------------------------------------------------------