-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample_test.go
50 lines (41 loc) · 1.13 KB
/
example_test.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
package rdsmysql_test
import (
"database/sql"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/go-sql-driver/mysql"
"github.com/shogo82148/rdsmysql"
)
func ExampleConnector() {
// configure AWS session
awsConfig := aws.NewConfig().WithRegion("ap-northeast-1")
awsSession := session.Must(session.NewSession(awsConfig))
// configure the connector
cfg, err := mysql.ParseDSN("user:@tcp(db-foobar.ap-northeast-1.rds.amazonaws.com:3306)/")
if err != nil {
panic(err)
}
connector := &rdsmysql.Connector{
Session: awsSession,
Config: cfg,
}
// open the database
db := sql.OpenDB(connector)
defer db.Close()
// ... do something using db ...
}
func ExampleDriver() {
// register authentication information
awsConfig := aws.NewConfig().WithRegion("ap-northeast-1")
awsSession := session.Must(session.NewSession(awsConfig))
driver := &rdsmysql.Driver{
Session: awsSession,
}
sql.Register("rdsmysql", driver)
db, err := sql.Open("rdsmysql", "user:@tcp(db-foobar.ap-northeast-1.rds.amazonaws.com:3306)/")
if err != nil {
panic(err)
}
defer db.Close()
// ... do something using db ...
}