mirror of
https://github.com/Unkn0wnCat/matrix-veles.git
synced 2025-04-29 02:07:37 +02:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"github.com/Unkn0wnCat/matrix-veles/internal/web/api"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"github.com/spf13/viper"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func StartServer() {
|
|
if viper.GetString("bot.web.secret") == "hunter2" {
|
|
log.Println("Web secret is not set! REFUSING TO START WEB SERVER!")
|
|
return
|
|
}
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Use(middleware.Logger)
|
|
|
|
r.Handle("/metrics", promhttp.Handler())
|
|
|
|
r.HandleFunc("/", HomeHandler)
|
|
//r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
|
|
|
r.Mount("/api", api.SetupAPI())
|
|
|
|
srv := &http.Server{
|
|
Handler: r,
|
|
Addr: viper.GetString("bot.web.listen"),
|
|
WriteTimeout: 15 * time.Second,
|
|
ReadTimeout: 15 * time.Second,
|
|
}
|
|
|
|
log.Printf("Now serving web-interface on http://%s", viper.GetString("bot.web.listen"))
|
|
|
|
log.Fatal(srv.ListenAndServe())
|
|
}
|
|
|
|
func HomeHandler(writer http.ResponseWriter, request *http.Request) {
|
|
writer.WriteHeader(200)
|
|
writer.Write([]byte("hello world"))
|
|
}
|