Skip to content

Commit

Permalink
Now you can add storages on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsupermanhd committed May 28, 2022
1 parent e29e602 commit c6b36d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
45 changes: 44 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,52 @@ func apiStorageReinit(w http.ResponseWriter, r *http.Request) (int, string) {
if err != nil {
return 500, err.Error()
}
return 200, ""
var ver string
ver, err = storages[i].Driver.GetStatus()
if err != nil {
return 500, err.Error()
}
return 200, ver
}
}
}
return 404, ""
}

func apiStorageAdd(w http.ResponseWriter, r *http.Request) (int, string) {
name := r.FormValue("name")
if name == "" {
return 400, "Empty name"
}
address := r.FormValue("address")
if address == "" {
return 400, "Empty address"
}
t := r.FormValue("type")
if t == "" {
return 400, "Empty type"
}
for i := range storages {
if storages[i].Name == name {
return 400, "Storage with that name already exists"
}
}
driver, err := initStorage(t, address)
if err != nil {
if err == errStorageTypeNotImplemented {
return 400, err.Error()
}
return 500, err.Error()
}
ver, err := driver.GetStatus()
if err != nil {
return 500, err.Error()
}
storages = append(storages, chunkStorage.Storage{
Name: name,
Type: t,
Address: address,
Driver: driver,
})
return 200, ver
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func main() {
router.HandleFunc("/api/submit/region/{world}/{dim}", apiAddRegionHandler)

router.HandleFunc("/api/storages", apiHandle(apiStoragesGET)).Methods("GET")
router.HandleFunc("/api/storages", apiHandle(apiStorageAdd)).Methods("PUT")
router.HandleFunc("/api/storages/{storage}/reinit", apiHandle(apiStorageReinit)).Methods("GET")

router.HandleFunc("/api/worlds", apiHandle(apiAddWorld)).Methods("POST")
Expand Down

0 comments on commit c6b36d0

Please sign in to comment.