How to get annotation of go language function? Example:
// @annotation1
// @annotation2
func Tags() string {
return ""
}
How to get the "@annotation1" and "@annotation2"?
How to get annotation of go language function? Example:
// @annotation1
// @annotation2
func Tags() string {
return ""
}
How to get the "@annotation1" and "@annotation2"?
Short answer, there is no native support for annotations in Golang. What's being used if tags, which you can get from the reflect
package.
So, you do not have annotations in Go, and to my knowledge there is no library which provides them. Depending of what you want to do, usually tags are more than enough, and you can use the language's power to achieve the desired results.
It should be possible to implement them as you can get the documentation strings, just like PHP does. However, in the big majority of cases it won't be necessary.
EDIT:
In Go, you have access to the documentation of structs, fields, methods, interfaces, functions (godoc isn't magical) through the ast
package. However, it requires parsing the files, there is no function such as type.getDocComments()
as in PHP.
So, an implementation is theoretically possible. However, the kind of annotations you're asking for are simply not part of Golang's philosophy. There are plenty of libraries that extensively use tags, but none use annotations.