随笔分类 -  5-Go

摘要:1. 调用C代码 把C语言代码写在注释中 导入import "C" 导入和注释之间不能有空行 package main /* int add(int a,int b) { return a+b; } */ import "C" func main() { i := C.add(3,5) printl 阅读全文
posted @ 2020-08-15 22:56 富坚老贼 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-05-22 22:40 富坚老贼 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-05-22 19:34 富坚老贼 阅读(118) 评论(0) 推荐(0) 编辑
摘要:go get github.com/tarm/goserial package main import ( "log" serial "github.com/tarm/goserial" ) func main() { //设置串口号和波特率 s := &serial.Config{Name: "c 阅读全文
posted @ 2020-05-22 15:45 富坚老贼 阅读(1660) 评论(0) 推荐(0) 编辑
摘要:1.基础 接口命名一般在最后加 er package main //计算 type calculationer interface { work(i int, j int) int } //加法结构体 type add struct { } func (c add) work(i int, j in 阅读全文
posted @ 2020-05-20 22:48 富坚老贼 阅读(136) 评论(0) 推荐(0) 编辑
摘要:init的执行时机 导入包时前面加 _ 表示只执行包内的init函数 main包会编译成.exe 使用首字母大小写来说明包是否外部可见 阅读全文
posted @ 2020-05-20 22:45 富坚老贼 阅读(90) 评论(0) 推荐(0) 编辑
摘要:使用go mod 代理来安装 https://goproxy.io是一个国内的代理执行 go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.io,direct 重启vscode提示安装所有插件 阅读全文
posted @ 2020-05-20 09:23 富坚老贼 阅读(136) 评论(0) 推荐(0) 编辑
摘要:1.启动go module set GO111MODULE=on GO111MODULE=off 禁用模块支持,编译时会从GOPATH和vendor文件夹中查找包 GO111MODULE=on启用模块支持,编译时会忽略GOPATH和vendor文件夹,只根据 go.mod下载依赖 GO111MODU 阅读全文
posted @ 2020-05-19 13:44 富坚老贼 阅读(235) 评论(0) 推荐(0) 编辑
摘要:1.服务器监听 package main import ( "net" ) func main() { //监听端口 ln, err := net.Listen("tcp", ":8080") if err != nil { } for { //接收请求建立连接,没有连接阻塞等待 conn, err 阅读全文
posted @ 2020-05-13 13:55 富坚老贼 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-05-12 13:25 富坚老贼 阅读(121) 评论(0) 推荐(0) 编辑
摘要:下载git 下载mysql库 go get github.com/go-sql-driver/mysql package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" ) func main() { // 阅读全文
posted @ 2020-05-06 22:55 富坚老贼 阅读(105) 评论(0) 推荐(0) 编辑
摘要:还可以参考 https://github.com/wendal/go-oci8 一、下载oci ORACLE调用接口(Oracle Call Interface简称OCI) https://www.oracle.com/database/technologies/instant-client/dow 阅读全文
posted @ 2020-04-30 22:43 富坚老贼 阅读(1290) 评论(0) 推荐(0) 编辑
摘要:一、 1.安装 go get -u github.com/gin-gonic/gin 2.例子 package main import "github.com/gin-gonic/gin" func main() { r := gin.Default() r.GET("/ping", func(c 阅读全文
posted @ 2019-06-14 21:43 富坚老贼 阅读(632) 评论(0) 推荐(0) 编辑
摘要:https://www.json.cn/ 阅读全文
posted @ 2019-05-12 09:09 富坚老贼 阅读(90) 评论(0) 推荐(0) 编辑
摘要:一、 引入 编写 编译或F5 访问 http://localhost:8080 二、 编码 访问 阅读全文
posted @ 2019-05-05 09:09 富坚老贼 阅读(204) 评论(0) 推荐(0) 编辑
摘要:1.go bulid 编译成 go build main.go 运行 .\main.exe 更改生成的exe名称 go build -o main.go 2.直接运行不生成.exe文件 go run main.go 3.install go install main go install 只是将编译 阅读全文
posted @ 2019-05-02 23:17 富坚老贼 阅读(410) 评论(0) 推荐(0) 编辑
摘要:一、协程 查看CPU数目 import ( "fmt" "runtime" ) func main() { num := runtime.NumCPU() fmt.Print(num) } 二、管道 管道用来在多个协程间进行通信 初始化分配 //使用make的类型 slice map chan // 阅读全文
posted @ 2019-04-30 20:43 富坚老贼 阅读(183) 评论(0) 推荐(0) 编辑
摘要:一、封装 二、继承 1. 2. 3. 4. 5 6. 7.多重继承 三、接口 1.接口定义 (1)接口本身不能创建实例,但可以现实指向该接口的实例 (2)接口中不能有方法体 (3)如果实现接口则需要实现这个接口的所有方法。 (4)不仅是结构体能实现接口,自定义类型都可以。 (5)一个自定义类型可以实 阅读全文
posted @ 2019-04-27 16:20 富坚老贼 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2019-04-26 19:38 富坚老贼 阅读(79) 评论(0) 推荐(0) 编辑
摘要:1. 声明一个结构体 type Student struct { age int name string } func main() { var stu = Student{age: 18, name: "liu"} print(stu.age) } 如果没初始化,默认为该类型默认值 var stu 阅读全文
posted @ 2019-04-26 19:35 富坚老贼 阅读(93) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示