1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
- package tick
- // 本文件实现配置文件的管理
- import (
- "encoding/json"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- )
- type GeneralItemConf struct {
- Run bool
- Download bool
- }
- type TickServerConf struct {
- DBConf
- DsMap map[string]*GeneralItemConf // 数据源配置
- Url string // 数据源地址
- UrlSSL string
- FileServerAddr string
- DataDir string // 数据保存地址
- InssFile string // 合约列表文件
- RpcAddr string // Rpc 监听地址 ":19528"
- StreamAddr string // 行情订阅地址 ":19529"
- }
- func WriteTSConf(fname string, conf *TickServerConf) error {
- b, err := json.MarshalIndent(conf, "", " ")
- if err != nil {
- return err
- }
- ioutil.WriteFile(fname, b, os.ModePerm)
- return nil
- }
- func ReadTSConf(fname string) (*TickServerConf, error) {
- f, err := os.Open(fname)
- if err != nil {
- return nil, err
- }
- defer f.Close()
- dec := json.NewDecoder(f)
- conf := &TickServerConf{}
- err = dec.Decode(conf)
- if err != nil {
- return nil, err
- }
- return conf, nil
- }
- var DefaultTickServerConf = makeDefaultTickServerConf()
- func makeDefaultTickServerConf() *TickServerConf {
- dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
- if err != nil {
- log.Fatal(err)
- }
- dataDir := filepath.Join(dir, "fzmnew")
- lmaxConf := &GeneralItemConf{
- Run: true,
- }
- sinaConf := &GeneralItemConf{
- Run: true,
- }
- dzhConf := &GeneralItemConf{
- Run: true,
- }
- m := map[string]*GeneralItemConf{
- Lmax: lmaxConf,
- Sina: sinaConf,
- Dzh: dzhConf,
- }
- dbConf := DBConf{
- DBDriver: "sqlite3", // mysql
- DSN: "", // root:fzm@1001@/fzmdb?charset=utf8"
- DBName: "fzmnewdb", //
- }
- return &TickServerConf{
- DBConf: dbConf,
- DsMap: m,
- Url: "http://127.0.0.1:2107/",
- UrlSSL: "https://127.0.0.1:443/",
- FileServerAddr: "localhost:8080",
- DataDir: dataDir,
- InssFile: "fzmnewinss.json",
- RpcAddr: ":19528",
- StreamAddr: ":19529",
- }
- }
|