~sircmpwn/chartsrv-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Add /chart.png path

Details
Message ID
<20201021230447.6497-1-noam@pixelhero.dev>
DKIM signature
fail
Download raw message
Patch: +22 -15 DKIM signature: fail
---
 main.go | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/main.go b/main.go
index 2bce2d7..0eab06f 100644
--- a/main.go
+++ b/main.go
@@ -126,19 +126,8 @@ func metricName(metric map[string]string) string {
	return out + "{" + strings.Join(inner, ",") + "}"
}

func main() {
	plotutil.DefaultDashes = [][]vg.Length{{}}

	if len(os.Args) < 2 {
		fmt.Printf("Usage: %s server\n", os.Args[0])
		os.Exit(1)
	}
	upstream = os.Args[1]
	router := chi.NewRouter()
	router.Use(middleware.RealIP)
	router.Use(middleware.Logger)

	router.Get("/chart.svg", func(w http.ResponseWriter, r *http.Request) {
func registerExtension(router chi.Router, extension string, mime string) {
	router.Get("/chart."+extension, func(w http.ResponseWriter, r *http.Request) {
		args := r.URL.Query()
		var query string
		if q, ok := args["query"]; !ok {
@@ -261,17 +250,35 @@ func main() {
			p.Add(plotters[i])
		}

		writer, err := p.WriterTo(width, height, "svg")
		writer, err := p.WriterTo(width, height, extension)
		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(fmt.Sprintf("%v", err)))
			return
		}

		w.Header().Add("Content-Type", "image/svg+xml")
		w.Header().Add("Content-Type", mime)
		writer.WriteTo(w)
	})

}

func main() {
	plotutil.DefaultDashes = [][]vg.Length{{}}

	if len(os.Args) < 2 {
		fmt.Printf("Usage: %s server\n", os.Args[0])
		os.Exit(1)
	}
	upstream = os.Args[1]
	router := chi.NewRouter()

	router.Use(middleware.RealIP)
	router.Use(middleware.Logger)

	registerExtension(router, "svg", "image/svg+xml")
	registerExtension(router, "png", "image/png")

	addr := ":8142"
	if len(os.Args) > 2 {
		addr = os.Args[2]
-- 
2.28.0
Details
Message ID
<C6L7FDL9NXCZ.22YX5XGOFLP3O@taiga>
In-Reply-To
<20201021230447.6497-1-noam@pixelhero.dev> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Thanks!

To git@git.sr.ht:~sircmpwn/chartsrv
   ad2375c..  master -> master
Reply to thread Export thread (mbox)