Skip to content

Commit

Permalink
feat: Simplifyin teapot
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Mar 16, 2021
1 parent c9e6b31 commit ecce11f
Show file tree
Hide file tree
Showing 17 changed files with 3 additions and 134 deletions.
33 changes: 1 addition & 32 deletions cmd/goweb/api.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"embed"
"flag"
"net/http"
"os"
"strconv"
"strings"

"github.com/ViBiOh/goweb/pkg/delay"
Expand All @@ -19,7 +17,6 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/logger"
"github.com/ViBiOh/httputils/v4/pkg/owasp"
"github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/renderer"
"github.com/ViBiOh/httputils/v4/pkg/server"
)

Expand All @@ -29,23 +26,6 @@ const (
delayPath = "/delay"
)

//go:embed templates static
var content embed.FS

func askedStatus(r *http.Request) int {
status := http.StatusTeapot

if userStatus := r.URL.Query().Get("status"); len(userStatus) != 0 {
if rawStatus, err := strconv.Atoi(userStatus); err != nil {
logger.Error("unable to parse wanted status: %s", err)
} else if rawStatus < http.StatusInternalServerError {
status = rawStatus
}
}

return status
}

func main() {
fs := flag.NewFlagSet("api", flag.ExitOnError)

Expand All @@ -58,7 +38,6 @@ func main() {
prometheusConfig := prometheus.Flags(fs, "prometheus")
owaspConfig := owasp.Flags(fs, "")
corsConfig := cors.Flags(fs, "cors")
rendererConfig := renderer.Flags(fs, "", flags.NewOverride("PublicURL", "https://api.vibioh.fr"), flags.NewOverride("Title", "I'm a teapot 🫖"))

helloConfig := hello.Flags(fs, "")

Expand All @@ -73,15 +52,9 @@ func main() {
prometheusApp := prometheus.New(prometheusConfig)
healthApp := health.New(healthConfig)

rendererApp, err := renderer.New(rendererConfig, content, nil)
logger.Fatal(err)

helloHandler := http.StripPrefix(helloPath, hello.Handler(helloConfig))
dumpHandler := http.StripPrefix(dumpPath, dump.Handler())
delayHandler := http.StripPrefix(delayPath, delay.Handler())
rendererHandler := rendererApp.Handler(func(r *http.Request) (string, int, map[string]interface{}, error) {
return "public", askedStatus(r), nil, nil
})

appHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, helloPath) {
Expand All @@ -97,11 +70,7 @@ func main() {
return
}

if strings.Contains(r.Header.Get("Accept"), "text/html") {
rendererHandler.ServeHTTP(w, r)
} else {
w.WriteHeader(askedStatus(r))
}
w.WriteHeader(http.StatusTeapot)
})

go promServer.Start("prometheus", healthApp.End(), prometheusApp.Handler())
Expand Down
Binary file removed cmd/goweb/static/favicon/android-chrome-192x192.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/android-chrome-512x512.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/apple-touch-icon.png
Binary file not shown.
9 changes: 0 additions & 9 deletions cmd/goweb/static/favicon/browserconfig.xml

This file was deleted.

Binary file removed cmd/goweb/static/favicon/favicon-16x16.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/favicon-32x32.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/favicon.ico
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/mstile-144x144.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/mstile-150x150.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/mstile-310x150.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/mstile-310x310.png
Binary file not shown.
Binary file removed cmd/goweb/static/favicon/mstile-70x70.png
Binary file not shown.
40 changes: 0 additions & 40 deletions cmd/goweb/static/favicon/safari-pinned-tab.svg

This file was deleted.

19 changes: 0 additions & 19 deletions cmd/goweb/static/favicon/site.webmanifest

This file was deleted.

33 changes: 0 additions & 33 deletions cmd/goweb/templates/index.html

This file was deleted.

3 changes: 2 additions & 1 deletion infra/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
Expand Down Expand Up @@ -31,4 +32,4 @@ spec:
ingress:
enabled: true
hosts:
- api.vibioh.fr
- api.vibioh.fr

0 comments on commit ecce11f

Please sign in to comment.