go web服务(2)
来源:互联网 发布:人口密度数据 编辑:程序博客网 时间:2024/06/07 20:34
练习:HTTP 处理
实现下面的类型,并在其上定义 ServeHTTP 方法。在 web 服务器中注册它们来处理指定的路径。
type String stringtype Struct struct { Greeting string Punct string Who string}
例如,可以使用如下方式注册处理方法:
http.Handle("/string", String("I'm a frayed knot."))http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
package mainimport ( "fmt" "log" "net/http")type String stringtype Struct struct { Greeting string Punct string Who string}func (s String) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, s)}func (s Struct) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, s)}func main() { http.Handle("/string", String("I'm a frayed knot.")) http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"}) log.Fatal(http.ListenAndServe("localhost:4000", nil))}
0 0
- go web服务(2)
- go web服务(1)
- Go web 服务简单使用
- go 运维,检测 web 服务状态
- GO实现简单的web服务功能
- Docker之搭建Go Web服务~~
- Go语言:REST Web服务调用
- Go 开发WEB服务之hello world
- Go Web服务开发入门(一) -- 搭建简单web服务器
- Go Web 开发(一)
- Go Web 开发(二)
- GO语言启动web服务的实现方式
- go 原生http web 服务跨域restful api 写法
- 用Go重构WEB请求分析跟踪服务
- Web服务(Web Service)
- Web服务(Web service)
- go web: 2 封装日志包log
- Go web之旅(Request分析)
- Light OJ 1198
- 【Ceph】centos7搭建Ceph集群(jewel)
- C语言学习2
- unity 语音识别
- golang获取当天零点时间
- go web服务(2)
- 机器学习面试问题9
- Sublime Text 3 配置 PHP IDE环境 并使用Xdebug进行调试
- 【poj 3067 cdoj 383】Japan 树状数组
- 实例学习ansible系列(6)常用模块之file
- C#控制台 输出hello world之 虚方法与覆写方法输出
- 房子只是破砖头~~ 家才是终点
- 【CURL】模拟登录网站并获取用户信息
- fork()函数与Linux中的多线程编程