当前位置:网站首页>Golang:go开启web服务
Golang:go开启web服务
2022-08-01 06:50:00 【ZzzWClock】
go开启web服务
一.前言
golang开启web服务需要用到net/http包
需要用到的函数有handle,函数必须要有 http.ResoponseWriter, *http.Reuqest
需要用到的方法有http.HandleFunc,http.ListenAndServer
二.示例
- 在终端执行 go run mian.go
- 输入url地址:localhost:8081

三.代码块
package main
import (
"fmt"
"net/http"
)
// 处理器
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hi cute body")
}
func main() {
// 路由器
http.HandleFunc("/", handle)
// 开启server服务
http.ListenAndServe(":8081", nil)
}
边栏推荐
- 小白的0基础教程SQL: 安装MYSQL 03
- ORACLE modify another user package (package)
- 第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
- Offer brush questions - 1
- MVVM project development (commodity management system 1)
- MySQL row locks and gap locks
- Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
- 小程序通过云函数操作数据库【使用get取数据库】
- Motion analysis and parameter optimization of crank-slider mechanism
- LeetCode 0150. Reverse Polish Expression Evaluation
猜你喜欢

Introduction to the basic principles, implementation and problem solving of crawler

Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)

Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers

Dart exception details

金山打字通 官网 下载

对于升级go1.18的goland问题

Vim扩展内容

Hunan institute of technology in 2022 ACM training sixth week antithesis

Matlab simulink particle swarm optimization fuzzy pid control motor pump

数据机构----线性表之单向链表
随机推荐
小程序通过云函数操作数据库【使用get取数据库】
对于升级go1.18的goland问题
ORACLE 实现另外一个用户修改包(package)
信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作
Dell PowerEdge Server R450 RAID Configuration Steps
Datagrip error "The specified database userpassword combination is rejected..."Solutions
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
Win任务栏图标异常解决
sum of special numbers
LeetCode 0150. Reverse Polish Expression Evaluation
I have three degrees, and I have five faces. I was "confessed" by the interviewer, and I got an offer of 33*15.
Offer刷题——1
return; represents meaning
小白的0基础教程SQL: 安装MYSQL 03
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
first unique character in characters
AspNet.WebApi.Owin custom Token request parameters
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
特别数的和
Leetcode第 304 场周赛