12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package api
- import (
- "net/http"
- "time"
- "github.com/go-chi/chi"
- "github.com/go-chi/render"
- "github.com/google/martian/log"
- "github.com/willie68/schematic-service-go/config"
- "github.com/willie68/schematic-service-go/dao"
- )
- // TenantHeader in this header thr right tenant should be inserted
- const TenantHeader = "X-es-tenant"
- const timeout = 1 * time.Minute
- //APIKey the apikey of this service
- var APIKey string
- //SystemID the systemid of this service
- var SystemID string
- /*
- ConfigDescription describres all metadata of a config
- */
- type ConfigDescription struct {
- StoreID string `json:"storeid"`
- TenantID string `json:"tenantID"`
- Size int `json:"size"`
- }
- /*
- ConfigRoutes getting all routes for the config endpoint
- */
- func ConfigRoutes() *chi.Mux {
- router := chi.NewRouter()
- router.Get("/", GetConfigEndpoint)
- router.Delete("/dropall", DropAllEndpoint)
- router.Post("/backup", PostBackupEndpoint)
- return router
- }
- /*
- GetConfigEndpoint getting if a store for a tenant is initialised
- because of the automatic store creation, the value is more likely that data is stored for this tenant
- */
- func GetConfigEndpoint(response http.ResponseWriter, req *http.Request) {
- Msg(response, http.StatusNotImplemented, "not im plemented yet")
- }
- /*
- PostConfigEndpoint create a new store for a tenant
- because of the automatic store creation, this method will always return 201
- */
- func PostBackupEndpoint(response http.ResponseWriter, req *http.Request) {
- go func() {
- err := dao.GetStorage().Backup(config.Get().Backup.Path)
- if err != nil {
- log.Infof("error in backup: %v", err)
- }
- }()
- render.JSON(response, req, "backup started.")
- }
- //DropAllEndpoint dropping all data
- func DropAllEndpoint(response http.ResponseWriter, req *http.Request) {
- dao.GetStorage().DropAll()
- render.JSON(response, req, "")
- }
|