Created
July 14, 2016 13:10
-
-
Save monkeybutter/99455fcd13a6f823f01ee3fcd8aa7954 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/xml" | |
| "fmt" | |
| "net/http" | |
| ) | |
| var input string = `<?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE WMT_MS_Capabilities SYSTEM "http://giswebservices.massgis.state.ma.us/geoserver/schemas/wms/1.1.1/WMS_MS_Capabilities.dtd"> | |
| <WMT_MS_Capabilities version="1.1.1" updateSequence="7007"> | |
| <Service> | |
| <Name>OGC:WMS</Name> | |
| <Title>Massachusetts Data from MassGIS (GeoServer)</Title> | |
| <Abstract>Statewide Massachusetts data served by MassGIS via GeoServer.</Abstract> | |
| <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://giswebservices.massgis.state.ma.us/geoserver/wms"/> | |
| </Service> | |
| </WMT_MS_Capabilities>` | |
| type WMT_MS_Capabilities struct { | |
| Service Service | |
| Version string `xml:"version,attr"` | |
| UpdateSeq string `xml:"updateSequence,attr"` | |
| } | |
| type Service struct { | |
| Name string | |
| Title string | |
| Abstract string | |
| OnlineResource Resource | |
| } | |
| type Resource struct { | |
| NSXLink string `xml:"xlink,attr"` | |
| XLink string `xml:"type,attr"` | |
| HRef string `xml:"href,attr"` | |
| } | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| w.Header().Set("Content-Disposition", "attachment; filename=getcapabilities.xml") | |
| enc := xml.NewEncoder(w) | |
| enc.Indent("", " ") | |
| b := WMT_MS_Capabilities{} | |
| xml.Unmarshal([]byte(input), &b) | |
| if err := enc.Encode(b); err != nil { | |
| fmt.Printf("error: %v\n", err) | |
| } | |
| } | |
| func main() { | |
| http.HandleFunc("/", handler) | |
| http.ListenAndServe(":8080", nil) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment