Skip to content

Commit

Permalink
chore: add kube manifests and revert using echo
Browse files Browse the repository at this point in the history
  • Loading branch information
kameshsampath committed Feb 1, 2023
1 parent 53e663e commit 9a1234f
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 3 deletions.
26 changes: 26 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://taskfile.dev

version: '3'

dotenv:
- .env

tasks:
clean:
cmds:
- git reset --soft HEAD~1
- git tag --delete v0.0.100-next
silent: true
ignore_error: true
tag:
cmds:
- git add .
- git commit -a -m "test and check for kos"
- git tag -a v0.0.100-next -m "test and check for kos"
silent: true
release:
cmds:
- ./goreleaser release --clean --debug
deps:
- clean
- tag
24 changes: 24 additions & 0 deletions config/serverfull/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
serviceAccountName: hello-world
containers:
- name: hello-world
image: docker.io/kameshsampath/go-hello-world
resources:
limits:
memory: "50Mi"
cpu: "50m"
ports:
- containerPort: 8080
name: http
4 changes: 4 additions & 0 deletions config/serverfull/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- sa.yaml
- service.yaml
- deployment.yaml
4 changes: 4 additions & 0 deletions config/serverfull/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: hello-world
10 changes: 10 additions & 0 deletions config/serverfull/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- port: 8080
targetPort: http
3 changes: 3 additions & 0 deletions config/serverless/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- sa.yaml
- service.yaml
4 changes: 4 additions & 0 deletions config/serverless/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: hello-world
13 changes: 13 additions & 0 deletions config/serverless/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello-world
spec:
template:
spec:
serviceAccountName: hello-world
containers:
- image: docker.io/kameshsampath/go-hello-world
env:
- name: GREETING_PREFIX
value: "Hello"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/kameshsampath/go-hello-world
go 1.18

require (
github.com/caarlos0/env/v7 v7.0.0
github.com/labstack/echo/v4 v4.7.2
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand All @@ -19,5 +21,6 @@ require (
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
github.com/caarlos0/env/v7 v7.0.0 h1:cyczlTd/zREwSr9ch/mwaDl7Hse7kJuUY8hvHfXu5WI=
github.com/caarlos0/env/v7 v7.0.0/go.mod h1:LPPWniDUq4JaO6Q41vtlyikhMknqymCLBw0eX4dcH1E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/labstack/echo/v4 v4.7.2 h1:Kv2/p8OaQ+M6Ex4eGimg9b9e6icoxA42JSlOR3msKtI=
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
Expand Down Expand Up @@ -28,6 +32,8 @@ golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1U
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
27 changes: 24 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
package main

import (
"fmt"
"net/http"

"github.com/caarlos0/env/v7"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)

const greeting = "Hello, World!"
type Greeting struct {
Prefix string `env:"GREETING_PREFIX" envDefault:"Hello"`
Name string `query:"name"`
Message string
}

func main() {
e := echo.New()

e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET("/", sayHello)
e.Logger.Fatal(e.Start(":8080"))
}

func sayHello(c echo.Context) error {
return c.String(http.StatusOK, greeting)
var greeting Greeting
err := env.Parse(&greeting)
if err != nil {
return err
}

err = c.Bind(&greeting)
if err != nil {
greeting.Name = "Anonymous"
}

greeting.Message = fmt.Sprintf("%s,%s", greeting.Prefix, greeting.Name)

return c.JSON(http.StatusOK, greeting)
}

0 comments on commit 9a1234f

Please sign in to comment.