Go http.server实战

栏目: Go · 发布时间: 7年前

package main

import (
	"fmt"
	"net/http"
)

func main()  {
	//监听协议
	http.HandleFunc("/",HelloWorldHandler)
	http.HandleFunc("/user/login",UserLoginHandler)
	//监听服务
	err := http.ListenAndServe("0.0.0.0:8880",nil)

	if err != nil {
		fmt.Println("服务器错误")
	}

}

func HelloWorldHandler(w http.ResponseWriter,r *http.Request)  {
	fmt.Println("r.Method = ", r.Method)
	fmt.Println("r.URL = ", r.URL)
	fmt.Println("r.Header = ", r.Header)
	fmt.Println("r.Body = ", r.Body)
	fmt.Fprintf(w,"HelloWorld!")
}

func UserLoginHandler(response http.ResponseWriter,request *http.Request)  {
	fmt.Println("Handler Hello")
	fmt.Fprintf(response,"Login Success")
}

以上所述就是小编给大家介绍的《Go http.server实战》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Head First HTML5 Programming

Head First HTML5 Programming

Eric Freeman、Elisabeth Robson / O'Reilly Media / 2011-10-18 / USD 49.99

What can HTML5 do for you? If you're a web developer looking to use this new version of HTML, you might be wondering how much has really changed. Head First HTML5 Programming introduces the key featur......一起来看看 《Head First HTML5 Programming》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具