Group config flags
This commit is contained in:
parent
e7206d431c
commit
c8603dc6ee
|
@ -58,7 +58,7 @@ There are a few command line flags that can be used to change the behaviour of t
|
|||
`data`)
|
||||
- `-maxsize $size`: changes the maximum size of a sync (in bytes) that can be accepted by the API. The default is set
|
||||
to 512000.
|
||||
- `-maxsyncs $num`: change the maximum number of syncs that can be stored. Default is 100000.
|
||||
- `-maxsyncs $num`: change the maximum number of syncs that can be stored. Default is 10000.
|
||||
|
||||
## Roadmap
|
||||
|
||||
|
|
|
@ -27,10 +27,14 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
config struct {
|
||||
listen string
|
||||
store string
|
||||
maxSyncSize int
|
||||
maxSyncs int
|
||||
}
|
||||
|
||||
store bsync.Store
|
||||
maxSyncSize = defaultMaxSyncSize
|
||||
maxSyncs = defaultMaxSyncs
|
||||
listen string
|
||||
serviceStatus = statusOnline
|
||||
sidRe = regexp.MustCompile("^[[:xdigit:]]{32}$")
|
||||
|
||||
|
@ -79,7 +83,7 @@ func info(w http.ResponseWriter, req *http.Request) {
|
|||
Version: apiVersion,
|
||||
Message: infoMessage,
|
||||
Status: serviceStatus,
|
||||
MaxSyncSize: maxSyncSize}
|
||||
MaxSyncSize: config.maxSyncSize}
|
||||
sendJSONOk(w, serviceInfo)
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +120,7 @@ func createSync(w http.ResponseWriter, req *http.Request) {
|
|||
sendJSONError(w, err)
|
||||
return
|
||||
}
|
||||
if maxSyncs > 0 && store.Count() >= maxSyncs {
|
||||
if config.maxSyncs > 0 && store.Count() >= config.maxSyncs {
|
||||
serviceStatus = statusReadOnly
|
||||
}
|
||||
sendJSONOk(w, resp)
|
||||
|
@ -154,13 +158,13 @@ func updateSync(syncId string, w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
body := new(bsync.UpdateReq)
|
||||
req.Body = http.MaxBytesReader(w, req.Body, int64(10000+maxSyncSize))
|
||||
req.Body = http.MaxBytesReader(w, req.Body, int64(10000+config.maxSyncSize))
|
||||
err := json.NewDecoder(req.Body).Decode(&body)
|
||||
if err != nil {
|
||||
sendJSONError(w, invalidRequestError)
|
||||
return
|
||||
}
|
||||
if len(body.Bookmarks) > maxSyncSize {
|
||||
if len(body.Bookmarks) > config.maxSyncSize {
|
||||
sendJSONError(w, bsync.SyncDataLimitExceededError)
|
||||
return
|
||||
}
|
||||
|
@ -234,18 +238,17 @@ func notFound(w http.ResponseWriter, _ *http.Request) {
|
|||
|
||||
func init() {
|
||||
var (
|
||||
err error
|
||||
storeFlag string
|
||||
storeDrv bsync.StoreDriver
|
||||
err error
|
||||
storeDrv bsync.StoreDriver
|
||||
)
|
||||
|
||||
flag.StringVar(&listen, "listen", ":8090", "listen address and port")
|
||||
flag.StringVar(&storeFlag, "store", "fs:data", "blob store driver")
|
||||
flag.IntVar(&maxSyncSize, "maxsize", defaultMaxSyncSize, "maximum size of a sync in bytes")
|
||||
flag.IntVar(&maxSyncs, "maxsyncs", defaultMaxSyncs, "maximum number of syncs")
|
||||
flag.StringVar(&config.listen, "listen", ":8090", "listen address and port")
|
||||
flag.StringVar(&config.store, "store", "fs:data", "blob store driver")
|
||||
flag.IntVar(&config.maxSyncSize, "maxsize", defaultMaxSyncSize, "maximum size of a sync in bytes")
|
||||
flag.IntVar(&config.maxSyncs, "maxsyncs", defaultMaxSyncs, "maximum number of syncs")
|
||||
flag.Parse()
|
||||
|
||||
storeFlagTokens := strings.Split(storeFlag, ":")
|
||||
storeFlagTokens := strings.Split(config.store, ":")
|
||||
|
||||
switch storeFlagTokens[0] {
|
||||
case "fs":
|
||||
|
@ -273,9 +276,9 @@ func main() {
|
|||
mux.HandleFunc("/bookmarks", bookmarks)
|
||||
mux.HandleFunc("/bookmarks/", bookmarks)
|
||||
|
||||
log.Println("HTTP server listening on", listen)
|
||||
log.Println("HTTP server listening on", config.listen)
|
||||
server := &http.Server{
|
||||
Addr: listen,
|
||||
Addr: config.listen,
|
||||
Handler: mux,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
WriteTimeout: 15 * time.Second,
|
||||
|
|
Loading…
Reference in New Issue