diff --git a/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl b/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl index c02e1d8..84b1a3e 100644 --- a/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl +++ b/assets/templates/txt/newRedirectPasteSuccess.txt.tmpl @@ -1,4 +1,4 @@ -{{- if .Request.PostForm.deleteToken -}} +{{if .Request.PostForm.deleteToken -}} {{.Request.Host}}/{{.Paste.Key}}?deleteToken={{.Paste.DeleteToken | urlquery}} {{else -}} {{.Request.Host}}/{{.Paste.Key}} diff --git a/cmd/rushlink/main.go b/cmd/rushlink/main.go index 5b9803d..b83a937 100644 --- a/cmd/rushlink/main.go +++ b/cmd/rushlink/main.go @@ -7,17 +7,20 @@ import ( "gitea.hashru.nl/dsprenkels/rushlink" ) -func main() { - var databasePath string +var ( + databasePath = flag.String("database", "", "location of the database file") + httpListen = flag.String("listen", "127.0.0.1:8000", "listen address (host:port)") + metricsListen = flag.String("metrics_listen", "127.0.0.1:58614", "listen address for metrics (host:port)") +) - flag.StringVar(&databasePath, "database", "", "Location of the database file") +func main() { flag.Parse() - if err := rushlink.Open(databasePath); err != nil { + if err := rushlink.Open(*databasePath); err != nil { log.Fatalln(err) } defer rushlink.Close() - go rushlink.StartMetricsServer() - rushlink.StartMainServer() + go rushlink.StartMetricsServer(*metricsListen) + rushlink.StartMainServer(*httpListen) } diff --git a/metrics.go b/metrics.go index 47b62f4..f6fc96f 100644 --- a/metrics.go +++ b/metrics.go @@ -13,11 +13,7 @@ import ( bolt "go.etcd.io/bbolt" ) -const ( - METRICS_ADDR = "127.0.0.1:58614" -) - -func StartMetricsServer() { +func StartMetricsServer(addr string) { var ( _ = promauto.NewGaugeFunc(prometheus.GaugeOpts{ Namespace: "rushlink", @@ -45,7 +41,7 @@ func StartMetricsServer() { router.Handle("/metrics", promhttp.Handler()).Methods("GET") srv := &http.Server{ Handler: router, - Addr: METRICS_ADDR, + Addr: addr, WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second, } diff --git a/router.go b/router.go index be723af..1ea3361 100644 --- a/router.go +++ b/router.go @@ -28,7 +28,7 @@ func recoveryMiddleware(next http.Handler) http.Handler { }) } -func StartMainServer() { +func StartMainServer(addr string) { // Initialize Gorilla router router := mux.NewRouter() router.Use(recoveryMiddleware) @@ -42,7 +42,7 @@ func StartMainServer() { srv := &http.Server{ Handler: router, - Addr: "127.0.0.1:8000", + Addr: addr, WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second, } diff --git a/views.go b/views.go index ad35ae2..0043dd8 100644 --- a/views.go +++ b/views.go @@ -1,6 +1,6 @@ package rushlink -//go:generate go-bindata -pkg $GOPACKAGE -prefix ./assets ./assets/... +//go:generate go-bindata -pkg $GOPACKAGE -prefix assets/ assets/... import ( "bytes"