澄澈的眼|Yiigo超好用的go开发辅助库
今天小编给大家推荐一个 Go 轻量级开发通用库 , 简单易上手 , 功能满足大部分日常开发
Features
- 支持 MySQL
- 支持 PostgreSQL
- 支持 MongoDB
- 支持 Redis
- 支持 Apollo
- 邮件使用 gomail
- 配置使用 toml
- SQL使用 sqlx
- ORM使用 gorm
- 日志使用 zap
- 包含一些实用的帮助方法 , 如:http、cypto、date、IP 等
Go1.11+Installationgo get github.com/shenghui0779/yiigoUsageConfig- yiigo.toml
[app]env = "dev" # dev | beta | proddebug = true[apollo]app_id = "test"cluster = "default"address = "127.0.0.1:8080"namespace = ["apollo_test"]cache_dir = "./"accesskey_secret = ""insecure_skip_verify = true[db][db.default]driver = "mysql"dsn = "username:password@tcp(localhost:3306)/dbname?timeout=10s
MySQL// default dbyiigo.DB().Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)yiigo.Orm().First(&User{}, 1)// other dbyiigo.DB("foo").Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)yiigo.Orm("foo").First(&User{}, 1)MongoDB// default mongodbctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)defer cancel()yiigo.Mongo().Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})// other mongodbctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)defer cancel()yiigo.Mongo("foo").Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})Redis// default redisconn, err := yiigo.Redis().Get()if err != nil {log.Fatal(err)}defer yiigo.Redis().Put(conn)conn.Do("SET", "test_key", "hello world")// other redisconn, err := yiigo.Redis("foo").Get()if err != nil {log.Fatal(err)}defer yiigo.Redis("foo").Put(conn)conn.Do("SET", "test_key", "hello world")HTTPclient, err := yiigo.NewHTTPClient(yiigo.WithHTTPMaxIdleConnsPerHost(1000),yiigo.WithHTTPMaxConnsPerHost(1000),yiigo.WithHTTPDefaultTimeout(time.Second*10),)if err != nil {log.Fatal(err)}b, err := client.Get("url...", yiigo.WithRequestTimeout(5*time.Second))if err != nil {log.Fatal(err)}fmt.Println(string(b))Logger【澄澈的眼|Yiigo超好用的go开发辅助库】// default loggeryiigo.Logger().Info("hello world")// other loggeryiigo.Logger("foo").Info("hello world")
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 美容|盘点秋冬超好看的口红:这些口红超滋润显白显温柔,你入手了几支
- 澄澈的眼|始料未及:华为不敌小米?上半年全球手机出货量TOP10公布
- 生姜|不干不坏,随吃随取!生姜保鲜,这5招超好用
- 烹饪|夏天冬瓜正当季,大厨教你这样做,鲜香味美,开胃下饭超好吃
- 澄澈的眼|10年了,腾讯微博终于不折腾了
- 宁静|李斯丹妮评价宁静, 坦言以后不再和宁静同台, 原因也是超好笑
- 美容|有哪些超好用的爽肤水品牌?这些爽肤水根源修护,简直是业内良心
- 穿搭|越来越冷的天气,穿搭假两件卫衣卫衣,时尚有美感,减龄效果超好
- 「淘宝」学生党福音!淘宝上便宜好看又质量超好的神仙女装店铺!均价不超过50!
- 澄澈的眼|这Spring注入对象处理过程也太细了,收藏了,什么神仙
