Skip to content

Commit

Permalink
update mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Nov 15, 2018
1 parent b9867a4 commit 7b4abd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ func main() {
manager := manage.NewDefaultManager()

// use mysql token store
manager.MapTokenStorage(
mysql.NewStore(mysql.NewConfig("root:123456@tcp(127.0.0.1:3306)/myapp_test?charset=utf8"), "", 0),
store := mysql.NewStore(
mysql.NewConfig("root:123456@tcp(127.0.0.1:3306)/myapp_test?charset=utf8"), "", 0),
"",
0,
)

defer store.Close()

manager.MapTokenStorage(store)
// ...
}

Expand Down
8 changes: 7 additions & 1 deletion mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type Config struct {
}

// NewStore create mysql store instance,
// config mysql configuration,
// tableName table name (default oauth2_token),
// GC time interval (in seconds, default 600)
func NewStore(config *Config, tableName string, gcInterval int) *Store {
db, err := sql.Open("mysql", config.DSN)
if err != nil {
Expand All @@ -55,7 +58,10 @@ func NewStore(config *Config, tableName string, gcInterval int) *Store {
return NewStoreWithDB(db, tableName, gcInterval)
}

// NewStoreWithDB create mysql store instance
// NewStoreWithDB create mysql store instance,
// db sql.DB,
// tableName table name (default oauth2_token),
// GC time interval (in seconds, default 600)
func NewStoreWithDB(db *sql.DB, tableName string, gcInterval int) *Store {
store := &Store{
db: &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{Encoding: "UTF8", Engine: "MyISAM"}},
Expand Down

0 comments on commit 7b4abd7

Please sign in to comment.