至少我们曾经在一起过。
来自:一言
记录一些踩坑笔记
1.http.post包有时候会验证https证书的有效性,需要加上一下代码进行跳过https证书的验证.以及跟随302跳转
错误:x509: cannot validate certificate for xxx:xxx:xxx:xxx because it doesn't contain any IP SANs
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权限
<?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>
go get github.com/akavel/rsrc 执行 rsrc.exe -manifest ico.manifest -o app.syso -ico app.ico 这样会生成一个叫做app.syso的文件,把这个文件和main.go放到一起
然后直接编译即可
3.利用strings.Contains判断字符串是否存在
if strings.Contains("try", "t") { //如果存在的话,会返回true
fmt.Println("t字符存在与try字符串中")
} else {
fmt.Println("t字符不存在与try字符串中")
}
4.设置国内软件源 GOPROXY=https://goproxy.cn,direct
5.golang编译时去除文件相关信息
go build -trimpath -ldflags="-w -s"
本文作者为TRY,转载请注明。