Flags for listen and metrics address; fix in newRedirectPasteSuccess.txt.tmpl

Fixes #9
This commit is contained in:
Gerdriaan Mulder 2019-11-09 21:43:51 +01:00
parent e26e37c97d
commit b738116f8a
5 changed files with 15 additions and 16 deletions

View File

@ -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}}

View File

@ -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)
}

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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"