Cosmetic fixes

This commit is contained in:
Maurizio Porrato 2021-05-17 16:31:34 +01:00
parent 561c1bf81d
commit 08c98588f6
Signed by: guru
GPG Key ID: C622977DF024AC24
5 changed files with 52 additions and 48 deletions

View File

@ -40,7 +40,7 @@ It will start the API server listening on port 8090 and using the `data` directo
There are a few command line flags that can be used to change the behaviour of the API service:
- `-listen $address:$port`: changes the listening address of the built in HTTP server, for example `-listen :9999` will
- `-listen $address:$port`: changes the listening address of the built-in HTTP server, for example `-listen :9999` will
listen on port 9999 on all addresses, while `-listen 127.0.0.1:9876` will only listen on port 9876 on the loopback
interface
- `-store $driver_name:$driver_args`: changes the datastore driver and its configuration. `$driver_name` is the name of

View File

@ -13,9 +13,24 @@ import (
"gitlab.com/mporrato/uBrowserSync/syncstore"
)
const apiVersion = "1.1.13"
const infoMessage = "Powered by uBrowserSync"
const defaultMaxSyncSize = 512000
const (
apiVersion = "1.1.13"
infoMessage = "Powered by uBrowserSync"
defaultMaxSyncSize = 512000
)
var (
store syncstore.Store
maxSyncSize = defaultMaxSyncSize
listen string
serviceStatus = 1
sidRe = regexp.MustCompile("^[[:xdigit:]]{32}$")
invalidRequestError = syncstore.NewSyncError(
"Invalid request",
"Malformed request body",
http.StatusBadRequest)
)
type serviceInfoResp struct {
Version string `json:"version"`
@ -45,13 +60,6 @@ type GetSyncVerResp struct {
Version string `json:"version"`
}
var store syncstore.Store
var maxSyncSize = defaultMaxSyncSize
var serviceStatus = 1
var listen string
var sidRe = regexp.MustCompile("^[[:xdigit:]]{32}$")
func sendJSON(w http.ResponseWriter, status int, data interface{}) {
body, err := json.Marshal(data)
if err != nil {
@ -96,11 +104,6 @@ func info(w http.ResponseWriter, req *http.Request) {
}
}
var invalidRequestError = syncstore.NewSyncError(
"Invalid request",
"Malformed request body",
http.StatusBadRequest)
func createSync(w http.ResponseWriter, req *http.Request) {
body := new(CreateReq)
err := json.NewDecoder(req.Body).Decode(&body)
@ -214,14 +217,15 @@ func bookmarks(w http.ResponseWriter, req *http.Request) {
return
}
}
//sendJSON(w, http.StatusOK, map[string][]string{"elements": elements})
sendJSONError(w, syncstore.NotImplementedError)
}
func init() {
var err error
var storeFlag string
var storeDrv syncstore.StoreDriver
var (
err error
storeFlag string
storeDrv syncstore.StoreDriver
)
flag.StringVar(&listen, "listen", ":8090", "listen address and port")
flag.StringVar(&storeFlag, "store", "fs:data", "blob store driver")

View File

@ -37,27 +37,29 @@ func NewSyncError(code string, message string, status int) SyncError {
Message: message}}
}
var NotImplementedError = NewSyncError(
"NotImplementedException",
"The requested route has not been implemented",
http.StatusNotFound)
var (
NotImplementedError = NewSyncError(
"NotImplementedException",
"The requested route has not been implemented",
http.StatusNotFound)
var MethodNotImplementedError = NewSyncError(
"NotImplementedException",
"The requested method has not been implemented",
http.StatusMethodNotAllowed)
MethodNotImplementedError = NewSyncError(
"NotImplementedException",
"The requested method has not been implemented",
http.StatusMethodNotAllowed)
var SyncNotFoundError = NewSyncError(
"SyncNotFoundException",
"Sync does not exist",
http.StatusUnauthorized)
SyncNotFoundError = NewSyncError(
"SyncNotFoundException",
"Sync does not exist",
http.StatusUnauthorized)
var SyncConflictError = NewSyncError(
"SyncConflictException",
"A sync conflict was detected",
http.StatusConflict)
SyncConflictError = NewSyncError(
"SyncConflictException",
"A sync conflict was detected",
http.StatusConflict)
var SyncDataLimitExceededError = NewSyncError(
"SyncDataLimitExceededException",
"Sync data limit exceeded",
http.StatusRequestEntityTooLarge)
SyncDataLimitExceededError = NewSyncError(
"SyncDataLimitExceededException",
"Sync data limit exceeded",
http.StatusRequestEntityTooLarge)
)

View File

@ -35,17 +35,17 @@ func (drv *FSStore) RawSave(s *Blob) error {
if err != nil {
return err
}
filename := drv.storePath(s.ID)
dirname := filepath.Dir(filename)
err = os.Mkdir(dirname, 0700)
fileName := drv.storePath(s.ID)
dirName := filepath.Dir(fileName)
err = os.Mkdir(dirName, 0700)
if err != nil && !os.IsExist(err) {
return err
}
f, err := os.CreateTemp(dirname, "tmp-"+s.ID+".*")
f, err := os.CreateTemp(dirName, "tmp-"+s.ID+".*")
if err != nil {
return err
}
tempname := f.Name()
tempName := f.Name()
_, err = f.Write(body)
err2 := f.Close()
if err != nil {
@ -55,7 +55,7 @@ func (drv *FSStore) RawSave(s *Blob) error {
if err2 != nil {
return err2
}
return os.Rename(tempname, filename)
return os.Rename(tempName, fileName)
}
func (drv *FSStore) RawLoad(id string) (*Blob, error) {

View File

@ -90,8 +90,6 @@ func TestStore_FS(t *testing.T) {
testStoreHelper(t, drv)
}
const concurrencyWorkers = 5
func testStoreConcurrencyWorker(wg *sync.WaitGroup, t *testing.T, store *Store, sid string, rounds int) {
defer wg.Done()
for i := 0; i < rounds; i++ {