Skip to content
Make Golang development easier !
Go
Branch: master
Clone or download
shenghui
shenghui update
Latest commit e9619c5 Aug 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore update Aug 15, 2019
LICENSE update Jul 6, 2017
README.md update Aug 16, 2019
crypto.go PKCS#7 Apr 22, 2019
crypto_test.go aes cbc crypt Apr 18, 2019
db.go update Aug 15, 2019
db_test.go update go.mod May 4, 2019
doc.go update Aug 15, 2019
env.go Update env & redis Jun 28, 2019
env_test.go add some improments Mar 27, 2019
go.mod update Aug 14, 2019
go.sum update Aug 14, 2019
http.go
logger.go update Aug 15, 2019
mailer.go update Aug 15, 2019
mongo.go
redis.go update Aug 15, 2019
slice.go add some improments Mar 27, 2019
slice_test.go add some improments Mar 27, 2019
strings.go update strings Jun 17, 2019
strings_test.go add some improments Mar 17, 2019
utils.go define XML CDATA section Apr 18, 2019
utils_test.go add some improments Mar 27, 2019
zipkin.go update Aug 15, 2019

README.md

yiigo

golang GoDoc GitHub release MIT license

A simple and light library which makes Golang development easier !

Features

Requirements

Go1.11+

Installation

go get github.com/iiinsomnia/yiigo/v3

Usage

MySQL

// 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

// 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

// 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

// 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

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

// 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

Enjoy 😊

You can’t perform that action at this time.