至少我们曾经在一起过。
来自:一言
var xhr = new XMLHttpRequest(); xhr.open('get', 'https://v1.hitokoto.cn/'); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { var data = JSON.parse(xhr.responseText); var hitokoto = document.getElementById('hitokoto'); hitokoto.innerText = data.hitokoto; } } xhr.send();
记录一些踩坑笔记
1.http.post包有时候会验证https证书的有效性,需要加上一下代码进行跳过https证书的验证.以及跟随302跳转
错误:x509: cannot validate certificate for xxx:xxx:xxx:xxx because it doesn't contain any IP SANs
查看代码
代码语言:javascript复制func Test(url string) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
c := &http.Client{
Transport: tr,
Timeout: 5 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
reqest, err := c.Get(url)
if err != nil {
return
}
defer reqest.Body.Close()
if err != nil {
fmt.Println("出错了!")
return
}
body, err := ioutil.ReadAll(reqest.Body)
//fmt.Println(string(body))
pageStr := string(body)
if reqest.Status == "302 Found" {
log.Println("有302重定向,重定向内容.", nurl)
}
}
2.golang设置图标与uac权限
点击查看ico.manifest内容
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="x86"
name="controls"
type="win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
代码语言:javascript复制go get github.com/akavel/rsrc
执行 rsrc.exe -manifest ico.manifest -o app.syso -ico app.ico 这样会生成一个叫做app.syso的文件,把这个文件和main.go放到一起
温馨提示
rsrc -arch 386 -manifest main.exe.manifest -ico icon.ico rsrc -arch amd64 -manifest main.exe.manifest -ico icon.ico
可指定位数
代码语言:javascript复制然后直接编译即可
3.利用strings.Contains判断字符串是否存在
点击查看相关代码
代码语言:javascript复制if strings.Contains("try", "t") { //如果存在的话,会返回true
fmt.Println("t字符存在与try字符串中")
} else {
fmt.Println("t字符不存在与try字符串中")
}
4.设置国内软件源 GOPROXY=https://goproxy.cn,direct
5.golang编译时去除文件相关信息
代码语言:javascript复制go build -trimpath -ldflags="-w -s"
Golang也太好玩了吧.