mapserver/web/colormapping.go

30 lines
511 B
Go
Raw Normal View History

2019-05-05 18:07:49 +03:00
package web
import (
"encoding/json"
"mapserver/app"
"net/http"
)
type ColorMappingHandler struct {
ctx *app.App
}
type Color struct {
R uint8 `json:"r"`
G uint8 `json:"g"`
B uint8 `json:"b"`
}
func (h *ColorMappingHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
cm := make(map[string]Color)
for k, v := range h.ctx.Colormapping.GetColors() {
cm[k] = Color{R: v.R, G: v.G, B: v.B}
}
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode(cm)
}