44 "encoding/json"
55 "encoding/xml"
66 "errors"
7+ "fmt"
78 "net/url"
89 "sort"
910 "strings"
@@ -21,17 +22,16 @@ type String string
2122// ErrNilMap ...
2223var ErrNilMap = errors .New ("nil map" )
2324
24- func init () {
25- //structs.DefaultTagName = "map"
26- }
27-
2825//String String
2926func (s String ) String () string {
3027 return string (s )
3128}
3229
33- //ToString ToString
34- func ToString (s string ) String {
30+ // ToString ...
31+ // @Description:
32+ // @param string
33+ // @return fmt.Stringer
34+ func ToString (s string ) fmt.Stringer {
3535 return String (s )
3636}
3737
@@ -85,11 +85,27 @@ func Merge(maps ...Map) Map {
8585 return target
8686}
8787
88- //Set set interface
88+ // Set ...
89+ // @Description: set interface
90+ // @receiver Map
91+ // @param string
92+ // @param interface{}
93+ // @return Map
8994func (m Map ) Set (key string , v interface {}) Map {
9095 return m .SetPath (strings .Split (key , "." ), v )
9196}
9297
98+ // AppendArray ...
99+ // @Description: append array interface to key
100+ // @receiver Map
101+ // @param string
102+ // @param ...interface{}
103+ // @return Map
104+ func (m Map ) AppendArray (key string , v ... interface {}) Map {
105+ source := m .GetArray (key )
106+ return m .Set (key , append (source , v ... ))
107+ }
108+
93109// SetPath is the same as SetPath, but allows you to provide comment
94110// information to the key, that will be reused by Marshal().
95111func (m Map ) SetPath (keys []string , v interface {}) Map {
@@ -140,7 +156,11 @@ func (m Map) ReplaceFromMap(s string, v Map) Map {
140156 return m
141157}
142158
143- //Get get interface from map with out default
159+ // Get ...
160+ // @Description: get interface from map without default
161+ // @receiver Map
162+ // @param string
163+ // @return interface{}
144164func (m Map ) Get (s string ) interface {} {
145165 if s == "" {
146166 return nil
@@ -151,7 +171,12 @@ func (m Map) Get(s string) interface{} {
151171 return nil
152172}
153173
154- //GetD get interface from map with default
174+ // GetD ...
175+ // @Description: get interface from map with default
176+ // @receiver Map
177+ // @param string
178+ // @param interface{}
179+ // @return interface{}
155180func (m Map ) GetD (s string , d interface {}) interface {} {
156181 if s == "" {
157182 return nil
@@ -162,12 +187,21 @@ func (m Map) GetD(s string, d interface{}) interface{} {
162187 return d
163188}
164189
165- //GetMap get map from map with out default
190+ // GetMap ...
191+ // @Description: get map from map without default
192+ // @receiver Map
193+ // @param string
194+ // @return Map
166195func (m Map ) GetMap (s string ) Map {
167196 return m .GetMapD (s , nil )
168197}
169198
170- //GetMapD get map from map with default
199+ // GetMapD ...
200+ // @Description: get map from map with default
201+ // @receiver Map
202+ // @param string
203+ // @param Map
204+ // @return Map
171205func (m Map ) GetMapD (s string , d Map ) Map {
172206 switch v := m .Get (s ).(type ) {
173207 case map [string ]interface {}:
@@ -185,7 +219,12 @@ func (m Map) GetMapArray(s string) []Map {
185219
186220}
187221
188- //GetMapArrayD get map from map with default
222+ // GetMapArrayD ...
223+ // @Description: get gomap from gomap with default
224+ // @receiver Map
225+ // @param string
226+ // @param []Map
227+ // @return []Map
189228func (m Map ) GetMapArrayD (s string , d []Map ) []Map {
190229 switch v := m .Get (s ).(type ) {
191230 case []Map :
@@ -201,13 +240,22 @@ func (m Map) GetMapArrayD(s string, d []Map) []Map {
201240 return d
202241}
203242
204- // GetArray get []interface value with out default
243+ // GetArray ...
244+ // @Description: get []interface value without default
245+ // @receiver Map
246+ // @param string
247+ // @return []interface{}
205248func (m Map ) GetArray (s string ) []interface {} {
206249 return m .GetArrayD (s , nil )
207250
208251}
209252
210- // GetArrayD get []interface value with default
253+ // GetArrayD ...
254+ // @Description: get []interface value with default
255+ // @receiver Map
256+ // @param string
257+ // @param []interface{}
258+ // @return []interface{}
211259func (m Map ) GetArrayD (s string , d []interface {}) []interface {} {
212260 switch v := m .Get (s ).(type ) {
213261 case []interface {}:
@@ -217,25 +265,44 @@ func (m Map) GetArrayD(s string, d []interface{}) []interface{} {
217265 return d
218266}
219267
220- //GetBool get bool from map with out default
268+ // GetBool ...
269+ // @Description: get bool from map with out default
270+ // @receiver Map
271+ // @param string
272+ // @return bool
221273func (m Map ) GetBool (s string ) bool {
222274 return m .GetBoolD (s , false )
223275}
224276
225- //GetBoolD get bool from map with default
277+ // GetBoolD ...
278+ // @Description: get bool from map with default
279+ // @receiver Map
280+ // @param string
281+ // @param bool
282+ // @return bool
226283func (m Map ) GetBoolD (s string , b bool ) bool {
227284 if v , b := m .Get (s ).(bool ); b {
228285 return v
229286 }
230287 return b
231288}
232289
233- //GetNumber get float64 from map with out default
290+ // GetNumber ...
291+ // @Description: get float64 from map with out default
292+ // @receiver Map
293+ // @param string
294+ // @return float64
295+ // @return bool
234296func (m Map ) GetNumber (s string ) (float64 , bool ) {
235297 return ParseNumber (m .Get (s ))
236298}
237299
238- //GetNumberD get float64 from map with default
300+ // GetNumberD ...
301+ // @Description: get float64 from map with default
302+ // @receiver Map
303+ // @param string
304+ // @param float64
305+ // @return float64
239306func (m Map ) GetNumberD (s string , d float64 ) float64 {
240307 n , b := ParseNumber (m .Get (s ))
241308 if b {
@@ -244,12 +311,22 @@ func (m Map) GetNumberD(s string, d float64) float64 {
244311 return d
245312}
246313
247- //GetInt64 get int64 from map with out default
314+ // GetInt64 ...
315+ // @Description: get int64 from map with out default
316+ // @receiver Map
317+ // @param string
318+ // @return int64
319+ // @return bool
248320func (m Map ) GetInt64 (s string ) (int64 , bool ) {
249321 return ParseInt (m .Get (s ))
250322}
251323
252- //GetInt64D get int64 from map with default
324+ // GetInt64D ...
325+ // @Description: get int64 from map with default
326+ // @receiver Map
327+ // @param string
328+ // @param int64
329+ // @return int64
253330func (m Map ) GetInt64D (s string , d int64 ) int64 {
254331 i , b := ParseInt (m .Get (s ))
255332 if b {
@@ -258,47 +335,78 @@ func (m Map) GetInt64D(s string, d int64) int64 {
258335 return d
259336}
260337
261- //GetString get string from map with out default
338+ // GetString ...
339+ // @Description: get string from map with out default
340+ // @receiver Map
341+ // @param string
342+ // @return string
262343func (m Map ) GetString (s string ) string {
263344 return m .GetStringD (s , "" )
264345}
265346
266- //GetStringD get string from map with default
347+ // GetStringD ...
348+ // @Description: get string from map with default
349+ // @receiver Map
350+ // @param string
351+ // @param string
352+ // @return string
267353func (m Map ) GetStringD (s string , d string ) string {
268354 if v , b := m .Get (s ).(string ); b {
269355 return v
270356 }
271357 return d
272358}
273359
274- //GetStringArray get string from map with out default
360+ // GetStringArray ...
361+ // @Description: get string from map without default
362+ // @receiver Map
363+ // @param string
364+ // @return []string
275365func (m Map ) GetStringArray (s string ) []string {
276366 return m .GetStringArrayD (s , []string {})
277367}
278368
279- //GetStringD get string from map with default
369+ // GetStringArrayD ...
370+ // @Description: get string from map with default
371+ // @receiver Map
372+ // @param string
373+ // @param []string
374+ // @return []string
280375func (m Map ) GetStringArrayD (s string , d []string ) []string {
281376 if v , b := m .Get (s ).([]string ); b {
282377 return v
283378 }
284379 return d
285380}
286381
287- //GetBytes get bytes from map with default
382+ // GetBytes ...
383+ // @Description: get bytes from map with default
384+ // @receiver Map
385+ // @param string
386+ // @return []byte
288387func (m Map ) GetBytes (s string ) []byte {
289388 return m .GetBytesD (s , nil )
290389
291390}
292391
293- //GetBytesD get bytes from map with default
392+ // GetBytesD ...
393+ // @Description: get bytes from map with default
394+ // @receiver Map
395+ // @param string
396+ // @param []byte
397+ // @return []byte
294398func (m Map ) GetBytesD (s string , d []byte ) []byte {
295399 if v , b := m .Get (s ).([]byte ); b {
296400 return v
297401 }
298402 return d
299403}
300404
301- //Delete delete key value if key is exist
405+ // Delete ...
406+ // @Description: delete key value if key is exist
407+ // @receiver Map
408+ // @param string
409+ // @return bool
302410func (m Map ) Delete (key string ) bool {
303411 if key == "" {
304412 return false
0 commit comments