AppendUnique appends (can reuse array!) fields which does not occur in existing fields slice.
(add Fields)
| 138 | |
| 139 | // AppendUnique appends (can reuse array!) fields which does not occur in existing fields slice. |
| 140 | func (f Fields) AppendUnique(add Fields) Fields { |
| 141 | if len(add) == 0 { |
| 142 | return f |
| 143 | } |
| 144 | |
| 145 | a := add.Iterator() |
| 146 | NextAddField: |
| 147 | for a.Next() { |
| 148 | k, v := a.At() |
| 149 | i := f.Iterator() |
| 150 | for i.Next() { |
| 151 | fk, _ := i.At() |
| 152 | if fk == k { |
| 153 | continue NextAddField |
| 154 | } |
| 155 | } |
| 156 | f = append(f, k, v) |
| 157 | } |
| 158 | return f |
| 159 | } |
| 160 | |
| 161 | // ExtractFields returns logging fields from the context. |
| 162 | // Fields can be added from the context using InjectFields. For example logging interceptor adds some (base) fields |