Пример #1
0
func main() {
	conn, _ := m2go.Connect(senderId, recvSpec, sendSpec)
	defer conn.Close()

	for true {
		req, _ := conn.Read()
		if req.IsDisconnect() {
			continue
		}

		req.Respond("Hello, World!")
	}
}
Пример #2
0
func main() {
	conn, _ := m2go.Connect(senderId, recvSpec, sendSpec)
	defer conn.Close()

	response := ""
	for true {
		req, _ := conn.Read()
		if req.IsDisconnect() {
			fmt.Println("Disconnect.")
			continue
		}

		done, dOk := req.Headers["x-mongrel2-upload-done"]
		start, sOk := req.Headers["x-mongrel2-upload-start"]

		if dOk {
			if start != done {
				fmt.Println("Got the wrong target file:  ", start, done)
				continue
			}

			body, _ := ioutil.ReadFile(done)
			fmt.Printf("Done:  Body is %d long, content-length is %s\n",
				len(body), req.Headers["content-length"])

			response = "Good!"
		} else if sOk {
			fmt.Println("Upload starting, don't reply yet.")
			fmt.Println("Will read file from", start)
			continue
		} else {
			response = "Hello, there!"
		}

		req.Respond(response + "\r\n")
	}
}