(new): expand runtime APIs
Golang lint / lint (push) Successful in 58s
Golang lint / lint (pull_request) Successful in 13m10s

(fix): harden concurrent lifecycle
(tests): add regression coverage
(doc): update v1.2 guidance
This commit is contained in:
2026-08-20 11:08:45 +03:00
parent 29b208eeec
commit 24040fe164
37 changed files with 1129 additions and 157 deletions
+13 -1
View File
@@ -97,6 +97,9 @@ func (codec BotOptsFileJSONCodec) FromBytes(data []byte) (*BotOpts, error) {
// ToBytes encodes BotOpts into JSON file bytes.
func (codec BotOptsFileJSONCodec) ToBytes(opts *BotOpts) ([]byte, error) {
if opts == nil {
return nil, ErrOptsIsNil
}
fileOpts := &BotOptsFileJSON{
Version: ConfigVersion,
Token: opts.Token,
@@ -143,7 +146,7 @@ func (codec BotOptsFileJSONCodec) EscapeEnv(s string) string {
return string(data[1 : len(data)-1])
}
var envParameterRegex = regexp.MustCompile(`\{\{\s*(\w+)\s*\}\}`)
var envParameterRegex = regexp.MustCompile(`\{\{\s*(\w+)\s*}}`)
type botOptsFileEnvEscaper interface {
EscapeEnv(string) string
@@ -159,6 +162,9 @@ type BotOptsFileCodec interface {
// LoadBotOptsFile reads a config file, expands env placeholders, and decodes BotOpts.
func LoadBotOptsFile(codec BotOptsFileCodec, filename string) (*BotOpts, error) {
if isNilValue(codec) {
return nil, ErrCodecIsNil
}
f, err := os.Open(filename)
if err != nil {
return nil, err
@@ -174,6 +180,12 @@ func LoadBotOptsFile(codec BotOptsFileCodec, filename string) (*BotOpts, error)
// SaveBotOptsFile encodes BotOpts with codec and writes the result to filename.
func SaveBotOptsFile(codec BotOptsFileCodec, filename string, opts *BotOpts) error {
if isNilValue(codec) {
return ErrCodecIsNil
}
if opts == nil {
return ErrOptsIsNil
}
data, err := codec.ToBytes(opts)
if err != nil {
return err