-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
48 lines (48 loc) · 2.24 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package annotation is used to parse and check java style annotation (e.x @SomeAnnotation(param="value"))
//
// The package can only be used for string that only contain the annotation, it can not find the annotation in an arbitrary string.
//
// Usage
// annotationString := `@Annotation(
// stringParam='String Value',
// someInt=2,
// someBool=true,
// someFloat=2.5
// )`
// ann, _ := annotation.Parse(annotationString)
// fmt.Printf("Annotation Name: %s\n", ann.Name) // Annotation Name: Annotation
// fmt.Printf("Annotation stringParam = %s\n", ann.Get("stringParam").String()) // Annotation stringParam = String Value
// fmt.Printf("Annotation someInt = %d\n", ann.Get("someInt").Int()) // Annotation someInt = 2
// fmt.Printf("Annotation someBool = %t\n", ann.Get("someBool").Bool()) // Annotation someBool = true
// fmt.Printf("Annotation someFloat = %.4f\n", ann.Get("someFloat").Float()) // Annotation someInt = 2.5000
//
// You can check the annotation using definitions
//
// annotationString := `@Annotation(
// stringParam='String Value',
// someInt=2,
// someBool=true,
// someFloat=2.5
// )`
// ann, _ := annotation.Parse(annotationString)
// stringParam := annotation.NewParameterDefinition("stringParam", true, annotation.STRING)
// someInt := annotation.NewParameterDefinition("someInt", true, annotation.INT)
// someBool := annotation.NewParameterDefinition("someBool", true, annotation.BOOL)
// someFloat := annotation.NewParameterDefinition("someFloat", true, annotation.FLOAT)
// definition := annotation.NewDefinition(
// "Annotation",
// false,
// stringParam,
// someInt,
// someBool,
// someFloat,
// )
// err := definition.Check(*ann)
//
// fmt.Println(err) // <nil>
//
// annotationMissingParam := "@Annotation(someInt=2, someBool=true, someFloat=2.5)"
// annWrong, _ := annotation.Parse(annotationMissingParam)
// err = definition.Check(*annWrong)
// fmt.Println(err) // the `stringParam` parameter is required for @Annotation() Annotation
package annotation