(new): rich message support
Golang lint / lint (pull_request) Successful in 1m20s
Golang lint / lint (push) Successful in 4m8s

(fix): runtime reliability
(tests): regression coverage
(doc): v1.1 release notes
This commit is contained in:
2026-08-12 16:34:44 +03:00
parent 48ddf66540
commit f03a081ed6
83 changed files with 6122 additions and 1925 deletions
+15 -2
View File
@@ -127,8 +127,18 @@ func (codec BotOptsFileJSONCodec) Save(filename string, opts *BotOpts) error {
return SaveBotOptsFile(codec, filename, opts)
}
// EscapeEnv escapes an environment value for use inside a JSON string.
func (codec BotOptsFileJSONCodec) EscapeEnv(s string) string {
data, _ := json.Marshal(s)
return string(data[1 : len(data)-1])
}
var envParameterRegex = regexp.MustCompile(`\{\{\s*(\w+)\s*\}\}`)
type botOptsFileEnvEscaper interface {
EscapeEnv(string) string
}
// BotOptsFileCodec decodes and encodes BotOpts file formats.
type BotOptsFileCodec interface {
FromBytes([]byte) (*BotOpts, error)
@@ -148,7 +158,7 @@ func LoadBotOptsFile(codec BotOptsFileCodec, filename string) (*BotOpts, error)
if err != nil {
return nil, err
}
data = expandEnvPlaceholdersInFile(data)
data = expandEnvPlaceholdersInFile(codec, data)
return codec.FromBytes(data)
}
@@ -165,7 +175,7 @@ func SaveBotOptsFile(codec BotOptsFileCodec, filename string, opts *BotOpts) err
return nil
}
func expandEnvPlaceholdersInFile(data []byte) []byte {
func expandEnvPlaceholdersInFile(codec BotOptsFileCodec, data []byte) []byte {
return envParameterRegex.ReplaceAllFunc(data, func(match []byte) []byte {
group := envParameterRegex.FindSubmatch(match)
if len(group) != 2 {
@@ -173,6 +183,9 @@ func expandEnvPlaceholdersInFile(data []byte) []byte {
}
key := group[1]
value := os.Getenv(string(key))
if escaper, ok := codec.(botOptsFileEnvEscaper); ok {
value = escaper.EscapeEnv(value)
}
return []byte(value)
})
}