2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-12 11:13:26 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-12 04:14:09 -06:00
|
|
|
"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()
|
2024-01-12 11:13:26 -06:00
|
|
|
url, repourl := findkey(tmp)
|
|
|
|
log.Info("url =", url, "repo url =", repourl)
|
2024-01-12 11:39:36 -06:00
|
|
|
if repourl != "" {
|
|
|
|
doGui(w, url, repourl)
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 12:26:05 -06:00
|
|
|
if tmp == "/" {
|
|
|
|
findFile(w, "files/index.html")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tmp == "/new" {
|
|
|
|
indexHeader(w)
|
|
|
|
indexBodyStart(w)
|
2024-01-12 12:40:54 -06:00
|
|
|
indexBodyRepo(w, "go.wit.com/gui/gui")
|
2024-01-12 12:26:05 -06:00
|
|
|
indexBodyEnd(w)
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 04:14:09 -06:00
|
|
|
if tmp == "/test" {
|
2024-01-12 11:55:45 -06:00
|
|
|
findFile(w, "files/repo.html")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tmp == "/skeleton.v2.css" {
|
|
|
|
findFile(w, "files/skeleton.v2.css")
|
2024-01-12 04:14:09 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-12 11:55:45 -06:00
|
|
|
fmt.Fprintln(w, "BAD", tmp)
|
2024-01-12 04:14:09 -06:00
|
|
|
}
|
|
|
|
|
2024-01-12 11:55:45 -06:00
|
|
|
func findFile(w http.ResponseWriter, filename string) {
|
|
|
|
// fmt.Fprintln(w, "GOT TEST?")
|
|
|
|
pfile, err := htmlFiles.ReadFile(filename)
|
2024-01-12 04:14:09 -06:00
|
|
|
if (err != nil) {
|
2024-01-12 11:55:45 -06:00
|
|
|
log.Println("ERROR:", err)
|
2024-01-12 04:14:09 -06:00
|
|
|
// w.Write(pfile)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var repohtml string
|
|
|
|
repohtml = string(pfile)
|
2024-01-12 11:55:45 -06:00
|
|
|
fmt.Fprintln(w, repohtml)
|
|
|
|
log.Println("findFile() found internal file:", filename)
|
2024-01-12 04:14:09 -06:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
*/
|
2024-01-12 04:44:36 -06:00
|
|
|
readconfigfile()
|
2024-01-12 04:14:09 -06:00
|
|
|
http.HandleFunc("/", okHandler)
|
2024-01-12 12:26:05 -06:00
|
|
|
https()
|
2024-01-12 04:14:09 -06:00
|
|
|
err := http.ListenAndServe(":80", nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Error starting server:", err)
|
|
|
|
}
|
|
|
|
}
|