feat(extension): pass namespace and pool config

This commit is contained in:
iyear 2024-11-23 14:42:01 +08:00
parent eee2d1c546
commit 20aec50413
2 changed files with 30 additions and 22 deletions

View File

@ -122,14 +122,16 @@ func NewExtensionCmd(em *extensions.Manager, ext extensions.Extension, stdin io.
} }
env := &extbase.Env{ env := &extbase.Env{
Name: ext.Name(), Name: ext.Name(),
AppID: app.AppID, AppID: app.AppID,
AppHash: app.AppHash, AppHash: app.AppHash,
Session: session, Session: session,
DataDir: dataDir, Namespace: viper.GetString(consts.FlagNamespace),
NTP: opts.NTP, DataDir: dataDir,
Proxy: opts.Proxy, NTP: opts.NTP,
Debug: viper.GetBool(consts.FlagDebug), 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 { if err = em.Dispatch(ext, args, env, stdin, stdout, stderr); err != nil {

View File

@ -21,14 +21,16 @@ import (
const EnvKey = "TDL_EXTENSION" const EnvKey = "TDL_EXTENSION"
type Env struct { type Env struct {
Name string `json:"name"` Name string `json:"name"`
AppID int `json:"app_id"` Namespace string `json:"namespace"`
AppHash string `json:"app_hash"` AppID int `json:"app_id"`
Session []byte `json:"session"` AppHash string `json:"app_hash"`
DataDir string `json:"data_dir"` Session []byte `json:"session"`
NTP string `json:"ntp"` DataDir string `json:"data_dir"`
Proxy string `json:"proxy"` NTP string `json:"ntp"`
Debug bool `json:"debug"` Proxy string `json:"proxy"`
Pool int64 `json:"pool"`
Debug bool `json:"debug"`
} }
type Options struct { type Options struct {
@ -50,9 +52,11 @@ type Extension struct {
} }
type Config struct { type Config struct {
DataDir string // data directory for extension Namespace string // tdl namespace
Proxy string // proxy URL DataDir string // data directory for extension
Debug bool // debug mode enabled Proxy string // proxy URL
Pool int64 // pool size
Debug bool // debug mode enabled
} }
func (e *Extension) Name() string { func (e *Extension) Name() string {
@ -136,9 +140,11 @@ func buildExtension(ctx context.Context, o Options) (*Extension, *telegram.Clien
client: client, client: client,
log: o.Logger, log: o.Logger,
config: &Config{ config: &Config{
DataDir: env.DataDir, Namespace: env.Namespace,
Proxy: env.Proxy, DataDir: env.DataDir,
Debug: env.Debug, Proxy: env.Proxy,
Pool: env.Pool,
Debug: env.Debug,
}, },
}, client, nil }, client, nil
} }