embed nullboard.html

master
Bel LaPointe 2021-03-29 07:41:55 -05:00
parent cd97b34d22
commit 790a898894
1 changed files with 10 additions and 3 deletions

13
main.go
View File

@ -1,6 +1,7 @@
package main
import (
_ "embed"
"encoding/json"
"fmt"
"io"
@ -11,6 +12,9 @@ import (
"net/http"
)
//go:embed nullboard.html
var nullboard string
type server struct {
db storage.DBStream
crud bool
@ -21,10 +25,14 @@ func main() {
as.Append(args.INT, "p", "port", 8121)
as.Append(args.STRING, "db", "db type", "mapstream")
as.Append(args.STRING, "dbaddr", "db addr", "/tmp/db")
as.Append(args.STRING, "level", "debug level", "info")
as.Append(args.BOOL, "nocrud", "no support CRUD api", false)
if err := as.Parse(); err != nil {
panic(err)
}
logb.Set(logb.LevelFromString(as.GetString("level")))
logb.Debugf("nullboard=%v", len(nullboard))
db, err := storage.New(storage.TypeFromString(as.GetString("db")), as.GetString("dbaddr"))
if err != nil {
@ -50,7 +58,6 @@ func (server server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer w2.Close()
w = w2
}
fileServer := http.FileServer(http.Dir("./"))
switch r.URL.Path {
case "/api":
if server.crud {
@ -61,8 +68,8 @@ func (server server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
default:
logb.Debug("serving dir", r.URL.Path)
fileServer.ServeHTTP(w, r)
logb.Debug("serving nullboard.html", r.URL.Path)
fmt.Fprintln(w, nullboard)
return
}
logb.Debug("404", r.URL.Path)