3 Star 1 Fork 0

NightTC / Gobige

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
http.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
buguang 提交于 2023-05-30 11:47 . 去掉没用的代码
package common
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os/user"
"runtime"
)
// 发送POST请求
// url: 请求地址
// data: POST请求提交的数据
// contentType: 请求体格式,如:application/json
// content: 请求放回的内容
func Post(url string, data interface{}, contentType string) (string, error) {
if contentType == "" {
contentType = "application/json"
}
// 超时时间:5秒
client := http.DefaultClient
jsonStr, _ := json.Marshal(data)
resp, err := client.Post(url, contentType, bytes.NewBuffer(jsonStr))
if err != nil {
return "", err
}
defer resp.Body.Close()
result, _ := ioutil.ReadAll(resp.Body)
return string(result), nil
}
func StackTrace() string {
ret := "\n\t\t[StackTrace]:\n"
for i := 1; i < 40; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
break
}
ret = fmt.Sprintf("%s\t\t%d. %s() %s:%d\n", ret, i, runtime.FuncForPC(pc).Name(), file, line)
}
return ret
}
func GetSystemUserName() string {
if us, err := user.Current(); err != nil {
return ""
} else {
return us.Username
}
}
Go
1
https://gitee.com/night-tc/gobige.git
git@gitee.com:night-tc/gobige.git
night-tc
gobige
Gobige
00125336c61c

搜索帮助

53164aa7 5694891 3bd8fe86 5694891