1、go设置代理直连
go env -w GOPROXY=https://goproxy.io,direct
go env -w GO111MODULE="on"
二、go编译dll
go build -buildmode=c-shared -o exportgo.dll exportgo.go
三、go基本安装命令
go get -u github.com/PuerkitoBio/goquery
三、go代码
package main
import "C"
import "fmt"
//export PrintBye
func PrintBye() {
fmt.Println("From DLL: Bye!")
}
//export Sum
func Sum(a int, b int) int {
return a + b;
}
func main() {
// Need a main function to make CGO compile package as C shared library
}
四、python调用代码
from ctypes import *
dll = windll.LoadLibrary(r'C:\Users\Administrator\Desktop\py\exportgo.dll')
print(dll.PrintBye())
print(dll.Sum(3, 2))
本文介绍了如何在Go中设置代理直连和编译为DLL以便于Python调用。步骤包括配置GOPROXY和GO111MODULE,使用gobuild编译动态链接库,并展示了Python通过ctypes导入Go DLL进行函数调用的实例。
2万+

被折叠的 条评论
为什么被折叠?



