diff --git a/codes.go b/codes.go index 03aa37f..e660f4a 100644 --- a/codes.go +++ b/codes.go @@ -3,6 +3,7 @@ package tdx import ( "errors" "github.com/injoyai/conv" + "github.com/injoyai/ios/client" "github.com/injoyai/logs" "github.com/injoyai/tdx/protocol" "github.com/robfig/cron/v3" @@ -17,7 +18,17 @@ import ( // DefaultCodes 增加单例,部分数据需要通过Codes里面的信息计算 var DefaultCodes *Codes -func NewCodes(c *Client, filename string) (*Codes, error) { +func DialCodes(filename string, op ...client.Option) (*Codes, error) { + c, err := DialDefault(op...) + if err != nil { + return nil, err + } + return NewCodes(c, filename) +} + +func NewCodes(c *Client, filenames ...string) (*Codes, error) { + + filename := conv.DefaultString("./codes.db", filenames...) //如果文件夹不存在就创建 dir, _ := filepath.Split(filename) diff --git a/example/GetQuote/main.go b/example/GetQuote/main.go index 15986eb..4239189 100644 --- a/example/GetQuote/main.go +++ b/example/GetQuote/main.go @@ -10,6 +10,9 @@ func main() { c, err := tdx.Dial("124.71.187.122:7709", tdx.WithDebug()) logs.PanicErr(err) + tdx.DefaultCodes, err = tdx.NewCodes(c, "./codes.db") + logs.PanicErr(err) + _ = c /*