57 lines
913 B
Go
57 lines
913 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func setRoutes(mux *http.ServeMux) {
|
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
|
|
Files := []string{}
|
|
for file := range files {
|
|
Files = append(Files, files[file].Alias)
|
|
}
|
|
|
|
data := struct {
|
|
Active string
|
|
Files []string
|
|
Content string
|
|
Lang string
|
|
Error string
|
|
Editor struct {
|
|
RO bool
|
|
}
|
|
}{
|
|
Files: Files,
|
|
Editor: struct{ RO bool }{},
|
|
}
|
|
|
|
content := ""
|
|
name := r.URL.Query().Get("name")
|
|
file, ok := files[name]
|
|
if name == "" || !ok {
|
|
contentB, err := GetConfig()
|
|
if err != nil {
|
|
content = err.Error()
|
|
} else {
|
|
content = string(contentB)
|
|
}
|
|
if !ok {
|
|
data.Error = name + " not found"
|
|
}
|
|
data.Active = "ConfigUI"
|
|
}
|
|
log.Println(file)
|
|
|
|
data.Content = content
|
|
|
|
Parse(w, "home", data)
|
|
})
|
|
}
|