go for simple http web service

main Package 

Import ( 
	"FMT" 
	"NET / HTTP" 
) 

FUNC Hello (http.ResponseWriter W, R & lt http.Request *) { 
	fmt.Println ( "Hello handle") 
	fmt.Fprintf (W, "hello12345") 
} 

FUNC index (http.ResponseWriter W, R & lt http.Request *) { 
	// Fprintf generate formatted according to the format parameter string and writes w. Returns the number of bytes written and any errors encountered 
	fmt.Fprintf (W, "the this index IS") 
} 

FUNC main () { 
	// HandleFunc register and a function handler processor mode corresponding pattern 
	// implementing routing functionality , hello to the function name 
	http.HandleFunc ( "/", hello) 
	http.HandleFunc ( "/ index", index) 
	// ListenAndServe listening srv.Addr specified TCP address and received calls Serve method of connection. If srv.Addr an empty string, use ": http". 
	err: = http.

	if err != nil {
		fmt.Println("http listen failed")
	}

}

  

Guess you like

Origin www.cnblogs.com/zhangxiaoj/p/11291374.html