From 4ce4adbfea04395a20c934fcea9a4a63755d4105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E7=BA=AF=E5=87=80?= <1113655791@qq.com> Date: Wed, 9 Apr 2025 23:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9B=98=E5=8F=A3=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=BE=97=E5=88=9D=E5=A7=8B=E5=8C=96DefaultCodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes.go | 13 ++++++++++++- example/GetQuote/main.go | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 /*