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