Mercurial > gemma
view pkg/controllers/geostyling.go @ 870:29c11f4bf9db geo-style
Started with endpoint to upload geo style.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sat, 29 Sep 2018 23:33:14 +0200 |
parents | |
children | f0b6852c14d1 |
line wrap: on
line source
package controllers import ( "bytes" "io" "log" "net/http" ) const ( maxStyleSize = 5 * 1024 * 1024 styleName = "style" ) func extractStyle(req *http.Request) ([]byte, error) { f, _, err := req.FormFile(styleName) if err != nil { return nil, err } defer f.Close() var buf bytes.Buffer if _, err := io.Copy(&buf, io.LimitReader(f, maxStyleSize)); err != nil { return nil, err } return buf.Bytes(), nil } func uploadStyle(rw http.ResponseWriter, req *http.Request) { data, 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(data)) // TODO: Implement me! }