Package Main//Gohttp Bottom-level implementation through gohttp not output through Beego//Import ("io" "Log" "net/http") Func main () {//set up Routeshttp. Handlefunc ("/", SayHello) Err:= http. Listenandserve (": 8080", nil)ifErr! =Nil {log. Fatal (Err)}}func SayHello (w http. Responsewriter, R*http. Request) {io. WriteString (W,"Hello Vwesion1")}
Package Main//Gohttp Second version: Implementing Routing through Mux,handlerImport ("io" "Log" "net/http") Func main () {mux:= http. Newservemux ()//Servemux//implement handler register to Servemux and then route the registrationMux. Handle ("/", &myhandler{})//registering routes and handlerMux. Handle ("/hello", SayHello)//registering routes with functionsERR:= http. Listenandserve (": 8080", MUX)ifErr! =Nil {log. Fatal (Err)}}type MyHandlerstruct{//this handle to implement the Serverhttp method}func ( This*myhandler) servehttp (w http. Responsewriter, R *http. Request) {io. WriteString (W,"Hello Vwesion2,"+R.url. String ())}func SayHello (w http. Responsewriter, R*http. Request) {io. WriteString (W,"Hello Vwesion2,"+R.url. String ())}
BEEGO3---gohttp bottom-level implementation