Golang go/ast.CommentGroup.Text() function examples
package go/ast
Text returns the text of the comment. Comment markers (//, /*, and */), the first space of a line comment, and leading and trailing empty lines are removed. Multiple empty lines are reduced to one, and trailing space on lines is trimmed. Unless the result is empty, it is newline-terminated.
Golang go/ast.CommentGroup.Text() function usage example
Example 1:
func saveConfig(pkg *build.Package, filename string, cg *ast.CommentGroup) error {
text := cg.Text() // <-- here
for _, line := range strings.Split(text, "\n") {
orig := line
....
}
Example 2:
func importComment(s ast.Spec) string {
c := s.(*ast.ImportSpec).Comment
if c == nil {
return ""
}
return c.Text()
}
Reference :
Advertisement
Something interesting
Tutorials
+8.1k Golang : HTTP Server Example
+7.9k Golang : Grayscale Image
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+12.5k Golang : Forwarding a local port to a remote server example
+6.6k Golang : How to validate ISBN?
+5.4k Golang : Reclaim memory occupied by make() example
+12.4k Golang : Search and extract certain XML data example
+5k Google : Block or disable caching of your website content
+12.1k Golang : Sort and reverse sort a slice of runes
+8.2k Golang : Get final or effective URL with Request.URL example
+9.4k Golang : Create unique title slugs example