golang web部分初探
package main import "fmt" import "log" import "net/http" import "time" type HttpHander struct {} var urlMapping map[string] func(http.ResponseWriter,*http.Request) func main() { server := &http.Server{} server.Addr = ":8080" server.Handler = HttpHander{} server.ReadTimeout = 5 *time.Second server.WriteTimeout = 5 *time.Second urlMapping = make(map[string] func(http.ResponseWriter,*http.Request)) urlMapping["/get"] = Get urlMapping["/post"] = Post urlMapping["/delete"] = Delete urlMapping["/put"] = Put urlMapping["/update"] = Update err := server.ListenAndServe() if err != nil { fmt.Println("========") log.Println(err) } } func(HttpHander) ServeHTTP(response http.ResponseWriter, request *http.Request) { v,ok:= urlMapping[request.URL.String()] if ok { v(response,request) } else { log.Println("no url mapping found !") } } func Get(response http.ResponseWriter, request *http.Request) { response.Write([]byte("get ....")) } func Post(response http.ResponseWriter, request *http.Request) { response.Write([]byte("Post ....")) } func Delete(response http.ResponseWriter, request *http.Request) { response.Write([]byte("Delete ....")) } func Put(response http.ResponseWriter, request *http.Request) { response.Write([]byte("Put ....")) } func Update(response http.ResponseWriter, request *http.Request) { response.Write([]byte("Update ....")) }
在浏览器输入:
http://localhost:8080/get
http://localhost:8080/post
http://localhost:8080/delete
http://localhost:8080/update
http://localhost:8080/put
看浏览器显示信息
相关推荐
Golang的web开发入门书籍,写的挺好的,排版佳。可读性强
golang web编程 图书英文版 学习golang还是要会看英文文档的~~
golang的web框架beego https://github.com/astaxie/beego
这是一份中文的文档,对于学习go语言的朋友来说是不错的选择。
golang_Web开发(1).pdf
利用go语言开发web应用的示例。详细说明见我的博客: http://blog.csdn.net/yavobo/article/details/9380011
利用go语言开发web应用的示例。相关说明见我的博客: http://blog.csdn.net/yavobo/article/details/9380011
golang web 编程 基础 golang 基础 ,网络编程。package
使用Golang 搭建http web服务器
macross-master 高效的WEB框架开发(有调整) The Macross Web Framework By Insion If you are using standard http, you may use a similar macross package makross which is adapted from Macross.
go语言web开发技术指南。适合想学习golang并进行网络开发的同学。
go语言学习的相关资源,有pdf格式和kindle专用格式mobi,资料包含:go语言程序设计、学习Go语言(Golang)、Go语言圣经、Go语言实战、golang Web开发
一个最新的golang 编写的web高性能框架,实现快速的处理提交,简单操作方便
优雅的Golang Web框架注意:此存储库包含Goyave框架的核心代码。 如果要构建Goyave应用程序,请访问Goyave模板项目存储库。 Goyave是一个优雅的Golang Web框架注意:此存储库包含Goyave框架的核心代码。 如果要构建...
一个基于web的IDE适合于使用Golang语言的团队
ftp+web用户管理界面 安装博客地址:https://blog.csdn.net/zhanremo3062/article/details/123083547?spm=1001.2014.3001.5502 创作不易,感谢大家以来的支持!
Golang网络服务器演示代码:路由,服务文件和一个简单的请求后响应示例。依存关系go get "github.com/fasthttp/router" 建造在主文件夹中调用go build并获取可执行文件。安装Golang
在golang中如何使用“ Web3”的示例。 更新 查阅我的小书《进行作为更好的指南。 概要 显示如何 编写智能合约 从ABI生成golang包 连接到rpc或websocket提供程序 从地址加载合同 加载私钥 调用合约方法 订阅合同事件 ...
工具使用WebView从您的golang http服务器构建Android应用