-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.go
More file actions
75 lines (59 loc) · 1.43 KB
/
Copy pathMain.go
File metadata and controls
75 lines (59 loc) · 1.43 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/gorilla/mux"
"log"
"net/http"
)
type Bookstore struct {
XMLName xml.Name `xml:"bookstore"`
Text string `xml:",chardata"`
Book []struct {
Text string `xml:",chardata"`
Category string `xml:"category,attr"`
Title struct {
Text string `xml:",chardata"`
Lang string `xml:"lang,attr"`
} `xml:"title"`
Author string `xml:"author"`
Year string `xml:"year"`
Price string `xml:"price"`
} `xml:"book"`
}
func main(){
router := mux.NewRouter()
router.HandleFunc("/doSomething", DoSomething).Methods("GET")
fmt.Printf("running server")
log.Fatal(http.ListenAndServe(":8080", router))
//bookstore := Bookstore{};
//
//byteXml, err := xml.Marshal(bookstore)
//if err != nil{
// fmt.Errorf(err.Error())
//}
//
//client := &http.Client{}
//
//url := "http://localhost:8080/doSomething"
//
//req, err := http.NewRequest("POST", url, bytes.NewBuffer(byteXml))
//if err != nil {
// fmt.Println(err)
//}
//req.Header.Add("Content-Type", "application/xml; charset=utf-8")
//// now POST it
//resp, err := client.Do(req)
//if err != nil {
// fmt.Println(err)
//}
//fmt.Println(resp)
}
func DoSomething(w http.ResponseWriter, r *http.Request){
params := mux.Vars(r)
for _, item := range params {
fmt.Printf("these is the request sent throught the post request: " + item)
}
json.NewEncoder(w).Encode("This is the response")
}