-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathxml.go
More file actions
32 lines (26 loc) · 683 Bytes
/
xml.go
File metadata and controls
32 lines (26 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Miminal golang web-server XML response
// Visit: http://127.0.0.1:8080
package main
import (
"net/http"
"encoding/xml"
)
type Response struct {
Name string
Hobbies []string
}
// Default Request Handler
func defaultHandler(w http.ResponseWriter, r *http.Request) {
profile := Response{"ET", []string{"music", "programming"}}
js, err := xml.MarshalIndent(profile, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/xml")
w.Write(js)
}
func main() {
http.HandleFunc("/", defaultHandler)
http.ListenAndServe(":8080", nil)
}