mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(global): replace /config endpoint with /settings to avoid confusion (#98)
This commit is contained in:
parent
1aaa5acbef
commit
7801a91149
7 changed files with 26 additions and 34 deletions
|
@ -29,8 +29,8 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
func (a *api) run(configuration *Config) {
|
||||
handler := a.newHandler(configuration)
|
||||
func (a *api) run(settings *Settings) {
|
||||
handler := a.newHandler(settings)
|
||||
if err := http.ListenAndServe(a.bindAddress, handler); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// 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 (
|
||||
mux = http.NewServeMux()
|
||||
fileHandler = http.FileServer(http.Dir(a.assetPath))
|
||||
|
@ -22,8 +22,8 @@ func (a *api) newHandler(c *Config) http.Handler {
|
|||
mux.Handle("/", fileHandler)
|
||||
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler))
|
||||
mux.Handle("/ws/exec", websocket.Handler(a.execContainer))
|
||||
mux.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
|
||||
configurationHandler(w, r, c)
|
||||
mux.HandleFunc("/settings", func(w http.ResponseWriter, r *http.Request) {
|
||||
settingsHandler(w, r, settings)
|
||||
})
|
||||
return CSRFHandler(newCSRFWrapper(mux))
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ func main() {
|
|||
TLSKeyPath: *tlskey,
|
||||
}
|
||||
|
||||
configuration := &Config{
|
||||
settings := &Settings{
|
||||
Swarm: *swarm,
|
||||
HiddenLabels: *labels,
|
||||
}
|
||||
|
||||
api := newAPI(apiConfig)
|
||||
api.run(configuration)
|
||||
api.run(settings)
|
||||
}
|
||||
|
|
17
api/settings.go
Normal file
17
api/settings.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue