Chore: use any rather than interface{} (#74066)
This commit is contained in:
@@ -95,7 +95,7 @@ func CalculateDiff(ctx context.Context, options *Options, baseData, newData *sim
|
||||
}
|
||||
|
||||
// getDiff computes the diff of two dashboard versions.
|
||||
func getDiff(baseData, newData *simplejson.Json) (interface{}, diff.Diff, error) {
|
||||
func getDiff(baseData, newData *simplejson.Json) (any, diff.Diff, error) {
|
||||
leftBytes, err := baseData.Encode()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -115,7 +115,7 @@ func getDiff(baseData, newData *simplejson.Json) (interface{}, diff.Diff, error)
|
||||
return nil, nil, ErrNilDiff
|
||||
}
|
||||
|
||||
left := make(map[string]interface{})
|
||||
left := make(map[string]any)
|
||||
err = json.Unmarshal(leftBytes, &left)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -22,8 +22,8 @@ type BasicDiff struct {
|
||||
// A BasicBlock represents a top-level element in a basic diff.
|
||||
type BasicBlock struct {
|
||||
Title string
|
||||
Old interface{}
|
||||
New interface{}
|
||||
Old any
|
||||
New any
|
||||
Change ChangeType
|
||||
Changes []*BasicChange
|
||||
Summaries []*BasicSummary
|
||||
@@ -35,8 +35,8 @@ type BasicBlock struct {
|
||||
// BasicChanges in a BasicBlock.
|
||||
type BasicChange struct {
|
||||
Key string
|
||||
Old interface{}
|
||||
New interface{}
|
||||
Old any
|
||||
New any
|
||||
Change ChangeType
|
||||
LineStart int
|
||||
LineEnd int
|
||||
@@ -60,7 +60,7 @@ type BasicFormatter struct {
|
||||
tpl *template.Template
|
||||
}
|
||||
|
||||
func NewBasicFormatter(left interface{}) *BasicFormatter {
|
||||
func NewBasicFormatter(left any) *BasicFormatter {
|
||||
tpl := template.Must(template.New("block").Funcs(tplFuncMap).Parse(tplBlock))
|
||||
tpl = template.Must(tpl.New("change").Funcs(tplFuncMap).Parse(tplChange))
|
||||
tpl = template.Must(tpl.New("summary").Funcs(tplFuncMap).Parse(tplSummary))
|
||||
|
||||
@@ -86,17 +86,17 @@ var diffTplFuncs = template.FuncMap{
|
||||
// and contains the data required to produce the tokens output in the basic
|
||||
// diff.
|
||||
type JSONLine struct {
|
||||
LineNum int `json:"line"`
|
||||
LeftLine int `json:"leftLine"`
|
||||
RightLine int `json:"rightLine"`
|
||||
Indent int `json:"indent"`
|
||||
Text string `json:"text"`
|
||||
Change ChangeType `json:"changeType"`
|
||||
Key string `json:"key"`
|
||||
Val interface{} `json:"value"`
|
||||
LineNum int `json:"line"`
|
||||
LeftLine int `json:"leftLine"`
|
||||
RightLine int `json:"rightLine"`
|
||||
Indent int `json:"indent"`
|
||||
Text string `json:"text"`
|
||||
Change ChangeType `json:"changeType"`
|
||||
Key string `json:"key"`
|
||||
Val any `json:"value"`
|
||||
}
|
||||
|
||||
func NewJSONFormatter(left interface{}) *JSONFormatter {
|
||||
func NewJSONFormatter(left any) *JSONFormatter {
|
||||
tpl := template.Must(template.New("JSONDiffWrapper").Funcs(diffTplFuncs).Parse(tplJSONDiffWrapper))
|
||||
tpl = template.Must(tpl.New("JSONDiffLine").Funcs(diffTplFuncs).Parse(tplJSONDiffLine))
|
||||
|
||||
@@ -112,7 +112,7 @@ func NewJSONFormatter(left interface{}) *JSONFormatter {
|
||||
}
|
||||
|
||||
type JSONFormatter struct {
|
||||
left interface{}
|
||||
left any
|
||||
path []string
|
||||
size []int
|
||||
inArray []bool
|
||||
@@ -130,7 +130,7 @@ type AsciiLine struct {
|
||||
|
||||
// the actual changes - no formatting
|
||||
key string
|
||||
val interface{}
|
||||
val any
|
||||
|
||||
// level of indentation for the current line
|
||||
indent int
|
||||
@@ -140,16 +140,16 @@ type AsciiLine struct {
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) Format(diff diff.Diff) (result string, err error) {
|
||||
if v, ok := f.left.(map[string]interface{}); ok {
|
||||
if v, ok := f.left.(map[string]any); ok {
|
||||
if err := f.formatObject(v, diff); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else if v, ok := f.left.([]interface{}); ok {
|
||||
} else if v, ok := f.left.([]any); ok {
|
||||
if err := f.formatArray(v, diff); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
return "", fmt.Errorf("expected map[string]interface{} or []interface{}, got %T",
|
||||
return "", fmt.Errorf("expected map[string]any or []any, got %T",
|
||||
f.left)
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (f *JSONFormatter) Format(diff diff.Diff) (result string, err error) {
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) formatObject(left map[string]interface{}, df diff.Diff) error {
|
||||
func (f *JSONFormatter) formatObject(left map[string]any, df diff.Diff) error {
|
||||
f.addLineWith(ChangeNil, "{")
|
||||
f.push("ROOT", len(left), false)
|
||||
if err := f.processObject(left, df.Deltas()); err != nil {
|
||||
@@ -176,7 +176,7 @@ func (f *JSONFormatter) formatObject(left map[string]interface{}, df diff.Diff)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) formatArray(left []interface{}, df diff.Diff) error {
|
||||
func (f *JSONFormatter) formatArray(left []any, df diff.Diff) error {
|
||||
f.addLineWith(ChangeNil, "[")
|
||||
f.push("ROOT", len(left), true)
|
||||
if err := f.processArray(left, df.Deltas()); err != nil {
|
||||
@@ -189,7 +189,7 @@ func (f *JSONFormatter) formatArray(left []interface{}, df diff.Diff) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) processArray(array []interface{}, deltas []diff.Delta) error {
|
||||
func (f *JSONFormatter) processArray(array []any, deltas []diff.Delta) error {
|
||||
patchedIndex := 0
|
||||
for index, value := range array {
|
||||
if err := f.processItem(value, deltas, diff.Index(index)); err != nil {
|
||||
@@ -214,7 +214,7 @@ func (f *JSONFormatter) processArray(array []interface{}, deltas []diff.Delta) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) processObject(object map[string]interface{}, deltas []diff.Delta) error {
|
||||
func (f *JSONFormatter) processObject(object map[string]any, deltas []diff.Delta) error {
|
||||
names := sortKeys(object)
|
||||
for _, name := range names {
|
||||
value := object[name]
|
||||
@@ -234,7 +234,7 @@ func (f *JSONFormatter) processObject(object map[string]interface{}, deltas []di
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, position diff.Position) error {
|
||||
func (f *JSONFormatter) processItem(value any, deltas []diff.Delta, position diff.Position) error {
|
||||
matchedDeltas := f.searchDeltas(deltas, position)
|
||||
positionStr := position.String()
|
||||
if len(matchedDeltas) > 0 {
|
||||
@@ -242,12 +242,12 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
|
||||
switch matchedDelta := matchedDelta.(type) {
|
||||
case *diff.Object:
|
||||
switch value.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
// ok
|
||||
default:
|
||||
return errors.New("type mismatch")
|
||||
}
|
||||
o := value.(map[string]interface{})
|
||||
o := value.(map[string]any)
|
||||
|
||||
f.newLine(ChangeNil)
|
||||
f.printKey(positionStr)
|
||||
@@ -267,12 +267,12 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
|
||||
|
||||
case *diff.Array:
|
||||
switch value.(type) {
|
||||
case []interface{}:
|
||||
case []any:
|
||||
// ok
|
||||
default:
|
||||
return errors.New("type mismatch")
|
||||
}
|
||||
a := value.([]interface{})
|
||||
a := value.([]any)
|
||||
|
||||
f.newLine(ChangeNil)
|
||||
f.printKey(positionStr)
|
||||
@@ -416,7 +416,7 @@ func (f *JSONFormatter) printComma() {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) printValue(value interface{}) {
|
||||
func (f *JSONFormatter) printValue(value any) {
|
||||
switch value.(type) {
|
||||
case string:
|
||||
f.line.val = value
|
||||
@@ -434,9 +434,9 @@ func (f *JSONFormatter) print(a string) {
|
||||
f.line.buffer.WriteString(a)
|
||||
}
|
||||
|
||||
func (f *JSONFormatter) printRecursive(name string, value interface{}, change ChangeType) {
|
||||
func (f *JSONFormatter) printRecursive(name string, value any, change ChangeType) {
|
||||
switch value := value.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
f.newLine(change)
|
||||
f.printKey(name)
|
||||
f.print("{")
|
||||
@@ -456,7 +456,7 @@ func (f *JSONFormatter) printRecursive(name string, value interface{}, change Ch
|
||||
f.printComma()
|
||||
f.closeLine()
|
||||
|
||||
case []interface{}:
|
||||
case []any:
|
||||
f.newLine(change)
|
||||
f.printKey(name)
|
||||
f.print("[")
|
||||
@@ -483,7 +483,7 @@ func (f *JSONFormatter) printRecursive(name string, value interface{}, change Ch
|
||||
}
|
||||
}
|
||||
|
||||
func sortKeys(m map[string]interface{}) (keys []string) {
|
||||
func sortKeys(m map[string]any) (keys []string) {
|
||||
keys = make([]string, 0, len(m))
|
||||
for key := range m {
|
||||
keys = append(keys, key)
|
||||
|
||||
@@ -188,7 +188,7 @@ func NewStorageClient(account, accessKey string) *StorageClient {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *StorageClient) absUrl(format string, a ...interface{}) string {
|
||||
func (c *StorageClient) absUrl(format string, a ...any) string {
|
||||
part := fmt.Sprintf(format, a...)
|
||||
return fmt.Sprintf("https://%s.blob.core.windows.net/%s", c.Auth.Account, part)
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ type signedURLOptsMatcher struct {
|
||||
opts *storage.SignedURLOptions
|
||||
}
|
||||
|
||||
func (m signedURLOptsMatcher) Matches(x interface{}) bool {
|
||||
func (m signedURLOptsMatcher) Matches(x any) bool {
|
||||
suOpts, ok := x.(*storage.SignedURLOptions)
|
||||
if !ok {
|
||||
return false
|
||||
|
||||
@@ -44,7 +44,7 @@ func (m *MockImageUploader) Upload(arg0 context.Context, arg1 string) (string, e
|
||||
}
|
||||
|
||||
// Upload indicates an expected call of Upload.
|
||||
func (mr *MockImageUploaderMockRecorder) Upload(arg0, arg1 interface{}) *gomock.Call {
|
||||
func (mr *MockImageUploaderMockRecorder) Upload(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Upload", reflect.TypeOf((*MockImageUploader)(nil).Upload), arg0, arg1)
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ var fileDescriptor_7a8976f235a02f79 = []byte{
|
||||
0x10, 0x6d, 0x6a, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (this *PushRequest) Equal(that interface{}) bool {
|
||||
func (this *PushRequest) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return this == nil
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func (this *PushRequest) Equal(that interface{}) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (this *PushResponse) Equal(that interface{}) bool {
|
||||
func (this *PushResponse) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return this == nil
|
||||
}
|
||||
@@ -305,7 +305,7 @@ func (this *PushResponse) Equal(that interface{}) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (this *StreamAdapter) Equal(that interface{}) bool {
|
||||
func (this *StreamAdapter) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return this == nil
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func (this *StreamAdapter) Equal(that interface{}) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (this *EntryAdapter) Equal(that interface{}) bool {
|
||||
func (this *EntryAdapter) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return this == nil
|
||||
}
|
||||
@@ -415,7 +415,7 @@ func (this *EntryAdapter) GoString() string {
|
||||
s = append(s, "}")
|
||||
return strings.Join(s, "")
|
||||
}
|
||||
func valueToGoStringLogproto(v interface{}, typ string) string {
|
||||
func valueToGoStringLogproto(v any, typ string) string {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.IsNil() {
|
||||
return "nil"
|
||||
@@ -473,7 +473,7 @@ func RegisterPusherServer(s *grpc.Server, srv PusherServer) {
|
||||
s.RegisterService(&_Pusher_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Pusher_Push_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _Pusher_Push_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
in := new(PushRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@@ -485,7 +485,7 @@ func _Pusher_Push_Handler(srv interface{}, ctx context.Context, dec func(interfa
|
||||
Server: srv,
|
||||
FullMethod: "/logproto.Pusher/Push",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
return srv.(PusherServer).Push(ctx, req.(*PushRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
@@ -776,7 +776,7 @@ func (this *EntryAdapter) String() string {
|
||||
}, "")
|
||||
return s
|
||||
}
|
||||
func valueToStringLogproto(v interface{}) string {
|
||||
func valueToStringLogproto(v any) string {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.IsNil() {
|
||||
return "nil"
|
||||
|
||||
@@ -405,7 +405,7 @@ func (m *Entry) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *Stream) Equal(that interface{}) bool {
|
||||
func (m *Stream) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return m == nil
|
||||
}
|
||||
@@ -438,7 +438,7 @@ func (m *Stream) Equal(that interface{}) bool {
|
||||
return m.Hash == that1.Hash
|
||||
}
|
||||
|
||||
func (m *Entry) Equal(that interface{}) bool {
|
||||
func (m *Entry) Equal(that any) bool {
|
||||
if that == nil {
|
||||
return m == nil
|
||||
}
|
||||
|
||||
@@ -63,14 +63,14 @@ func FloatFromString(f string, nullString string) (Float, error) {
|
||||
// It also supports unmarshaling a sql.NullFloat64.
|
||||
func (f *Float) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
var v interface{}
|
||||
var v any
|
||||
if err = json.Unmarshal(data, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch x := v.(type) {
|
||||
case float64:
|
||||
f.Float64 = x
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
err = json.Unmarshal(data, &f.NullFloat64)
|
||||
case nil:
|
||||
f.Valid = false
|
||||
|
||||
@@ -20,11 +20,11 @@ func Version() string {
|
||||
}
|
||||
|
||||
type Json struct {
|
||||
data interface{}
|
||||
data any
|
||||
}
|
||||
|
||||
func (j *Json) FromDB(data []byte) error {
|
||||
j.data = make(map[string]interface{})
|
||||
j.data = make(map[string]any)
|
||||
|
||||
dec := json.NewDecoder(bytes.NewBuffer(data))
|
||||
dec.UseNumber()
|
||||
@@ -39,7 +39,7 @@ func (j *Json) ToDB() ([]byte, error) {
|
||||
return j.Encode()
|
||||
}
|
||||
|
||||
func (j *Json) Scan(val interface{}) error {
|
||||
func (j *Json) Scan(val any) error {
|
||||
switch v := val.(type) {
|
||||
case []byte:
|
||||
if len(v) == 0 {
|
||||
@@ -85,17 +85,17 @@ func MustJson(body []byte) *Json {
|
||||
// New returns a pointer to a new, empty `Json` object
|
||||
func New() *Json {
|
||||
return &Json{
|
||||
data: make(map[string]interface{}),
|
||||
data: make(map[string]any),
|
||||
}
|
||||
}
|
||||
|
||||
// NewFromAny returns a pointer to a new `Json` object with provided data.
|
||||
func NewFromAny(data interface{}) *Json {
|
||||
func NewFromAny(data any) *Json {
|
||||
return &Json{data: data}
|
||||
}
|
||||
|
||||
// Interface returns the underlying data
|
||||
func (j *Json) Interface() interface{} {
|
||||
func (j *Json) Interface() any {
|
||||
return j.data
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func (j *Json) MarshalJSON() ([]byte, error) {
|
||||
|
||||
// Set modifies `Json` map by `key` and `value`
|
||||
// Useful for changing single key/value in a `Json` object easily.
|
||||
func (j *Json) Set(key string, val interface{}) {
|
||||
func (j *Json) Set(key string, val any) {
|
||||
m, err := j.Map()
|
||||
if err != nil {
|
||||
return
|
||||
@@ -126,37 +126,37 @@ func (j *Json) Set(key string, val interface{}) {
|
||||
|
||||
// SetPath modifies `Json`, recursively checking/creating map keys for the supplied path,
|
||||
// and then finally writing in the value
|
||||
func (j *Json) SetPath(branch []string, val interface{}) {
|
||||
func (j *Json) SetPath(branch []string, val any) {
|
||||
if len(branch) == 0 {
|
||||
j.data = val
|
||||
return
|
||||
}
|
||||
|
||||
// in order to insert our branch, we need map[string]interface{}
|
||||
if _, ok := (j.data).(map[string]interface{}); !ok {
|
||||
// in order to insert our branch, we need map[string]any
|
||||
if _, ok := (j.data).(map[string]any); !ok {
|
||||
// have to replace with something suitable
|
||||
j.data = make(map[string]interface{})
|
||||
j.data = make(map[string]any)
|
||||
}
|
||||
curr := j.data.(map[string]interface{})
|
||||
curr := j.data.(map[string]any)
|
||||
|
||||
for i := 0; i < len(branch)-1; i++ {
|
||||
b := branch[i]
|
||||
// key exists?
|
||||
if _, ok := curr[b]; !ok {
|
||||
n := make(map[string]interface{})
|
||||
n := make(map[string]any)
|
||||
curr[b] = n
|
||||
curr = n
|
||||
continue
|
||||
}
|
||||
|
||||
// make sure the value is the right sort of thing
|
||||
if _, ok := curr[b].(map[string]interface{}); !ok {
|
||||
if _, ok := curr[b].(map[string]any); !ok {
|
||||
// have to replace with something suitable
|
||||
n := make(map[string]interface{})
|
||||
n := make(map[string]any)
|
||||
curr[b] = n
|
||||
}
|
||||
|
||||
curr = curr[b].(map[string]interface{})
|
||||
curr = curr[b].(map[string]any)
|
||||
}
|
||||
|
||||
// add remaining k/v
|
||||
@@ -238,7 +238,7 @@ func (j *Json) CheckGetIndex(index int) (*Json, bool) {
|
||||
|
||||
// SetIndex modifies `Json` array by `index` and `value`
|
||||
// for `index` in its `array` representation
|
||||
func (j *Json) SetIndex(index int, val interface{}) {
|
||||
func (j *Json) SetIndex(index int, val any) {
|
||||
a, err := j.Array()
|
||||
if err == nil {
|
||||
if len(a) > index {
|
||||
@@ -266,19 +266,19 @@ func (j *Json) CheckGet(key string) (*Json, bool) {
|
||||
}
|
||||
|
||||
// Map type asserts to `map`
|
||||
func (j *Json) Map() (map[string]interface{}, error) {
|
||||
if m, ok := (j.data).(map[string]interface{}); ok {
|
||||
func (j *Json) Map() (map[string]any, error) {
|
||||
if m, ok := (j.data).(map[string]any); ok {
|
||||
return m, nil
|
||||
}
|
||||
return nil, errors.New("type assertion to map[string]interface{} failed")
|
||||
return nil, errors.New("type assertion to map[string]any failed")
|
||||
}
|
||||
|
||||
// Array type asserts to an `array`
|
||||
func (j *Json) Array() ([]interface{}, error) {
|
||||
if a, ok := (j.data).([]interface{}); ok {
|
||||
func (j *Json) Array() ([]any, error) {
|
||||
if a, ok := (j.data).([]any); ok {
|
||||
return a, nil
|
||||
}
|
||||
return nil, errors.New("type assertion to []interface{} failed")
|
||||
return nil, errors.New("type assertion to []any failed")
|
||||
}
|
||||
|
||||
// Bool type asserts to `bool`
|
||||
@@ -326,15 +326,15 @@ func (j *Json) StringArray() ([]string, error) {
|
||||
return retArr, nil
|
||||
}
|
||||
|
||||
// MustArray guarantees the return of a `[]interface{}` (with optional default)
|
||||
// MustArray guarantees the return of a `[]any` (with optional default)
|
||||
//
|
||||
// useful when you want to iterate over array values in a succinct manner:
|
||||
//
|
||||
// for i, v := range js.Get("results").MustArray() {
|
||||
// fmt.Println(i, v)
|
||||
// }
|
||||
func (j *Json) MustArray(args ...[]interface{}) []interface{} {
|
||||
var def []interface{}
|
||||
func (j *Json) MustArray(args ...[]any) []any {
|
||||
var def []any
|
||||
|
||||
switch len(args) {
|
||||
case 0:
|
||||
@@ -352,15 +352,15 @@ func (j *Json) MustArray(args ...[]interface{}) []interface{} {
|
||||
return def
|
||||
}
|
||||
|
||||
// MustMap guarantees the return of a `map[string]interface{}` (with optional default)
|
||||
// MustMap guarantees the return of a `map[string]any` (with optional default)
|
||||
//
|
||||
// useful when you want to iterate over map values in a succinct manner:
|
||||
//
|
||||
// for k, v := range js.Get("dictionary").MustMap() {
|
||||
// fmt.Println(k, v)
|
||||
// }
|
||||
func (j *Json) MustMap(args ...map[string]interface{}) map[string]interface{} {
|
||||
var def map[string]interface{}
|
||||
func (j *Json) MustMap(args ...map[string]any) map[string]any {
|
||||
var def map[string]any
|
||||
|
||||
switch len(args) {
|
||||
case 0:
|
||||
@@ -549,13 +549,13 @@ func (j *Json) MustUint64(args ...uint64) uint64 {
|
||||
}
|
||||
|
||||
// MarshalYAML implements yaml.Marshaller.
|
||||
func (j *Json) MarshalYAML() (interface{}, error) {
|
||||
func (j *Json) MarshalYAML() (any, error) {
|
||||
return j.data, nil
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements yaml.Unmarshaller.
|
||||
func (j *Json) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var data interface{}
|
||||
func (j *Json) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var data any
|
||||
if err := unmarshal(&data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ func TestSimplejson(t *testing.T) {
|
||||
ms2 := js.Get("test").Get("missing_string").MustString("fyea")
|
||||
assert.Equal(t, "fyea", ms2)
|
||||
|
||||
ma2 := js.Get("test").Get("missing_array").MustArray([]interface{}{"1", 2, "3"})
|
||||
assert.Equal(t, ma2, []interface{}{"1", 2, "3"})
|
||||
ma2 := js.Get("test").Get("missing_array").MustArray([]any{"1", 2, "3"})
|
||||
assert.Equal(t, ma2, []any{"1", 2, "3"})
|
||||
|
||||
msa := js.Get("test").Get("string_array").MustStringArray()
|
||||
assert.Equal(t, msa[0], "asdf")
|
||||
@@ -102,8 +102,8 @@ func TestSimplejson(t *testing.T) {
|
||||
msa3 := js.Get("test").Get("missing_array").MustStringArray([]string{"1", "2", "3"})
|
||||
assert.Equal(t, msa3, []string{"1", "2", "3"})
|
||||
|
||||
mm2 := js.Get("test").Get("missing_map").MustMap(map[string]interface{}{"found": false})
|
||||
assert.Equal(t, mm2, map[string]interface{}{"found": false})
|
||||
mm2 := js.Get("test").Get("missing_map").MustMap(map[string]any{"found": false})
|
||||
assert.Equal(t, mm2, map[string]any{"found": false})
|
||||
|
||||
strs, err := js.Get("test").Get("string_array").StringArray()
|
||||
assert.Equal(t, err, nil)
|
||||
@@ -207,7 +207,7 @@ func TestSetPathNoPath(t *testing.T) {
|
||||
f := js.GetPath("some_number").MustFloat64(99.0)
|
||||
assert.Equal(t, f, 1.0)
|
||||
|
||||
js.SetPath([]string{}, map[string]interface{}{"foo": "bar"})
|
||||
js.SetPath([]string{}, map[string]any{"foo": "bar"})
|
||||
|
||||
s, err := js.GetPath("foo").String()
|
||||
assert.Equal(t, nil, err)
|
||||
|
||||
Reference in New Issue
Block a user