mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-27 06:48:21 -05:00
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@gmail.com>
42 lines
813 B
Go
42 lines
813 B
Go
package database
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"scroll-tech/database/cache"
|
|
)
|
|
|
|
// PersistenceConfig persistence db config.
|
|
type PersistenceConfig struct {
|
|
// data source name
|
|
DSN string `json:"dsn"`
|
|
DriverName string `json:"driver_name"`
|
|
|
|
MaxOpenNum int `json:"maxOpenNum" default:"200"`
|
|
MaxIdleNum int `json:"maxIdleNum" default:"20"`
|
|
}
|
|
|
|
// DBConfig db config
|
|
type DBConfig struct {
|
|
Persistence *PersistenceConfig `json:"persistence"`
|
|
Redis *cache.RedisConfig `json:"redis"`
|
|
}
|
|
|
|
// NewConfig returns a new instance of Config.
|
|
func NewConfig(file string) (*DBConfig, error) {
|
|
buf, err := os.ReadFile(filepath.Clean(file))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cfg := &DBConfig{}
|
|
err = json.Unmarshal(buf, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|