netflux-homepage/main.go

46 lines
1018 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")
2024-11-19 18:55:01 +00:00
rootPath := os.Getenv("NETFLUX_ROOT_PATH")
if matrixHostname == "" || matrixBaseURL == "" || rootPath == "" {
log.Fatal("NETFLUX_MATRIX_HOSTNAME and NETFLUX_MATRIX_BASE_URL and NETFLUX_ROOT_PATH are all required")
2022-06-06 16:48:53 +00:00
}
listenAddr := os.Getenv("NETFLUX_LISTEN_ADDR")
if listenAddr == "" {
listenAddr = defaultListenAddr
}
server := http.Server{
2024-11-19 18:55:01 +00:00
Addr: listenAddr,
Handler: handler.New(handler.Params{
MatrixHostname: matrixHostname,
MatrixBaseURL: matrixBaseURL,
RootPath: rootPath,
}),
2022-06-06 16:48:53 +00:00
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
}
if err := server.ListenAndServe(); err != nil {
log.Fatalf("server error: %v", err)
}
}