Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
feat: small go setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed May 29, 2024
1 parent 4132391 commit 84e484e
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 15 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ginTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: verfiy rocket showcase

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:


jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.21'
- uses: taiki-e/install-action@v2
with:
tool: just@1,hurl@4
- run: just verify-gin
4 changes: 0 additions & 4 deletions .github/workflows/rocketTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
pull_request:
workflow_dispatch:

env:
_JAVA_OPTS: "-Xmx2g"
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2 -Dorg.gradle.console=plain"

jobs:
verify:
runs-on: ubuntu-latest
Expand Down
11 changes: 7 additions & 4 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ set export

PORT := "5000"

alias verify := showcase

# show slides
show:
marp -s ./slides
Expand All @@ -18,15 +20,16 @@ install-scoop:
install:
brew install marp-cli

verify:
just showcase

showcase:
cd showcases/springboot && just verify
cd showcases/rocket && just verify
cd showcases/gin && just verify

verify-spring:
cd showcases/springboot && just verify

verify-rocket:
cd showcases/rocket && just verify
cd showcases/rocket && just verify

verify-gin:
cd showcases/gin && just verify
27 changes: 27 additions & 0 deletions showcases/gin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# syntax=docker/dockerfile:1

FROM golang:1.19

# Set destination for COPY
WORKDIR /app

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/reference/dockerfile/#copy
COPY *.go ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /docker-gs-ping

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 8002

# Run
CMD ["/docker-gs-ping"]
2 changes: 2 additions & 0 deletions showcases/gin/api_tests/hurl.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target=http://localhost:8002
token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjEyMDkxMDkyOTAifQ.eyJhdWQiOlsibG9jYWwubXlfZG9tYWluLmNvbSJdLCJhenAiOiJkMTlYcDhEWEkxQVE4ZUNjeDdweHM5bkZiUTRUMHUwdCIsImVtYWlsIjoiam9obi5kb2VAb3B0cmF2aXMuY29tIiwiZXhwIjozMjUwMzY3NjQwMCwiaWF0IjowLCJpc3MiOiJodHRwczovL2F1dGgubXlfZG9tYWluLmNvbS8iLCJteV9vdGhlcl9zcGVjaWFsX2NsYWltIjoiaGVsbG8gd29ybGQiLCJuYW1lIjoiSm9obiIsInN1YiI6IjcwZTQ5M2Q5LTg0ZDAtNDliMS05YjYzLWJkNTVmOTVhOTI3ZSJ9.NQQFnHJlL7xiKP-6tk3gYrKpYPW8eVga_u5x6t3-l8U
3 changes: 3 additions & 0 deletions showcases/gin/api_tests/implemented/healthz.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# wait for healthy
GET {{target}}/api/healthz
HTTP 200
9 changes: 9 additions & 0 deletions showcases/gin/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
service:
image: hurl-gin:latest
environment:
- 'PORT=8002'
- 'AUTH_HS256_SECRET=CTRKew35ltwdWhGv9WF10lJ06oYBZKzACYhANx7QXPZpvBvCNZbq161xHg2rKhcp'
- 'AUTH_JWT_AUD=local.my_domain.com'
ports:
- '8002:8002'
2 changes: 1 addition & 1 deletion showcases/gin/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module hurl-gin

go 1.22.1
go 1.21

require github.com/gin-gonic/gin v1.10.0

Expand Down
51 changes: 50 additions & 1 deletion showcases/gin/justfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@

image_name := "hurl-gin:latest"
hurl_opts := "--variables-file api_tests/hurl.env.test --test"

run:
go run main.go

test:
go test .

verify: test (up "-d") api-test lint
docker-compose down

install-dep:
go get -u github.com/gin-gonic/gin

up c="": build
docker-compose down
docker-compose up {{c}}

# Watch the source files and run `just verify` when source changes
watch:
cargo watch -- just verify

# Run the static code analysis
lint:
golangci-lint run

# Build docker image for testing
build:
docker build -t {{image_name}} .

wait-for-api:
hurl api_tests/implemented/healthz.hurl --retry 60 {{hurl_opts}}

pre-api-test:
hurl api/pre_test/*.hurl {{hurl_opts}}

# run acceptance tests against the running test stack
api-test *args: wait-for-api
hurl api_tests/implemented/*.hurl {{hurl_opts}} {{args}}

# run all acceptance tests against the running test stack, including for non-implemented api
api-test-not-implemented *args: wait-for-api
hurl api_tests/not_implemented/*.hurl {{hurl_opts}} {{args}}

# Install cargo dev-tools used by the `verify` recipe (requires rustup to be already installed)
install-dev-tools:
just install-linter

install-linter:
brew install golangci-lint
brew upgrade golangci-lint

install-hurl:
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl_4.1.0_amd64.deb
udo apt update && sudo apt install ./hurl_4.1.0_amd64.deb
rm hurl_4.1.0_amd64.deb


@replace-token:
cd token_creation && just replace
23 changes: 18 additions & 5 deletions showcases/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@ package main
import "github.com/gin-gonic/gin"
import "net/http"

import (
"log"
"os"
)

func setupRouter() *gin.Engine {
r := gin.Default()

// Get user value
r.GET("/healthz", func(c *gin.Context) {
r.GET("/api/healthz", func(c *gin.Context) {
c.Status(http.StatusOK)
})

return r
}

func main() {
r := setupRouter()
// Listen and Server in 0.0.0.0:8080
r.Run(":8002")
}
logx := log.New(os.Stdout, "hurl-example:", log.LstdFlags)

runner := setupRouter()
if runner != nil {
var result = runner.Run(":8002")
if result != nil {
logx.Println("Shutdown")
} else {
logx.Println("Shutdown with err")
}
}
}

0 comments on commit 84e484e

Please sign in to comment.