Add /api/providers API
This commit is contained in:
parent
93b5410987
commit
0b3928dafb
2 changed files with 28 additions and 24 deletions
8
file.go
8
file.go
|
@ -21,7 +21,6 @@ func (provider *FileProvider) Provide(configurationChan chan<- configMessage) er
|
|||
log.Error("Error creating file watcher", err)
|
||||
return err
|
||||
}
|
||||
defer watcher.Close()
|
||||
|
||||
file, err := os.Open(provider.Filename)
|
||||
if err != nil {
|
||||
|
@ -30,8 +29,10 @@ func (provider *FileProvider) Provide(configurationChan chan<- configMessage) er
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
if provider.Watch {
|
||||
// Process events
|
||||
go func() {
|
||||
defer watcher.Close()
|
||||
for {
|
||||
select {
|
||||
case event := <-watcher.Events:
|
||||
|
@ -47,15 +48,12 @@ func (provider *FileProvider) Provide(configurationChan chan<- configMessage) er
|
|||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if provider.Watch {
|
||||
err = watcher.Add(filepath.Dir(file.Name()))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Error("Error adding file watcher", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
configuration := provider.LoadFileConfig(file.Name())
|
||||
configurationChan <- configMessage{"file", configuration}
|
||||
|
|
6
web.go
6
web.go
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/BurntSushi/ty/fun"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/elazarl/go-bindata-assetfs"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -25,6 +26,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- configMessage) err
|
|||
systemRouter.Methods("GET").Path("/").Handler(http.HandlerFunc(GetHTMLConfigHandler))
|
||||
systemRouter.Methods("GET").Path("/health").Handler(http.HandlerFunc(GetHealthHandler))
|
||||
systemRouter.Methods("GET").Path("/api").Handler(http.HandlerFunc(GetConfigHandler))
|
||||
systemRouter.Methods("GET").Path("/api/providers").Handler(http.HandlerFunc(GetProvidersHandler))
|
||||
systemRouter.Methods("GET").Path("/api/{provider}").Handler(http.HandlerFunc(GetConfigHandler))
|
||||
systemRouter.Methods("PUT").Path("/api/{provider}").Handler(http.HandlerFunc(
|
||||
func(rw http.ResponseWriter, r *http.Request) {
|
||||
|
@ -82,6 +84,10 @@ func GetHealthHandler(rw http.ResponseWriter, r *http.Request) {
|
|||
templatesRenderer.JSON(rw, http.StatusOK, metrics.Data())
|
||||
}
|
||||
|
||||
func GetProvidersHandler(rw http.ResponseWriter, r *http.Request) {
|
||||
templatesRenderer.JSON(rw, http.StatusOK, fun.Keys(currentConfigurations))
|
||||
}
|
||||
|
||||
func GetBackendsHandler(rw http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
providerId := vars["provider"]
|
||||
|
|
Loading…
Reference in a new issue