Add CardtraderToken field to config file
This commit is contained in:
parent
93c2b55754
commit
429732d076
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"User": "<your username>",
|
||||
"Passwd": "<your password>",
|
||||
"Net": "tcp",
|
||||
"Addr": "127.0.0.1:3306",
|
||||
"DBName": "<your database name>",
|
||||
"AllowNativePasswords": true
|
||||
"DatabaseConfig": {
|
||||
"User": "<your username>",
|
||||
"Passwd": "<your password>",
|
||||
"Net": "tcp",
|
||||
"Addr": "127.0.0.1:3306",
|
||||
"DBName": "<your database name>",
|
||||
"AllowNativePasswords": true
|
||||
},
|
||||
"CardtraderToken": "<your cardtrader token>"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
type SevenkeysConfig struct {
|
||||
DatabaseConfig mysql.Config `json:"DatabaseConfig"`
|
||||
CardtraderToken string `json:"CardtraderToken"`
|
||||
}
|
||||
|
||||
func ReadConfigFromFile(filename string) SevenkeysConfig {
|
||||
bytes, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var config SevenkeysConfig
|
||||
err = json.Unmarshal(bytes, &config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
|
@ -2,31 +2,12 @@ package database
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func readConfigFromFile(filename string) mysql.Config {
|
||||
bytes, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var config mysql.Config
|
||||
err = json.Unmarshal(bytes, &config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func GetDatabaseFromConfig(filename string) *sql.DB {
|
||||
config := readConfigFromFile(filename)
|
||||
|
||||
func GetDatabaseFromConfig(config mysql.Config) *sql.DB {
|
||||
db, err := sql.Open("mysql", config.FormatDSN())
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"sevenkeys/config"
|
||||
"sevenkeys/database"
|
||||
"sevenkeys/delverlens"
|
||||
"sevenkeys/logic"
|
||||
|
@ -37,7 +38,8 @@ func main() {
|
|||
|
||||
flag.Parse()
|
||||
|
||||
db := database.GetDatabaseFromConfig("config." + profile + ".json")
|
||||
config := config.ReadConfigFromFile("config." + profile + ".json")
|
||||
db := database.GetDatabaseFromConfig(config.DatabaseConfig)
|
||||
|
||||
if len(flag.Args()) == 0 {
|
||||
fmt.Fprintln(os.Stderr, "Please specify a subcommand.")
|
||||
|
|
Loading…
Reference in New Issue