Mercurial > gemma
view pkg/controllers/geostyling.go @ 873:ad9272460ef3 geo-style
Do the XSLT to adjust the layer name when updating the style column in the database.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 30 Sep 2018 14:24:37 +0200 |
parents | f0b6852c14d1 |
children | 876d1f5433be |
line wrap: on
line source
package controllers import ( "bytes" "fmt" "io" "log" "net/http" "gemma.intevation.de/gemma/pkg/models" "github.com/gorilla/mux" ) const ( maxStyleSize = 5 * 1024 * 1024 styleName = "style" ) func extractStyle(req *http.Request) (string, error) { f, _, err := req.FormFile(styleName) if err != nil { return "", err } defer f.Close() var buf bytes.Buffer if _, err := io.Copy(&buf, io.LimitReader(f, maxStyleSize)); err != nil { return "", err } return buf.String(), nil } func supportedWMSFeature(name string) bool { return len(models.InternalServices.Filter( models.IntAnd(models.IntWMS, models.IntByName(name)))) > 0 } func uploadStyle(rw http.ResponseWriter, req *http.Request) { feature := mux.Vars(req)["feature"] // only allow internal WMS features if !supportedWMSFeature(feature) { http.Error(rw, fmt.Sprintf("WMS feature %s is not found.", feature), http.StatusNotFound) return } style, err := extractStyle(req) if err != nil { log.Printf("error: %v\n", err) http.Error(rw, "error: "+err.Error(), http.StatusBadRequest) return } log.Printf("uploaded file length: %d\n", len(style)) if err := models.UpdateInternalStyle(req, feature, style); err != nil { log.Printf("error: %v\n", err) http.Error(rw, "error: "+err.Error(), http.StatusInternalServerError) return } // TODO: Configure GeoServer }