netflux-homepage/main.go

41 lines
860 B
Go
Raw Normal View History

2022-06-06 16:48:53 +00:00
package main
import (
"log"
"net/http"
"os"
"time"
"git.netflux.io/rob/netflux-homepage/handler"
)
const (
readTimeout = time.Second * 3
writeTimeout = time.Second * 3
defaultListenAddr = ":9000"
)
func main() {
matrixHostname := os.Getenv("NETFLUX_MATRIX_HOSTNAME")
matrixBaseURL := os.Getenv("NETFLUX_MATRIX_BASE_URL")
if matrixHostname == "" || matrixBaseURL == "" {
log.Fatal("NETFLUX_MATRIX_HOSTNAME and NETFLUX_MATRIX_BASE_URL are both required")
}
listenAddr := os.Getenv("NETFLUX_LISTEN_ADDR")
if listenAddr == "" {
listenAddr = defaultListenAddr
}
server := http.Server{
Addr: listenAddr,
Handler: handler.New(matrixHostname, matrixBaseURL),
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
}
if err := server.ListenAndServe(); err != nil {
log.Fatalf("server error: %v", err)
}
}