首页 > 其他分享 >go http请求

go http请求

时间:2024-06-12 16:32:54浏览次数:17  
标签:return 请求 err nil resp go http wechatRobotURL

func Send(notification model.Notification, defaultRobot string) (err error) {

markdown, robotURL, err := transformer.TransformToMarkdown(notification)

if err != nil {
return
}

data, err := json.Marshal(markdown)
if err != nil {
return
}

var wechatRobotURL string

if robotURL != "" {
wechatRobotURL = robotURL
} else {
wechatRobotURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + defaultRobot
}

req, err := http.NewRequest(
"POST",
wechatRobotURL,
bytes.NewBuffer(data))

if err != nil {
return
}

req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)

if err != nil {
return
}

defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)

return
}

标签:return,请求,err,nil,resp,go,http,wechatRobotURL
From: https://www.cnblogs.com/cheyunhua/p/18244228

相关文章

  • Go版RuoYi
     RuoYi-Go  https://github.com/Kun-GitHub/RuoYi-Go1.关于我个人介绍2.介绍后端用Go写的RuoYi权限管理系统(功能正在持续实现)后端 Gitee地址3.前端RuoYi-Vue3官方前端Vue3版4.Go后端技术栈(持续在对齐项目,在补充)功能框架是否采用备注配置......
  • The dragon Boat Festival
    TheDragonBoatFestival,alsoknownastheDuanwuFestival,isatraditionalChineseholidaycelebratedonthefifthdayofthefifthmonthofthelunarcalendar.ItfallsonJune3rdthisyear.Thisfestivalhasahistoryspanningover2000yearsandis......
  • node使用http-proxy-middleware做代理,解决跨域问题
    constexpress=require('express')consthistory=require('connect-history-api-fallback')const{createProxyMiddleware}=require('http-proxy-middleware')letapp=express()app.use(history())////匹配api开头的请求,实际转发的请求保a......
  • Dragon Boat Festival
    essenceofthisfestivalAsweallknow,DragonBoatFestivalisatraditionalchinesefestivaltoshowourrespecttoQuYuan.Dragonboatracing,eatingzongzi,prayingforblessings,andwardingoffevilthingsarethecustomthemesoftheDragonBoat......
  • Dragon Boat Festival
    AstheDragonBoatFestivalapproaches,ourcommunityburstswithexcitementandanticipationforthisholiday.Inmyeyes,thisfestivalisrootedinourChinesehistoryandcultureandisfamouswithawell-knownpeoplecalledQuyuan.Inourcommunity,......
  • 基础设施建设——全局异常请求处理
    基础设施建设——全局异常请求处理1.引言在大型微服务架构中,伴随着错综复杂的调用链,统一的、全局的异常请求兜底处理就显得非常重要,如果没有全局统一的请求/响应规范,上下游之间的接口调用、协同配合将会变得异常困难,但是单纯的在业务逻辑中声明可能抛出的异常或者可能返回的错误......
  • Zgo - Writing to a file
     packagemainimport("bufio""fmt""io""os")funcmain(){buffer:=[]byte("Datatowrite\n")f1,err:=os.Create("f1.txt")iferr!=nil{fmt.Pri......
  • On the Parameterization and Initialization of Diagonal State Space Models
    目录概符号说明S4D代码GuA.,GuptaA.,GoelK.andReC.Ontheparameterizationandinitializationofdiagonalstatespacemodels.NeurIPS,2022.概Mamba系列第四作:S4D.符号说明\(u(t)\in\mathbb{R}\),输入信号;\(x(t)\in\mathbb{R}^N\),中间状态;\(......
  • Dragon Boat Festival
    BeforetheDragonBoatFestival,mygrandmamadedozensofzongzimadeupofreedleaves,polishedglutinousriceandmeat.Mygrandmamakesdeliciouszongzieveryyear.Idon’tknowhowtomakeit.TheDragonBoatFestivalcamesilently.Onthemorning,......
  • jmeter控制读取CSV文件数据发送请求完毕后停止压测
    在JMeter中,如果你想让线程组循环读取文件中的数据并发送请求,直到文件中的数据用尽后自动停止线程组,可以采用CSVDataSetConfig元件配合合适的线程组设置来实现。以下是如何配置的具体步骤:步骤1:添加CSVDataSetConfig1.右键点击你的线程组,选择“添加”(Add)>“配置元件”......