Config UI: dynamic default values, remove static HA instance default (#25525)
This commit is contained in:
parent
4fbd4c01a0
commit
65fce6e6b4
13 changed files with 200 additions and 9 deletions
39
util/demo/service.go
Normal file
39
util/demo/service.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package demo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/evcc-io/evcc/server/service"
|
||||
)
|
||||
|
||||
func init() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /single", getSingle)
|
||||
mux.HandleFunc("GET /country", getCountry)
|
||||
mux.HandleFunc("GET /{country}/city", getCity)
|
||||
|
||||
service.Register("demo", mux)
|
||||
}
|
||||
|
||||
func getSingle(w http.ResponseWriter, req *http.Request) {
|
||||
json.NewEncoder(w).Encode([]string{"demo-value"})
|
||||
}
|
||||
|
||||
func getCountry(w http.ResponseWriter, req *http.Request) {
|
||||
json.NewEncoder(w).Encode([]string{"germany", "france", "spain"})
|
||||
}
|
||||
|
||||
func getCity(w http.ResponseWriter, req *http.Request) {
|
||||
country := req.PathValue("country")
|
||||
var cities []string
|
||||
switch country {
|
||||
case "germany":
|
||||
cities = []string{"berlin", "munich", "hamburg"}
|
||||
case "france":
|
||||
cities = []string{"paris", "lyon", "marseille"}
|
||||
case "spain":
|
||||
cities = []string{"madrid", "barcelona", "valencia"}
|
||||
}
|
||||
json.NewEncoder(w).Encode(cities)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue