package conf

import (
	"gopkg.in/yaml.v2"
	"os"
)

var DbConfig *EnvConfig

type EnvConfig struct {
	Finr                   int    `yaml:"finr"`
	Mongdbname             string `yaml:"mongdbname"`
	Mongdbip               string `yaml:"mongdbip"`
	Mongdbport             string `yaml:"mongdbport"`
	Masterdbserver         string `yaml:"masterdbserver"`
	Masterdbdrivername     string `yaml:"masterdbdrivername"`
	Masterdbuser           string `yaml:"masterdbuser"`
	Masterdbpassword       string `yaml:"masterdbpassword"`
	Masterdbname           string `yaml:"masterdbname"`
	Masterdbport           int    `yaml:"masterdbport"`
	TemplatePath           string `yaml:"templatepath"`
	ReadTaskInterval       int    `yaml:"readtaskinterval"`
	PrinterType            string `yaml:"printertype"`
	Inbox                  string `yaml:"inbox"`
	Outbox                 string `yaml:"outbox"`
	AndonTouchOff          string `yaml:"andontouchoff"`
	PortalGetTimeUrl       string `yaml:"portalgettimeurl"`
	PortalPostFileUrl      string `yaml:"portalpostfileurl"`
	PortalCachePostFileUrl string `yaml:"portalcachepostfileurl"`
	PortalHost             string `yaml:"portalhost"`
	Proxy                  string `yaml:"proxy"`
}

//read yaml config
//注：path为yaml或yml文件的路径
func ReadYamlConfig(path string) error {
	DbConfig = &EnvConfig{}
	f, err := os.Open(path)

	if err != nil {
		return err
	} else {
		yaml.NewDecoder(f).Decode(DbConfig)
	}
	defer f.Close()

	return nil
}
