sim offline and assert offline support
parent
6670a6de6c
commit
8feeceffe4
9
main.go
9
main.go
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
db storage.DBStream
|
db storage.DBStream
|
||||||
|
crud bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -20,6 +21,7 @@ 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.BOOL, "nocrud", "no support CRUD api", false)
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -32,6 +34,7 @@ func main() {
|
||||||
|
|
||||||
server := server{
|
server := server{
|
||||||
db: dbs,
|
db: dbs,
|
||||||
|
crud: !as.GetBool("nocrud"),
|
||||||
}
|
}
|
||||||
addr := fmt.Sprintf(":%d", as.GetInt("p"))
|
addr := fmt.Sprintf(":%d", as.GetInt("p"))
|
||||||
|
|
||||||
|
|
@ -50,14 +53,20 @@ func (server server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
fileServer := http.FileServer(http.Dir("./"))
|
fileServer := http.FileServer(http.Dir("./"))
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/api":
|
case "/api":
|
||||||
|
if server.crud {
|
||||||
logb.Debug("serving api", r.URL.Path, r.URL.Query())
|
logb.Debug("serving api", r.URL.Path, r.URL.Query())
|
||||||
if err := server.apiHandler(w, r); err != nil {
|
if err := server.apiHandler(w, r); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
logb.Debug("serving dir", r.URL.Path)
|
logb.Debug("serving dir", r.URL.Path)
|
||||||
fileServer.ServeHTTP(w, r)
|
fileServer.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
logb.Debug("404", r.URL.Path)
|
||||||
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server server) apiHandler(w http.ResponseWriter, r *http.Request) error {
|
func (server server) apiHandler(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
|
||||||
|
|
@ -1337,6 +1337,8 @@
|
||||||
|
|
||||||
syncCacheWithPrimary()
|
syncCacheWithPrimary()
|
||||||
{
|
{
|
||||||
|
if (this.pendingSyncCount())
|
||||||
|
return;
|
||||||
this.syncAWithB(this.cache(), this.primary());
|
this.syncAWithB(this.cache(), this.primary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue