Mercurial > gemma
view pkg/controllers/geostyling.go @ 928:0a0013fbda4a geo-style
octree2contour: Merge multi linestrings in user land before sending them to database.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 08 Oct 2018 13:09:02 +0200 |
parents | 4bf3a3a20ce1 |
children | a244b18cb916 |
line wrap: on
line source
package controllers import ( "bytes" "fmt" "io" "log" "net/http" "github.com/gorilla/mux" "gemma.intevation.de/gemma/pkg/geoserver" "gemma.intevation.de/gemma/pkg/models" ) 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 } geoserver.ReconfigureStyle(feature) // Nothing to return rw.WriteHeader(http.StatusNoContent) }