Golang go/ast.CommentGroup type examples

package go/ast

A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.

Golang go/ast.CommentGroup type usage examples

Example 1:

  func NodeDescription(n ast.Node) string {
 switch n := n.(type) {
 case *ast.ArrayType:
 return "array type"
 case *ast.AssignStmt:
 return "assignment"
 case *ast.CommentGroup:
 return "comment group"
 ...
  }

Example 2:

 func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpath string) error {
 if comments != nil && comments.List != nil {  // <-- here
 for _, c := range comments.List {
 t := strings.TrimSpace(strings.TrimLeft(c.Text, "//"))
 if strings.HasPrefix(t, "@badrouting") {
 .....

Reference :

http://golang.org/pkg/go/ast/#CommentGroup

Advertisement