您的位置:首页 > 理论基础 > 计算机网络

使用go语言net/http开发一个简单的get/post 接口

2017-08-24 20:51 543 查看

使用go语言开发一个简单的get/post 接口

直接上代码

package main

import (
"fmt"
"net/http"
)

func main() {
//第一个参数是接口名,第二个参数 http handle func
http.HandleFunc("/", helloWorld)
//服务器要监听的主机地址和端口号
http.ListenAndServe("127.0.0.1:8081", nil)
}

// http handle func
func helloWorld(rw http.ResponseWriter, req *http.Request) {
// 返回字符串 "Hello world"
fmt.Fprint(rw, "Hello world")
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: