Golang初学:一些第三方包

go version go1.22.1

--

 

Web 开发

gorilla

https://gowebexamples.com

中的示例有用到。

 

Routing (using gorilla/mux)

go get -u github.com/gorilla/mux

-

Sessions

"github.com/gorilla/sessions"

-

Websockets

$ go get github.com/gorilla/websocket

-

 

gin

go get github.com/gin-gonic/gin

or

go get -u github.com/gin-gonic/gin

 

go zero

https://go-zero.dev

go-zero 是一个集成了各种工程实践的 web 和 rpc 框架。

go-zero 包含极简的 API 定义和生成工具 goctl,可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。

 

安装汇总:
golang 安装
goctl 安装
protoc 安装
go-zero 安装
goctl-intellij 安装
goctl-vscode 安装
-

 

一些命令:

go install github.com/zeromicro/go-zero/tools/goctl@latest

goctl env check --install --verbose --force

go get -u github.com/zeromicro/go-zero@latest

-

 

Beego

命令
go get github.com/astaxie/beego
-

About
beego is an open-source, high-performance web framework for the Go programming language.

https://github.com/astaxie/beego

-

命令:

go get github.com/astaxie/beego@v2.0.0

-

 

bee tool

命令

go get github.com/beego/bee

-

 

Iris

TODO

 

go swagger

命令

go get -u github.com/swaggo/swag/cmd/swag

go install github.com/swaggo/swag/cmd/swag

--以上应该一步完成,install 后,会有一个 swag 可执行文件。

检查 swag版本:

swag -v

--

go get -u -v github.com/swaggo/gin-swagger

go get -u github.com/swaggo/gin-swagger/swaggerFiles

--

go get -u -v github.com/swaggo/files

--

 

swag 命令:

swag --help

swag -h init

-

swag init

$ swag init --output prjswagger
-- 指定目录,默认在 docs 目录。
 
注意,go swagger 目前只用过 "swagger": "2.0",“3.0”不晓得有没有 开源包,TODO
注意,swagger 文档 页面的 UI 没有 Java 的 UI 方便,TODO

 

数据

MySQL

驱动

go get -u github.com/go-sql-driver/mysql

 

sqlite

go get -u gorm.io/gorm

go get -u gorm.io/driver/sqlite

 

gorm

The fantastic ORM library for Golang, aims to be developer friendly.

https://github.com/go-gorm/gorm

$ go get -u gorm.io/gorm

$ go get gorm.io/driver/mysql

-

MySQL、postgresql、sqlite 都支持。

 

Redis

go get github.com/redis/go-redis

上面是 不正确的用法,没有指定版本,虽然也可以用。

下面是正确的:v9

go get github.com/redis/go-redis/v9

-

文档:

https://pkg.go.dev/github.com/redis/go-redis/v9

 

MongoDB

https://www.mongodb.com/zh-cn/docs/languages/go/

MongoDB Go Driver

https://www.mongodb.com/zh-cn/docs/drivers/go/current/

英文版:

https://www.mongodb.com/docs/drivers/go/current/

最新:1.5

 

MongoDB Atlas

MongoDB Enterprise

MongoDB Community:source-available、免费使用且可自行管理的 MongoDB 版本。

 

命令

go get go.mongodb.org/mongo-driver/mongo

go get github.com/joho/godotenv

-

环境变量

export MONGODB_URI='<your atlas connection string>'

 

GridFS

使用 GridFS 规范在 MongoDB 中存储和检索大文件。

GridFS 将大文件分割为数据段,并将每个数据段存储为一个单独的文档。

如果文件大小超过16 MB 的 BSON 文档大小限制,请使用 GridFS。

 

ElasticSearch

https://github.com/elastic/go-elasticsearch

About

The official Go client for Elasticsearch.

v8.13.1

版本

github.com/elastic/go-elasticsearch/v7

github.com/elastic/go-elasticsearch/v8

-

文档

Full documentation is hosted at GitHub and PkgGoDev. This documentation provides only an overview of features.

https://github.com/elastic/go-elasticsearch

https://pkg.go.dev/github.com/elastic/go-elasticsearch

-

 

命令:

go get github.com/elastic/go-elasticsearch/v8@latest

-

 

Kafka

有多个库。

其中 IBM/Sarama 是 最新的 且 比较完备的。

Sarama is a Go library for Apache Kafka.
https://github.com/IBM/sarama

 

其它:

/segmentio/kafka-go

confluent-kafka-go

goka

-

 

命令:

go get github.com/IBM/sarama

-

 

confluent-kafka-go 命令:

安装librdkafka
$ git clone https://github.com/edenhill/librdkafka.git
配置、编译、安装
$ go get -u github.com/confluentinc/confluent-kafka-go/kafka

-

来自 博文:

golang confluent-kafka-go

https://www.cnblogs.com/ExMan/p/14156056.html

posted on 2020-12-18 17:28  ExplorerMan

-

 

RabbitMQ

官方

官方 rabbitmq/amqp091-go

RabbitMQ tutorial - "Hello World!"

https://www.rabbitmq.com/tutorials/tutorial-one-go

命令

go mod init <your-module-name>

go get github.com/rabbitmq/amqp091-go

-

import amqp "github.com/rabbitmq/amqp091-go"

-

 

topgoer

topgoer.com 中 的 2个:

github.com/streadway/amqp

github.com/student/kuteng-RabbitMQ/RabbitMQ

-

 

Etcd

https://etcd.io/

A distributed, reliable key-value store for the most critical data of a distributed system.

 

https://github.com/etcd-io/etcd

etcd is a Go-based project that provides a simple, secure, fast and reliable key-value store for distributed systems.

 

https://pkg.go.dev/go.etcd.io/etcd/client/v3

etcd/clientv3 is the official Go etcd client for v3.

 

命令:

go get go.etcd.io/etcd/client/v3

-

 

场景:

1)直接使用。

2)在 k8s 集群中使用。

 

大数据

TODO

 

---END---

 

参考资料

1、topgoer

https://www.topgoer.com

2、

 

posted @ 2024-06-05 17:17  快乐的二当家815  阅读(9)  评论(0编辑  收藏  举报