Skip to content

Commit

Permalink
feat(extension): pass namespace and pool config
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 23, 2024
1 parent eee2d1c commit 20aec50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
18 changes: 10 additions & 8 deletions cmd/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 20 additions & 14 deletions extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 20aec50

Please sign in to comment.