This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
forked from shenghui0779/yiigo
/
doc.go
117 lines (117 loc) · 2.9 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Package yiigo makes Golang development easier !
//
// Basic 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.GetBool("app.debug", true)
// yiigo.Env.GetInt("app.port", 12345)
// yiigo.Env.GetString("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"),
// 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")
//
// For more details, see the documentation for the types and methods.
//
package yiigo