accounts/internal/xrayconfig/definition.go
Haitao Pan 07e31ff6bd feat: move account service to repo root
# Conflicts:
#	account/Makefile
#	account/go.mod
#	docs/account-admin-settings.md
#	docs/account-svc-plus.md
2026-01-16 16:15:23 +08:00

29 lines
904 B
Go

package xrayconfig
import "encoding/json"
// Definition describes a base Xray configuration structure that can be rendered
// with runtime client information. Each call to Base should return a fresh copy
// so that callers can safely mutate the returned value without affecting future
// renders.
type Definition interface {
Base() (map[string]interface{}, error)
}
// JSONDefinition implements Definition by decoding a JSON document. A copy of
// the raw payload is kept to ensure Base can be called repeatedly without
// sharing state between renders.
type JSONDefinition struct {
Raw []byte
}
// Base returns a deep copy of the JSON document as a map so the generator can
// inject client credentials.
func (d JSONDefinition) Base() (map[string]interface{}, error) {
var root map[string]interface{}
if err := json.Unmarshal(d.Raw, &root); err != nil {
return nil, err
}
return root, nil
}