(new): expand runtime APIs
(fix): harden concurrent lifecycle (tests): add regression coverage (doc): update v1.2 guidance
This commit is contained in:
+13
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user