gowebd/main.go

83 lines
1.5 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"go.wit.com/log"
"net/http"
"embed"
)
//go:embed files/*
var htmlFiles embed.FS
func okHandler(w http.ResponseWriter, r *http.Request) {
dumpClient(r)
var tmp string
tmp = r.URL.String()
url, repourl := findkey(tmp)
log.Info("url =", url, "repo url =", repourl)
if repourl != "" {
doGui(w, url, repourl)
return
}
if tmp == "/" {
findFile(w, "files/index.html")
return
}
if tmp == "/new" {
indexHeader(w)
indexBodyStart(w)
indexBodyEnd(w)
return
}
if tmp == "/test" {
findFile(w, "files/repo.html")
return
}
if tmp == "/skeleton.v2.css" {
findFile(w, "files/skeleton.v2.css")
return
}
fmt.Fprintln(w, "BAD", tmp)
}
func findFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?")
pfile, err := htmlFiles.ReadFile(filename)
if (err != nil) {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
var repohtml string
repohtml = string(pfile)
fmt.Fprintln(w, repohtml)
log.Println("findFile() found internal file:", filename)
// w.Close()
/*
filename = "/tmp/" + name + ".so"
log.Error(err, "write out file here", name, filename, len(pfile))
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
f.Close()
*/
}
func main() {
/*
pfile, err := htmlFiles.ReadFile("html/repo.html")
if (err != nil) {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
*/
readconfigfile()
http.HandleFunc("/", okHandler)
https()
err := http.ListenAndServe(":80", nil)
if err != nil {
log.Println("Error starting server:", err)
}
}