当前位置:网站首页>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)
}
边栏推荐
- Compare two objects are the same depth
- leetcode43 string multiplication
- 我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
- 上课作业(7)——#598. 取余运算(mod)
- Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
- weight distribution
- 【FiddlerScript】利用FiddlerScript抓包保利威下载
- 响应式织梦模板园林景观类网站
- 点餐系统数据库设计--SQL Server
- crypto-js使用
猜你喜欢
滚动条样式修改
Vim扩展内容
Matlab simulink particle swarm optimization fuzzy pid control motor pump
Detailed explanation of the crawler framework Scrapy
金山打字通 官网 下载
信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作
MVVM project development (commodity management system 1)
阿里三面:MQ 消息丢失、重复、积压问题,该如何解决?
sum of special numbers
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
随机推荐
Bean的生命周期
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
【FiddlerScript】利用FiddlerScript抓包保利威下载
weight distribution
爬虫框架 Scrapy 详解
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
Srping中bean的生命周期
vsce package 后出现 Command failed: npm list --production --parseable --depth=99999 --loglevel=error异常
Does flinkcdc have any solution for mysql's date field type conversion?
LeetCode 0149. 直线上最多的点数
first unique character in characters
rhcsa 第三次
Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
MVVM项目开发(商品管理系统一)
Three aspects of Ali: How to solve the problem of MQ message loss, duplication and backlog?
torch
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02
Vim三种模式
小白的0基础教程SQL: 关系数据库概述 02
WebSocket implements chat function