mirror of
https://github.com/valitydev/thriftlint.git
synced 2024-11-06 00:05:20 +00:00
29 lines
779 B
Go
29 lines
779 B
Go
|
package thriftlint
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
|
||
|
"github.com/alecthomas/go-thrift/parser"
|
||
|
)
|
||
|
|
||
|
// Annotation returns the annotation value associated with "key" from the .Annotations field of a
|
||
|
// go-thrift AST node.
|
||
|
//
|
||
|
// This will panic if node is not a struct with an Annotations field of the correct type.
|
||
|
func Annotation(node interface{}, key, dflt string) string {
|
||
|
annotations := reflect.Indirect(reflect.ValueOf(node)).
|
||
|
FieldByName("Annotations").
|
||
|
Interface().([]*parser.Annotation)
|
||
|
for _, annotation := range annotations {
|
||
|
if annotation.Name == key {
|
||
|
return annotation.Value
|
||
|
}
|
||
|
}
|
||
|
return dflt
|
||
|
}
|
||
|
|
||
|
// AnnotationExists checks if an annotation is present at all.
|
||
|
func AnnotationExists(node interface{}, key string) bool {
|
||
|
return Annotation(node, key, "\000") != "\000"
|
||
|
}
|