当前位置: 首页 > news >正文

洛龙区网站设计建设国外设计师作品网站

洛龙区网站设计建设,国外设计师作品网站,wordpress user pass,上海营销seo前情提要#xff1a; 需要安装好go的环境和VSCode的go插件。 hello world快速上手 1、创建go.mod 在项目根目录下打开命令行#xff0c;或者直接用VSCode中的终端。输入命令 go mod init github.com/solenovex/web-tutorial 然后就能看到项目结构中多了一个go.mod 2、…前情提要 需要安装好go的环境和VSCode的go插件。 hello world快速上手 1、创建go.mod 在项目根目录下打开命令行或者直接用VSCode中的终端。输入命令 go mod init github.com/solenovex/web-tutorial 然后就能看到项目结构中多了一个go.mod 2、编写main.go package mainimport net/httpfunc main() {//HandleFunc有两个参数第一个参数相当于一个路由地址。写“/”表示监听的根地址//第二个参数是个回调函数。函数内也有两个参数第一个参数w是用来写响应的//第二个参数r会把传入请求的所有信息都包裹在里面。http.HandleFunc(/, func (w http.ResponseWriter, r *http.Request) {w.Write([]byte(hello world))})//监听请求的地址和端口 相当于一个路由器http.ListenAndServe(localhost:8080, nil) }3、go run main.go运行项目 在项目根目录下打开命令行或者直接用VSCode中的终端。输入命令 go run main.go 然后打开浏览器输入相应地址可以看到hello world。 http.Server http.Server 这是一个 struct里面有若干字段。以下是常用字段 Addr 字段表示网络地址 如果为“”那么就是所有网络接口的 80 端口 Handler 字段 如果为 nil那么就是 DefaultServeMux ListenAndServe() 函数。 其封装好的语句为如下 http.ListenAndServe(localhost:8080, nil) 底层源码如下 server : http.Server{Addr: localhost:8080,Handler: nil, } server.ListenAndServe() 所以这两种代码是等效的第一种更简洁第二种灵活性更强。 handler: handler 是一个接口interface handler 里面只定义了一个方法 ServeHTTP() 参数一HTTPResponseWriter 参数二指向 Request 这个 struct 的指针   源码   type Handler interface {ServeHTTP(ResponseWriter, *Request)   } package mainimport net/httptype myHandler struct{}func (m *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {w.Write([]byte(hello world)) }func main() {mh : myHandler{}//以下五行就和http.ListenAndServe(localhost:8080, mh)效果一样是其源码。server : http.Server{Addr: localhost:8080,Handler: mh,}server.ListenAndServe()}http.Handle:  该函数可以实现多个handler注册到DefaultServeMux上的效果从而达到一个路径对应一个请求一个处理逻辑 package mainimport net/httptype helloHandler struct{}func (m *helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {w.Write([]byte(hello world)) }type aboutHandler struct{}func (m *aboutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {w.Write([]byte(about)) }func main() {mh : helloHandler{}ah : aboutHandler{}server : http.Server{Addr: localhost:8080,Handler: nil,}http.Handle(/hello, mh)http.Handle(/about, ah)server.ListenAndServe() }http.HandleFunc func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) package mainimport net/httpfunc welcome(w http.ResponseWriter, r *http.Request) {w.Write([]byte(welcome)) }func main() {server : http.Server{Addr: localhost:8080,Handler: nil,}http.HandleFunc(/home, func(w http.ResponseWriter, r *http.Request) {w.Write([]byte(home))})http.HandleFunc(/welcome, welcome)//相当于http.Handle(/welcome, http.HandlerFunc(welcome))server.ListenAndServe() }ps:Go 有一个函数类型HandlerFunc。可以将某个具有适当签名的函数 f适配成为一个 Handler而这个 Handler 具有方法 f。 两者区别 ​​​​​​​
http://www.hkea.cn/news/14496173/

相关文章:

  • iis网站突然无法访问企业网电话
  • 郑州优化网站公司有哪些游戏优化大师官网
  • 深圳网站建设者怎样购买起名软件自己做网站
  • wordpress网站标题自定义百度登录
  • 营销型手机网站怎么在ps做网站首页
  • wordpress模板更改页面泉州推广优化公司
  • 网站不良正能量直接进入大学网站建设管理办法
  • 自适应网站手机端厦门有家装饰
  • 教育响应式网站建设注册安全工程师考试题库
  • 天津市网站制作 公司郴州网页设计招聘
  • 代做毕设网站推荐wordpress推荐管理
  • 如何提升网站百度权重宁波如何建网站
  • 合肥网站建站网站建设与维护项目六
  • 网站管理有哪些wordpress登录的图片
  • 神华科技 网站建设360免费建站怎么做
  • pc网站案例wordpress做新闻cms
  • 爱站权重做网站和做app的区别
  • 用动易建设网站教程彩页设计教程
  • 网站的费用青龙建站教程自学网
  • 公司想建网站个人网站设计与制作代码
  • 优舟网站建设怎么在网站上建设投票统计
  • php做网站框架湖南住房与城乡建设部网站
  • 商务网站规划与网页制作那个网站教做馒头
  • 手机软件制作网站平台电子信息工程是互联网专业吗
  • 网站开发培训成都做h5的网站的区别
  • 建设企业网站是静态还是动态好注册网站步骤
  • 会展网站的建设情况洛阳app开发公司
  • 星夜智能建站平台申请免费网站注册
  • 大连哪个企业想做网站南通网站制作计划
  • 中国做外贸的网站百度咨询电话人工台