当前位置:网站首页>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)
}
边栏推荐
- Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
- 小白的0基础教程SQL: 关系数据库概述 02
- Dart exception details
- 基于MATLAB的BP神经网络进行语音特征信号分类
- Jupyter shortcuts
- 特别数的和
- 我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
- 【FiddlerScript】利用FiddlerScript抓包保利威下载
- sum of special numbers
- 基于百度OCR的网站验证码在线识别
猜你喜欢
零代码网站开发利器:WordPress
curl (7) Failed connect to localhost8080; Connection refused
rhcsa 第四天
NIO编程
datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
LeetCode 0149. 直线上最多的点数
sum of special numbers
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
随机推荐
对于升级go1.18的goland问题
mysql的行锁和间隙锁
LeetCode 0149. 直线上最多的点数
解决浏览器滚动条导致的页面闪烁问题
uva12326
leetcode125 Verify palindrome string
「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面
曲柄滑块机构运动分析和参数优化
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
LeetCode 0150. Reverse Polish Expression Evaluation
Compare two objects are the same depth
小白的0基础教程SQL: 安装MYSQL 03
Detailed explanation of the crawler framework Scrapy
More than 2022 cattle guest school game 4 yue
05-SDRAM:仲裁
从离线到实时对客,湖仓一体释放全量数据价值
Offer刷题——1
MATLAB程序设计与应用 2.5 MATLAB运算
Go 支持 OOP: 用 struct 代替 class
matlab simulink 粒子群优化模糊pid控制的电机泵