yiigo 3.x 版本釋出
# [yiigo](https://github.com/iiinsomnia/yiigo)
A simple and light library which makes Golang development easier !
## Features
- Support [MySQL](https://github.com/go-sql-driver/mysql)
- Support [PostgreSQL](https://github.com/lib/pq)
- Support [MongoDB](https://github.com/mongodb/mongo-go-driver)
- Support [Redis](https://github.com/gomodule/redigo)
- Support [Zipkin](https://github.com/openzipkin/zipkin-go)
- Use [gomail](https://github.com/go-gomail/gomail) for email sending
- Use [toml](https://github.com/pelletier/go-toml) for configuration
- Use [sqlx](https://github.com/jmoiron/sqlx) for SQL executing
- Use [zap](https://github.com/uber-go/zap) for logging
## Requirements
`Go1.11+`
## Installation
```sh
go get github.com/iiinsomnia/yiigo/v3
```
## Usage
#### MySQL
```go
// default db
yiigo.RegisterDB(yiigo.AsDefault, yiigo.MySQL, "root:root@tcp(localhost:3306)/test")
yiigo.DB.Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)
// other db
yiigo.RegisterDB("foo", yiigo.MySQL, "root:root@tcp(localhost:3306)/foo")
yiigo.UseDB("foo").Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)
```
#### MongoDB
```go
// default mongodb
yiigo.RegisterMongoDB(yiigo.AsDefault, "mongodb://localhost:27017")
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
yiigo.Mongo.Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})
// other mongodb
yiigo.RegisterMongoDB("foo", "mongodb://localhost:27017")
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
yiigo.UseMongo("foo").Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})
```
#### Redis
```go
// default redis
yiigo.RegisterRedis(yiigo.AsDefault, "localhost:6379")
conn, err := yiigo.Redis.Get()
if err != nil {
log.Fatal(err)
}
defer yiigo.Redis.Put(conn)
conn.Do("SET", "test_key", "hello world")
// other redis
yiigo.RegisterRedis("foo", "localhost:6379")
foo := yiigo.UseRedis("foo")
conn, err := foo.Get()
if err != nil {
log.Fatal(err)
}
defer foo.Put(conn)
conn.Do("SET", "test_key", "hello world")
```
#### Config
```go
// env.toml
//
// [app]
// env = "dev"
// debug = true
// port = 50001
yiigo.UseEnv("env.toml")
yiigo.Env.Bool("app.debug", true)
yiigo.Env.Int("app.port", 12345)
yiigo.Env.String("app.env", "dev")
```
#### Zipkin
```go
tracer, err := yiigo.NewZipkinTracer("http://localhost:9411/api/v2/spans",
yiigo.WithZipkinTracerEndpoint("zipkin-test", "localhost"),
yiigo.WithZipkinTracerSharedSpans(false),
yiigo.WithZipkinTracerSamplerMod(1),
)
if err != nil {
log.Fatal(err)
}
client, err := yiigo.NewZipkinClient(tracer)
if err != nil {
log.Fatal(err)
}
b, err := client.Get(context.Background(), "url...",
yiigo.WithRequestHeader("Content-Type", "application/json; charset=utf-8"),
yiigo.WithRequestTimeout(5*time.Second),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
```
#### Logger
```go
// default logger
yiigo.RegisterLogger(yiigo.AsDefault, "app.log")
yiigo.Logger.Info("hello world")
// other logger
yiigo.RegisterLogger("foo", "foo.log")
yiigo.UseLogger("foo").Info("hello world")
```
## Documentation
- [API Reference](https://godoc.org/github.com/iiinsomnia/yiigo)
- [TOML](https://github.com/toml-lang/toml)
- [Example](https://github.com/iiinsomnia/yiigo-example)
**Enjoy ^_^**
相關文章
- yiigo 4.x 版本釋出Go
- Apache Lucene 5.0釋出,不再相容3.X系列版本Apache
- ClickHouse ORM 3.x 釋出啦ORM
- jQuery 釋出 3.4.0 版本jQuery
- Gitea 釋出 1.0.1 版本Git
- Oracle 12.1.0.2.0 版本釋出Oracle
- SOA新版本釋出
- [版本釋出]ThinkOX V1正式版釋出【版本號V1.0.2】
- Apache Doris 1.2.4 Release 版本正式釋出|版本通告Apache
- Spark版本釋出歷史,及其各版本特性Spark
- Swoftcli: 釋出 v0.1.5 版本
- HMS Core 6.3.0 版本釋出公告
- openGauss 2.0.0 版本正式釋出
- FlutterBoost3.0釋出preview版本FlutterView
- Apache Doris 2.0.3 版本正式釋出Apache
- Apache APISIX 3.1.0 版本正式釋出ApacheAPI
- BabaSSL 8.3.1 釋出穩定版本
- Apache Doris 2.0.4 版本正式釋出Apache
- beego 1.7.1 新版本釋出Go
- Gitea 釋出 1.0.1版本Git
- Apache Doris 2.0.5 版本正式釋出Apache
- Apache Doris 2.0.5 版本正式釋出!Apache
- Rust 1.82.0版本釋出Rust
- ASP.NET Core 3.x API版本控制ASP.NETAPI
- Swoole v4.6.1 版本釋出,Bug 修復版本
- 優麒麟 14.04.6 LTS 版本釋出!
- Laravel-admin 釋出 1.7.3 版本Laravel
- Laravel-admin 釋出 1.7.0 版本Laravel
- Laravel-admin 釋出 1.7.2 版本Laravel
- MAUI候選版本3釋出啦UI
- Erlang/OTP 24版本釋出
- Micronaut框架3的GA 版本釋出!框架
- OpenHarmony v3.1 Release版本釋出
- SuperEdge v0.6.0 版本正式釋出
- Apache HugeGraph1.0.0 版本正式釋出!Apache
- HMS Core 6.10.0版本釋出公告
- Apache Doris 1.2.2 Release 版本正式釋出Apache
- MySQL 版本釋出歷史總結MySql