41 lines
860 B
Go
41 lines
860 B
Go
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)
|
|
}
|
|
}
|