Add xml response
This commit is contained in:
parent
d9ccc888ec
commit
84e7f7e95c
16
main.go
16
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"io"
|
"io"
|
||||||
|
@ -101,9 +102,6 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
values := save(buf)
|
values := save(buf)
|
||||||
|
|
||||||
switch output {
|
|
||||||
case "json":
|
|
||||||
b := &Response{
|
b := &Response{
|
||||||
ID: values[0],
|
ID: values[0],
|
||||||
HASH: values[1],
|
HASH: values[1],
|
||||||
|
@ -112,6 +110,9 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
DELKEY: values[4],
|
DELKEY: values[4],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch output {
|
||||||
|
case "json":
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
err := json.NewEncoder(w).Encode(b)
|
err := json.NewEncoder(w).Encode(b)
|
||||||
|
|
||||||
|
@ -119,6 +120,15 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case "xml":
|
||||||
|
x, err := xml.MarshalIndent(b, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/xml")
|
||||||
|
w.Write(x)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
io.WriteString(w, values[2]+"\n")
|
io.WriteString(w, values[2]+"\n")
|
||||||
|
|
Loading…
Reference in New Issue