git.zd.zone/hrpc/hrpc@v0.0.12/database/mysql/README.md (about) 1 # Introduction 2 3 4 ## Usages 5 6 Customized use case. 7 ```go 8 func main() { 9 s, err := hrpc.NewServer( 10 option.WithServerName("orderservice"), 11 option.WithDatabases(mysql.New( 12 mysql.WithCustomized(), // Very important, if you forget to provide this option, the HRPC will read configuration got from the configuration center to load. 13 mysql.WithAddress("xxxx"), 14 mysql.WithDB("aaa_db"), 15 mysql.WithAuth("user", "pass"), 16 mysql.WithPort(12144), // Default 3306 17 )), 18 option.WithEnvironment(option.Development), 19 option.WithHealthCheck(), 20 ) 21 // xxx 22 } 23 ``` 24 25 26 Customized use case with connection pool 27 ```go 28 func main() { 29 s, err := hrpc.NewServer( 30 option.WithServerName("orderservice"), 31 option.WithDatabases(mysql.New( 32 mysql.WithCustomized(), 33 mysql.WithAddress("xxxx"), 34 mysql.WithDB("aaa_db"), 35 mysql.WithAuth("user", "pass"), 36 mysql.WithPort(12144), // Default 3306 37 mysql.WithMaxOpenConns(10), // Default 3 38 mysql.WithMaxIdleConns(4), // Default 1 39 )), 40 option.WithEnvironment(option.Development), 41 option.WithHealthCheck(), 42 ) 43 // xxx 44 } 45 ```