示例#1
0
func Md5Handler() http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		content, _ := ioutil.ReadAll(r.Body)

		switch r.Method {
		case exercise.POST:
			{
				hash := md5.Md5sum(content)
				w.Write([]byte(hash))
			}
		}
	})
}
示例#2
0
func TestPost(t *testing.T) {
	service := NewMd5Service(":9091")
	go service.ListenAndServe()

	//Make put request
	c := &http.Client{}
	rq, _ := http.NewRequest("POST", "http://localhost:9091/md5/", strings.NewReader("test:chicago"))
	r, _ := c.Do(rq)
	body, _ := ioutil.ReadAll(r.Body)
	//Verify
	if string(body) != md5.Md5sum([]byte("test:chicago")) {
		t.Error("Add Not Successful", string(body))
	}
	service.Stop()

}
示例#3
0
func print(content []byte, err error) {
	if err != nil {
		fmt.Errorf("ERROR:", err)
	}
	fmt.Println("Hash:", md5.Md5sum(content))
}