github.com/coveo/gotemplate@v2.7.7+incompatible/json/generated_impl.go (about) 1 // This file was automatically generated by genny. 2 // Any changes will be lost if this file is regenerated. 3 // see https://github.com/cheekybits/genny 4 5 package json 6 7 import "github.com/coveo/gotemplate/collections" 8 9 // List implementation of IGenericList for jsonList 10 type List = jsonList 11 type jsonIList = collections.IGenericList 12 type jsonList []interface{} 13 14 func (l jsonList) AsArray() []interface{} { return []interface{}(l) } 15 func (l jsonList) Cap() int { return cap(l) } 16 func (l jsonList) Capacity() int { return cap(l) } 17 func (l jsonList) Clone() jsonIList { return jsonListHelper.Clone(l) } 18 func (l jsonList) Contains(values ...interface{}) bool { 19 return jsonListHelper.Contains(l, values...) 20 } 21 func (l jsonList) Count() int { return len(l) } 22 func (l jsonList) Create(args ...int) jsonIList { return jsonListHelper.CreateList(args...) } 23 func (l jsonList) CreateDict(args ...int) jsonIDict { 24 return jsonListHelper.CreateDictionary(args...) 25 } 26 func (l jsonList) First() interface{} { return jsonListHelper.GetIndexes(l, 0) } 27 func (l jsonList) Get(indexes ...int) interface{} { 28 return jsonListHelper.GetIndexes(l, indexes...) 29 } 30 func (l jsonList) Has(values ...interface{}) bool { return l.Contains(values...) } 31 func (l jsonList) Join(sep interface{}) str { return l.StringArray().Join(sep) } 32 func (l jsonList) Last() interface{} { return jsonListHelper.GetIndexes(l, len(l)-1) } 33 func (l jsonList) Len() int { return len(l) } 34 func (l jsonList) New(args ...interface{}) jsonIList { return jsonListHelper.NewList(args...) } 35 func (l jsonList) Reverse() jsonIList { return jsonListHelper.Reverse(l) } 36 func (l jsonList) StringArray() strArray { return jsonListHelper.GetStringArray(l) } 37 func (l jsonList) Strings() []string { return jsonListHelper.GetStrings(l) } 38 func (l jsonList) TypeName() str { return "Json" } 39 func (l jsonList) Unique() jsonIList { return jsonListHelper.Unique(l) } 40 41 func (l jsonList) GetHelpers() (collections.IDictionaryHelper, collections.IListHelper) { 42 return jsonDictHelper, jsonListHelper 43 } 44 45 func (l jsonList) Append(values ...interface{}) jsonIList { 46 return jsonListHelper.Add(l, false, values...) 47 } 48 49 func (l jsonList) Intersect(values ...interface{}) jsonIList { 50 return jsonListHelper.Intersect(l, values...) 51 } 52 53 func (l jsonList) Pop(indexes ...int) (interface{}, jsonIList) { 54 if len(indexes) == 0 { 55 indexes = []int{len(l) - 1} 56 } 57 return l.Get(indexes...), l.Remove(indexes...) 58 } 59 60 func (l jsonList) Prepend(values ...interface{}) jsonIList { 61 return jsonListHelper.Add(l, true, values...) 62 } 63 64 func (l jsonList) Remove(indexes ...int) jsonIList { 65 return jsonListHelper.Remove(l, indexes...) 66 } 67 68 func (l jsonList) Set(i int, v interface{}) (jsonIList, error) { 69 return jsonListHelper.SetIndex(l, i, v) 70 } 71 72 func (l jsonList) Union(values ...interface{}) jsonIList { 73 return jsonListHelper.Add(l, false, values...).Unique() 74 } 75 76 func (l jsonList) Without(values ...interface{}) jsonIList { 77 return jsonListHelper.Without(l, values...) 78 } 79 80 // Dictionary implementation of IDictionary for jsonDict 81 type Dictionary = jsonDict 82 type jsonIDict = collections.IDictionary 83 type jsonDict map[string]interface{} 84 85 func (d jsonDict) Add(key, v interface{}) jsonIDict { return jsonDictHelper.Add(d, key, v) } 86 func (d jsonDict) AsMap() map[string]interface{} { return (map[string]interface{})(d) } 87 func (d jsonDict) Clone(keys ...interface{}) jsonIDict { return jsonDictHelper.Clone(d, keys) } 88 func (d jsonDict) Count() int { return len(d) } 89 func (d jsonDict) Create(args ...int) jsonIDict { return jsonListHelper.CreateDictionary(args...) } 90 func (d jsonDict) CreateList(args ...int) jsonIList { return jsonHelper.CreateList(args...) } 91 func (d jsonDict) Flush(keys ...interface{}) jsonIDict { return jsonDictHelper.Flush(d, keys) } 92 func (d jsonDict) Get(keys ...interface{}) interface{} { return jsonDictHelper.Get(d, keys) } 93 func (d jsonDict) GetKeys() jsonIList { return jsonDictHelper.GetKeys(d) } 94 func (d jsonDict) GetValues() jsonIList { return jsonDictHelper.GetValues(d) } 95 func (d jsonDict) Has(keys ...interface{}) bool { return jsonDictHelper.Has(d, keys) } 96 func (d jsonDict) KeysAsString() strArray { return jsonDictHelper.KeysAsString(d) } 97 func (d jsonDict) Len() int { return len(d) } 98 func (d jsonDict) Native() interface{} { return collections.ToNativeRepresentation(d) } 99 func (d jsonDict) Pop(keys ...interface{}) interface{} { return jsonDictHelper.Pop(d, keys) } 100 func (d jsonDict) Set(key, v interface{}) jsonIDict { return jsonDictHelper.Set(d, key, v) } 101 func (d jsonDict) Transpose() jsonIDict { return jsonDictHelper.Transpose(d) } 102 func (d jsonDict) TypeName() str { return "Json" } 103 104 func (d jsonDict) GetHelpers() (collections.IDictionaryHelper, collections.IListHelper) { 105 return jsonDictHelper, jsonListHelper 106 } 107 108 func (d jsonDict) Default(key, defVal interface{}) interface{} { 109 return jsonDictHelper.Default(d, key, defVal) 110 } 111 112 func (d jsonDict) Delete(key interface{}, otherKeys ...interface{}) (jsonIDict, error) { 113 return jsonDictHelper.Delete(d, append([]interface{}{key}, otherKeys...)) 114 } 115 116 func (d jsonDict) Merge(dict jsonIDict, otherDicts ...jsonIDict) jsonIDict { 117 return jsonDictHelper.Merge(d, append([]jsonIDict{dict}, otherDicts...)) 118 } 119 120 func (d jsonDict) Omit(key interface{}, otherKeys ...interface{}) jsonIDict { 121 return jsonDictHelper.Omit(d, append([]interface{}{key}, otherKeys...)) 122 } 123 124 // Generic helpers to simplify physical implementation 125 func jsonListConvert(list jsonIList) jsonIList { return jsonList(list.AsArray()) } 126 func jsonDictConvert(dict jsonIDict) jsonIDict { return jsonDict(dict.AsMap()) } 127 func needConversion(object interface{}, strict bool) bool { 128 return needConversionImpl(object, strict, "Json") 129 } 130 131 var jsonHelper = helperBase{ConvertList: jsonListConvert, ConvertDict: jsonDictConvert, NeedConversion: needConversion} 132 var jsonListHelper = helperList{BaseHelper: jsonHelper} 133 var jsonDictHelper = helperDict{BaseHelper: jsonHelper} 134 135 // DictionaryHelper gives public access to the basic dictionary functions 136 var DictionaryHelper collections.IDictionaryHelper = jsonDictHelper 137 138 // GenericListHelper gives public access to the basic list functions 139 var GenericListHelper collections.IListHelper = jsonListHelper 140 141 type ( 142 str = collections.String 143 strArray = collections.StringArray 144 ) 145 146 var iif = collections.IIf