sim offline and assert offline support
parent
6670a6de6c
commit
8feeceffe4
19
main.go
19
main.go
|
|
@ -12,7 +12,8 @@ import (
|
|||
)
|
||||
|
||||
type server struct {
|
||||
db storage.DBStream
|
||||
db storage.DBStream
|
||||
crud bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
@ -20,6 +21,7 @@ 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.BOOL, "nocrud", "no support CRUD api", false)
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -31,7 +33,8 @@ func main() {
|
|||
dbs := db.(storage.DBStream)
|
||||
|
||||
server := server{
|
||||
db: dbs,
|
||||
db: dbs,
|
||||
crud: !as.GetBool("nocrud"),
|
||||
}
|
||||
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("./"))
|
||||
switch r.URL.Path {
|
||||
case "/api":
|
||||
logb.Debug("serving api", r.URL.Path, r.URL.Query())
|
||||
if err := server.apiHandler(w, r); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
if server.crud {
|
||||
logb.Debug("serving api", r.URL.Path, r.URL.Query())
|
||||
if err := server.apiHandler(w, r); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
default:
|
||||
logb.Debug("serving dir", r.URL.Path)
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -1337,6 +1337,8 @@
|
|||
|
||||
syncCacheWithPrimary()
|
||||
{
|
||||
if (this.pendingSyncCount())
|
||||
return;
|
||||
this.syncAWithB(this.cache(), this.primary());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue