From 20aec50413021cfdbef57326476c1d2b26955cfb Mon Sep 17 00:00:00 2001 From: iyear Date: Sat, 23 Nov 2024 14:42:01 +0800 Subject: [PATCH] feat(extension): pass namespace and pool config --- cmd/extension.go | 18 ++++++++++-------- extension/extension.go | 34 ++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/cmd/extension.go b/cmd/extension.go index bbc1811..febb7a7 100644 --- a/cmd/extension.go +++ b/cmd/extension.go @@ -122,14 +122,16 @@ func NewExtensionCmd(em *extensions.Manager, ext extensions.Extension, stdin io. } env := &extbase.Env{ - Name: ext.Name(), - AppID: app.AppID, - AppHash: app.AppHash, - Session: session, - DataDir: dataDir, - NTP: opts.NTP, - Proxy: opts.Proxy, - Debug: viper.GetBool(consts.FlagDebug), + Name: ext.Name(), + AppID: app.AppID, + AppHash: app.AppHash, + Session: session, + Namespace: viper.GetString(consts.FlagNamespace), + DataDir: dataDir, + NTP: opts.NTP, + Proxy: opts.Proxy, + Pool: viper.GetInt64(consts.FlagPoolSize), + Debug: viper.GetBool(consts.FlagDebug), } if err = em.Dispatch(ext, args, env, stdin, stdout, stderr); err != nil { diff --git a/extension/extension.go b/extension/extension.go index 13e7ac1..8982ffe 100644 --- a/extension/extension.go +++ b/extension/extension.go @@ -21,14 +21,16 @@ import ( const EnvKey = "TDL_EXTENSION" type Env struct { - Name string `json:"name"` - AppID int `json:"app_id"` - AppHash string `json:"app_hash"` - Session []byte `json:"session"` - DataDir string `json:"data_dir"` - NTP string `json:"ntp"` - Proxy string `json:"proxy"` - Debug bool `json:"debug"` + Name string `json:"name"` + Namespace string `json:"namespace"` + AppID int `json:"app_id"` + AppHash string `json:"app_hash"` + Session []byte `json:"session"` + DataDir string `json:"data_dir"` + NTP string `json:"ntp"` + Proxy string `json:"proxy"` + Pool int64 `json:"pool"` + Debug bool `json:"debug"` } type Options struct { @@ -50,9 +52,11 @@ type Extension struct { } type Config struct { - DataDir string // data directory for extension - Proxy string // proxy URL - Debug bool // debug mode enabled + Namespace string // tdl namespace + DataDir string // data directory for extension + Proxy string // proxy URL + Pool int64 // pool size + Debug bool // debug mode enabled } func (e *Extension) Name() string { @@ -136,9 +140,11 @@ func buildExtension(ctx context.Context, o Options) (*Extension, *telegram.Clien client: client, log: o.Logger, config: &Config{ - DataDir: env.DataDir, - Proxy: env.Proxy, - Debug: env.Debug, + Namespace: env.Namespace, + DataDir: env.DataDir, + Proxy: env.Proxy, + Pool: env.Pool, + Debug: env.Debug, }, }, client, nil }