github.com/searKing/golang/go@v1.2.117/encoding/internal/tag/condAddrTagFunc.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tag 6 7 import "reflect" 8 9 // If CanAddr then get addr and handle else handle directly 10 type condAddrTagFunc struct { 11 canAddrTagFunc, elseTagFunc tagFunc 12 } 13 14 func (ce *condAddrTagFunc) handle(e *tagState, v reflect.Value, opts tagOpts) (isUserDefined bool) { 15 if v.CanAddr() { 16 return ce.canAddrTagFunc(e, v, opts) 17 } 18 return ce.elseTagFunc(e, v, opts) 19 } 20 21 // newCondAddrConverter returns an encoder that checks whether its structTag 22 // CanAddr and delegates to canAddrTagFunc if so, else to elseTagFunc. 23 func newCondAddrTagFunc(canAddrConvert, elseConvert tagFunc) tagFunc { 24 tagFn := &condAddrTagFunc{canAddrTagFunc: canAddrConvert, elseTagFunc: elseConvert} 25 return tagFn.handle 26 }