github.com/searKing/golang/go@v1.2.117/encoding/internal/tag/tag.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 type tagOpts struct { 10 TagHandler func(val reflect.Value, tag reflect.StructTag) error 11 } 12 13 // Convert wrapper of convertState 14 func Tag(v any, tagHandler func(val reflect.Value, tag reflect.StructTag) error) error { 15 e := newTagState() 16 err := e.handle(v, tagOpts{tagHandler}) 17 if err != nil { 18 return err 19 } 20 21 e.Reset() 22 tagStatePool.Put(e) 23 return nil 24 } 25 26 // Tagger is the interface implemented by types that 27 // can marshal themselves into valid JSON. 28 type Tagger interface { 29 TagDefault() error 30 }