comment

package module
v0.0.0-...-0ca9786 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2016 License: MIT Imports: 4 Imported by: 1

README

Orivil comment component

Install

go get -v gopkg.in/orivil/comment.v0

Test

cd $GOPATH/src/gopkg.in/orivil/comment.v0

go test example_test.go

Usage

see example_test.go

Contributors

https://github.com/orivil/comment/graphs/contributors

License

Released under the MIT License.

Documentation

Overview

Package comment provide one method for read the comments which in struct, method and function.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDirComment

func GetDirComment(filter func(f os.FileInfo) bool, dirs ...string) (sc StructComment, mc MethodComment, fc FuncComment, e error)
Example
package main

import (
	"fmt"
	"gopkg.in/orivil/comment.v0"
	"log"
	"os"
)

// controller comment
type controller struct {
}

// @route {get}/
func (c *controller) index() {

}

// add two parameters
func add(a, b int) int {
	return a + b
}

func main() {
	fileFilter := func(f os.FileInfo) bool {
		// match all file
		return true
	}

	structComment, methodComment, functionComment, err := comment.GetDirComment(fileFilter, "./")
	if err != nil {
		log.Fatal(err)
	}

	// get struct comment
	fmt.Println(structComment["comment_test.controller"] == "controller comment\n")

	// get method comment
	fmt.Println(methodComment["comment_test.controller"]["index"] == "@route {get}/\n")

	// get function comment
	fmt.Println(functionComment["comment_test.add"] == "add two parameters\n")

}
Output:

true
true
true

Types

type FuncComment

type FuncComment map[string]string // {package.func: comment}

type MethodComment

type MethodComment map[string]map[string]string // {package.struct: {methodName: comment}}

type StructComment

type StructComment map[string]string // {package.struct: comment}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL