当前位置:网站首页>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)
}
边栏推荐
猜你喜欢

从零开始—仿牛客网讨论社区项目(一)

The BP neural network based on MATLAB voice characteristic signal classification

安装SQL Server详细教程

Dart exception details

牛客刷SQL---2

curl (7) Failed connect to localhost8080; Connection refused

奇葩问题 npm install 报错 gyp ERR

rhcsa 第四天

爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】

matlab simulink 粒子群优化模糊pid控制的电机泵
随机推荐
Jupyter shortcuts
mysql中添加字段的相关问题
Dell PowerEdge Server R450 RAID Configuration Steps
从零开始—仿牛客网讨论社区项目(一)
目标检测概述-上篇
Offer brush questions - 1
小白的0基础教程SQL: 关系数据库概述 02
问下 mysql向pg同步多个表的话 有什么好的方案吗?
Guest brush SQL - 2
数据机构----线性表之单向链表
matlab wind speed model wavelet filtering
LeetCode 0149. Maximum number of points on a line
ORACLE modify another user package (package)
深度比较两个对象是否相同
测试工具(四)Jenkins环境搭建与使用
Classwork (7) - #598. remainder operation (mod)
表的创建、修改与删除
LeetCode每日一题(309. Best Time to Buy and Sell Stock with Cooldown)
Talk about the bugs in using for in to traverse the array in js
权重等比分配