
golang
anyincc125
这个作者很懒,什么都没留下…
展开
-
http探针实现
背景 项目在做三方推送时需要先判断三方服务是否存活,以避免不必要的错误推送 原理 利用HTTP的OPTIONS:这个方法极少使用。它用于获取当前URL所支持的方法。若请求成功,则它会在HTTP头中包含一个名为“Allow”的头,值是所支持的方法,如“GET, POST”。这样就能够检测出服务是否支持默写方法继而检测存活 示例代码 package httputils import ( "bytes" "errors" "io/ioutil" "net/http" "os" ) //ht原创 2020-12-16 10:36:01 · 1380 阅读 · 3 评论 -
http client 短链接复用(变为长连接)
背景: go在做服务之间调用时http client会消费系统的tcp资源(大量并发会耗费掉系统资源,资源有限),故此需要复用 1.复用 func HttpPostJson(client *http.Client, url string, jsonstr string) (bool, error) { var request *http.Reque...原创 2018-09-28 13:11:41 · 3963 阅读 · 0 评论 -
golang 转换时指定多个别名
type Result_ struct { ErrCode int32 thrift:"errCode,1" db:"errCode" json:"errCode" ErrMsg string thrift:"errMsg,2" db:"errMsg" json:"errMsg" }原创 2018-12-11 16:57:42 · 2343 阅读 · 0 评论