代码拉取完成,页面将自动刷新
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
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。