GO学习笔记

GO相关技术

相关技术栈

  1. gin
  2. gorm
  3. swagger
  4. logrus auth

gin 是目前 golang使用最广泛的web框架之一

API: https://gin-gonic.com/zh-cn/docs/

  • webSocket
  • channel/goroutine
  • gin
  • template
  • gorm
  • sql
  • nosql
  • mq

环境搭建

go version

set GO111MODULE=on

go mod init go_exam

go mod tidy

GOPROXY

go env -w GOPROXY=https://goproxy.cn,direct

go env -w GOSUMDB=off (关闭包的有效性验证)

go env -w GOSUMDB=“sum.golang.google.cn” (也可设置国内提供的sum 验证服务)

go mod 初始化

go mod init modlename

go mod tidy

go package查找

http://go.pkg.dev

token 加入

用str=fmt.Sprintf(“%d”, time.Now().Unix())

temp= utils.MD5Encode(str)

utilsdb.Models()

go get githup.com/garyburd/redigo/redis

GO GRPC

https://blog.csdn.net/qq_62345961/article/details/124479488

go get -u google.golang.org/grpc

go get -u google.golang.org/protobuf

https://github.com/protocolbuffers/protobuf/releases

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

image-20230110105658161

golang中使用RESTful,用json传输数据,一般使用

https://github.com/gorilla/mux ,

https://github.com/gin-gonic/gin,

https://github.com/labstack/echo,

https://github.com/emicklei/go-restful 等
golang中的RPC现在一般使用g家的gRPC,

https://grpc.io/, 毕竟大家都相信g家的技术实力 – -!

go grpc demo

https://www.cnblogs.com/zhangmingcheng/p/16329237.html

https://blog.csdn.net/qq_37362891/article/details/103809482?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-10-103809482-blog-115807946.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-10-103809482-blog-115807946.pc_relevant_default&utm_relevant_index=11

https://www.cnblogs.com/gutousu/p/9951956.html

https://www.jianshu.com/p/21d5d7624951

protoc --go_out=.  service.proto
protoc --go-grpc_out=. service.proto  

https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md

grpc版本参考

go.mod

module go-grpc

go 1.19

require (
    google.golang.org/grpc v1.51.0
    google.golang.org/protobuf v1.28.1
)

require (
    github.com/golang/protobuf v1.5.2 // indirect
    golang.org/x/net v0.5.0 // indirect
    golang.org/x/sys v0.4.0 // indirect
    golang.org/x/text v0.6.0 // indirect
    google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
)

go_package

.proto 文件中需要这是go_package,分号前为目录,如果与 .proto一样,则可以输出.,分号后面为package名。

option go_package = ".;proto";

.proto生成go 代码

protoc --go_out=. --go_opt=paths=source_relative  --go-grpc_out=. --go-grpc_opt=paths=source_relative  common/service.proto

protoc --go_out=. --go_opt=paths=source_relative  --go-grpc_out=. --go-grpc_opt=paths=source_relative  helloworld/helloworld.proto

grpc抓包分析

image-20230111224924379

server

GOROOT=D:\Go #gosetup
GOPATH=C:\Users\Administrator\go #gosetup
D:\Go\bin\go.exe build -o C:\Users\Administrator\AppData\Local\Temp\GoLand\___1go_build_go_grpc_main_service.exe go-grpc/main/service #gosetup
C:\Users\Administrator\AppData\Local\Temp\GoLand\___1go_build_go_grpc_main_service.exe

client

GOROOT=D:\Go #gosetup
GOPATH=C:\Users\Administrator\go #gosetup
D:\Go\bin\go.exe build -o C:\Users\Administrator\AppData\Local\Temp\GoLand\___2go_build_go_grpc_main_client.exe go-grpc/main/client #gosetup
C:\Users\Administrator\AppData\Local\Temp\GoLand\___2go_build_go_grpc_main_client.exe hahahahaha
2023/01/11 22:45:26 Greeting: Hello hahahahaha

【go语言专题】JAVA&GO通过GRPC互相调用

https://blog.csdn.net/qq_37362891/article/details/103809482

https://github.com/fafeidou/fast-cloud-nacos

https://github.com/fafeidou/go-grpc

go 动态加载库

https://github.com/hashicorp/go-plugin

它基于net/rpc ,grpc实现,主程序和plugin程序是两个qtj独立进程,可以通过主程序调用plugin进程启动,也可以附加进程的方式。通过本地网络通讯,达到类似动态链接库调用的效果。

go get github.com/hashicorp/go-hclog

go get github.com/hashicorp/go-plugin

go get google.golang.org/grpc

go get golang.org/x/net/context

GO GRPC DEMO

二个命令同时生成客户端和服务端需要代码

protoc –go_out=src\proto src\proto\user_provider.proto
protoc –go-grpc_out=src\proto src\proto\user_provider.proto

一个命令同时生成客户端和服务端需要代码

protoc –go_out=. –go_opt=paths=source_relative –go-grpc_out=. –go-grpc_opt=paths=source_relative src\proto\user_provider.proto

go开发窗口程序

https://golang-tech-stack.com/tutorial/

安装MSYS2

pacman -Syu

pacman -S git mingw-w64-x86_64-toolchain

第一个fyne应用

go get fyne.io/fyne/v2

二:原因
https://proxy.golang.org/github.com/ 国内无法访问

三:换成国内可访问的地址,设置GOPROXY代理
go env -w GOPROXY=https://goproxy.cn,direct

go env -w GOSUMDB=off (关闭包的有效性验证)

go env -w GOSUMDB=“sum.golang.google.cn” (也可设置国内提供的sum 验证服务)

备注:-w 标记 要求一个或多个形式为 NAME=VALUE 的参数且覆盖默认的设置

打包go fyne应用

go install fyne.io/fyne/v2/cmd/fyne@latest

fyne package –appVersion 1.0.0 –name godemo –release –appID godemo01.001

sqlite DB

go get github.com/glebarez/go-sqlite

GTK

msys2

安装gtk3

pacman -S mingw-w64-x86_64-gtk3

pacman -S mingw-w64-x86_64-gtk2

pkg-config –cflags gtk+-2.0

make -v

github.com/mattn/go-gtk/gtk

goplus

https://github.com/goplus/spx

go游戏开发

http://docs.cocos.com/creator/manual/zh/getting-started/install

https://docs.cocos.com/creator/manual/zh/

欢迎使用 Cocos Creator 3.7!

Cocos Creator 既是一款高效、轻量、免费开源的跨平台 2D&3D 图形引擎,也是一个实时 2D&3D 数字内容创作平台。拥有高性能低功耗流式加载跨平台等诸多优点,您可以用它来创作游戏车机XR元宇宙等领域的项目。

go excel

GitHub: https://github.com/xuri/excelize Docs: https://xuri.me/excelize

go get github.com/360EntSecGroup-Skylar/excelize/v2

emacs 配置golang

https://github.com/lienhua34/myemacs-conf/tree/master/elisp/golang

golang 操作apache ignite数据库

PS D:\work\goprj\godemo01> go get -u github.com/amsokol/ignite-go-client
go: downloading github.com/amsokol/ignite-go-client v0.12.2
go: added github.com/amsokol/ignite-go-client v0.12.2
PS D:\work\goprj\godemo01> 

CREATE TABLE PUBLIC.USER (
    ID INTEGER,
    NAME VARCHAR(100),
    AGE INTEGER,
    SEX VARCHAR(100),
    CONSTRAINT USER_PK PRIMARY KEY (ID)
);


INSERT INTO USER VALUES(1,'ZHANGSAN',18,'F');
INSERT INTO USER VALUES(2,'LISI',20,'M');

SELECT * FROM USER;


CREATE TABLE sys_authorities_copy1  (
  created_at datetime ,
  updated_at datetime ,
  deleted_at datetime ,
  authority_id bigint,
  authority_name varchar(191),
  parent_id bigint UNSIGNED ,
  default_router varchar(191) ,
  PRIMARY KEY (authority_id)
)

SELECT * FROM sys_authorities_copy1



"INSERT INTO Organization(_key, name, foundDateTime)

CREATE TABLE PUBLIC.Organization (
    _key INTEGER,
    NAME VARCHAR(100),
    foundDateTime DATETIME
    CONSTRAINT USER_PK PRIMARY KEY (_key)
);

发表评论