refactor(global): replace /config endpoint with /settings to avoid confusion

pull/98/head
Anthony Lapenna 2016-08-03 21:12:46 +12:00
parent 1aaa5acbef
commit 19d4e38d94
7 changed files with 26 additions and 34 deletions

View File

@ -29,8 +29,8 @@ type (
} }
) )
func (a *api) run(configuration *Config) { func (a *api) run(settings *Settings) {
handler := a.newHandler(configuration) handler := a.newHandler(settings)
if err := http.ListenAndServe(a.bindAddress, handler); err != nil { if err := http.ListenAndServe(a.bindAddress, handler); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -1,25 +0,0 @@
package main
import (
"encoding/json"
"net/http"
)
// Config defines the configuration available under the /config endpoint
type Config struct {
Swarm bool `json:"swarm"`
HiddenLabels pairList `json:"hiddenLabels"`
}
// newConfig creates a new Config from command flags
func newConfig(swarm bool, labels pairList) Config {
return Config{
Swarm: swarm,
HiddenLabels: labels,
}
}
// configurationHandler defines a handler function used to encode the configuration in JSON
func configurationHandler(w http.ResponseWriter, r *http.Request, c *Config) {
json.NewEncoder(w).Encode(*c)
}

View File

@ -10,7 +10,7 @@ import (
) )
// newHandler creates a new http.Handler with CSRF protection // newHandler creates a new http.Handler with CSRF protection
func (a *api) newHandler(c *Config) http.Handler { func (a *api) newHandler(settings *Settings) http.Handler {
var ( var (
mux = http.NewServeMux() mux = http.NewServeMux()
fileHandler = http.FileServer(http.Dir(a.assetPath)) fileHandler = http.FileServer(http.Dir(a.assetPath))
@ -22,8 +22,8 @@ func (a *api) newHandler(c *Config) http.Handler {
mux.Handle("/", fileHandler) mux.Handle("/", fileHandler)
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler)) mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler))
mux.Handle("/ws/exec", websocket.Handler(a.execContainer)) mux.Handle("/ws/exec", websocket.Handler(a.execContainer))
mux.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/settings", func(w http.ResponseWriter, r *http.Request) {
configurationHandler(w, r, c) settingsHandler(w, r, settings)
}) })
return CSRFHandler(newCSRFWrapper(mux)) return CSRFHandler(newCSRFWrapper(mux))
} }

View File

@ -33,11 +33,11 @@ func main() {
TLSKeyPath: *tlskey, TLSKeyPath: *tlskey,
} }
configuration := &Config{ settings := &Settings{
Swarm: *swarm, Swarm: *swarm,
HiddenLabels: *labels, HiddenLabels: *labels,
} }
api := newAPI(apiConfig) api := newAPI(apiConfig)
api.run(configuration) api.run(settings)
} }

17
api/settings.go Normal file
View File

@ -0,0 +1,17 @@
package main
import (
"encoding/json"
"net/http"
)
// Settings defines the settings available under the /settings endpoint
type Settings struct {
Swarm bool `json:"swarm"`
HiddenLabels pairList `json:"hiddenLabels"`
}
// configurationHandler defines a handler function used to encode the configuration in JSON
func settingsHandler(w http.ResponseWriter, r *http.Request, s *Settings) {
json.NewEncoder(w).Encode(*s)
}

View File

@ -155,5 +155,5 @@ angular.module('uifordocker', [
// You need to set this to the api endpoint without the port i.e. http://192.168.1.9 // You need to set this to the api endpoint without the port i.e. http://192.168.1.9
.constant('DOCKER_ENDPOINT', 'dockerapi') .constant('DOCKER_ENDPOINT', 'dockerapi')
.constant('DOCKER_PORT', '') // Docker port, leave as an empty string if no port is requred. If you have a port, prefix it with a ':' i.e. :4243 .constant('DOCKER_PORT', '') // Docker port, leave as an empty string if no port is requred. If you have a port, prefix it with a ':' i.e. :4243
.constant('CONFIG_ENDPOINT', 'config') .constant('CONFIG_ENDPOINT', 'settings')
.constant('UI_VERSION', 'v1.5.0'); .constant('UI_VERSION', 'v1.5.0');

View File

@ -160,7 +160,7 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
remove: {method: 'DELETE'} remove: {method: 'DELETE'}
}); });
}]) }])
.factory('Config', ['$resource', 'CONFIG_ENDPOINT', function($resource, CONFIG_ENDPOINT) { .factory('Config', ['$resource', 'CONFIG_ENDPOINT', function ConfigFactory($resource, CONFIG_ENDPOINT) {
return $resource(CONFIG_ENDPOINT).get(); return $resource(CONFIG_ENDPOINT).get();
}]) }])
.factory('Settings', ['DOCKER_ENDPOINT', 'DOCKER_PORT', 'UI_VERSION', function SettingsFactory(DOCKER_ENDPOINT, DOCKER_PORT, UI_VERSION) { .factory('Settings', ['DOCKER_ENDPOINT', 'DOCKER_PORT', 'UI_VERSION', function SettingsFactory(DOCKER_ENDPOINT, DOCKER_PORT, UI_VERSION) {