cluster.go 889 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5
package console

import (
	"strconv"

Y
Your Name 已提交
6 7
	"github.com/pkg/errors"

黄孟柱 已提交
8 9
	"github.com/eolinker/goku-api-gateway/common/conf"
	"github.com/eolinker/goku-api-gateway/server/entity"
E
eoLinker API Management 已提交
10 11 12
)

func getDefaultDatabase() (*entity.ClusterDB, error) {
Y
Your Name 已提交
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
	dbType := conf.MastValue("db_type", "sqlite3")
	switch dbType {
	case mysqlDriver:
		{
			dbPort, err := strconv.Atoi(conf.MastValue("db_port", "3306"))
			if err != nil {
				return nil, err
			}
			return &entity.ClusterDB{
				Driver:   dbType,
				Host:     conf.Value("db_host"),
				Port:     dbPort,
				UserName: conf.Value("db_user"),
				Password: conf.Value("db_password"),
				Database: conf.Value("db_name"),
			}, nil
		}
	case sqlite3Driver:
		{
			return &entity.ClusterDB{
				Driver: dbType,
				Path:   conf.MastValue("db_path", "./work/goku.db"),
			}, nil
		}
	default:
		{
			return nil, errors.New("unsupported database type")
		}
E
eoLinker API Management 已提交
41 42 43
	}

}