新增admin
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -33,13 +34,20 @@ func Init() error {
|
||||
}
|
||||
|
||||
func initConfig() error {
|
||||
var dbPath, dbName, dbUsername, dbPwd, dbLogZap, dbLogMod string
|
||||
var dbIp, dbPort, dbName, dbUsername, dbPwd, dbLogZap, dbLogMod string
|
||||
var maxIdleConns, maxOpenConns int
|
||||
fmt.Println("Please input your database path: ")
|
||||
fmt.Printf("Database path default is '%s'\n", CONFIG.Path)
|
||||
fmt.Scanln(&dbPath)
|
||||
if dbPath != "" {
|
||||
CONFIG.Path = dbPath
|
||||
fmt.Println("Please input your database Ip: ")
|
||||
fmt.Printf("Database path default is '%s'\n", CONFIG.Ip)
|
||||
fmt.Scanln(&dbIp)
|
||||
if dbIp != "" {
|
||||
CONFIG.Ip = dbIp
|
||||
}
|
||||
|
||||
fmt.Println("Please input your database Port: ")
|
||||
fmt.Printf("Database path default is '%s'\n", strconv.Itoa(CONFIG.Port))
|
||||
fmt.Scanln(&dbPort)
|
||||
if dbPort != "" {
|
||||
CONFIG.Port, _ = strconv.Atoi(dbPort)
|
||||
}
|
||||
|
||||
fmt.Println("Please input your database db-name: ")
|
||||
|
||||
@@ -3,6 +3,7 @@ package database
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
@@ -11,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
var CONFIG = Mysql{
|
||||
Path: "127.0.0.1:3306",
|
||||
Ip: "127.0.0.1",
|
||||
Port: 3306,
|
||||
Config: "charset=utf8mb4&parseTime=True&loc=Local",
|
||||
DbName: "iris-admin",
|
||||
Username: "root",
|
||||
@@ -23,7 +25,8 @@ var CONFIG = Mysql{
|
||||
}
|
||||
|
||||
type Mysql struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
Ip string `mapstructure:"ip" json:"ip" yaml:"ip"`
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"`
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"`
|
||||
DbName string `mapstructure:"db-name" json:"db-name" yaml:"db-name"`
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"`
|
||||
@@ -41,7 +44,7 @@ func (m *Mysql) Dsn() string {
|
||||
|
||||
// Dsn return
|
||||
func (m *Mysql) BaseDsn() string {
|
||||
return fmt.Sprintf("%s:%s@tcp(%s)/", m.Username, m.Password, m.Path)
|
||||
return fmt.Sprintf("%s:%s@tcp(%s)/", m.Username, m.Password, m.Ip+":"+strconv.Itoa(m.Port))
|
||||
}
|
||||
|
||||
// IsExist config file is exist
|
||||
@@ -88,7 +91,8 @@ func getViperConfig() viper_server.ViperConfig {
|
||||
//
|
||||
Default: []byte(`
|
||||
{
|
||||
"path": "` + CONFIG.Path + `",
|
||||
"ip": "` + CONFIG.Ip + `",
|
||||
"port": "` + strconv.Itoa(CONFIG.Port) + `",
|
||||
"config": "` + CONFIG.Config + `",
|
||||
"db-name": "` + CONFIG.DbName + `",
|
||||
"username": "` + CONFIG.Username + `",
|
||||
|
||||
Reference in New Issue
Block a user