initial commit
This commit is contained in:
23
user/internal/svc/servicecontext.go
Normal file
23
user/internal/svc/servicecontext.go
Normal file
@ -0,0 +1,23 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"godemo/user/internal/config"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db := sqlx.MustConnect("postgres", c.DataSource)
|
||||
db.SetMaxOpenConns(10)
|
||||
db.SetMaxIdleConns(5)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user