go: github.com/shurcooL/go/analysis Index | Examples | Files

package analysis

import "github.com/shurcooL/go/analysis"

Package analysis provides a routine that determines if a file is generated or handcrafted.

It's intended to stay up to date with the proposed format specification in https://github.com/golang/go/issues/13560.

Index

Examples

Package Files

generated_detection.go

func IsFileGenerated Uses

func IsFileGenerated(rootDir, name string) (bool, error)

IsFileGenerated returns true if the specified file is generated, or false if it's handcrafted. rootDir is the filepath of root directory, but name is a '/'-separated path to file.

Code:

cwd, err := os.Getwd()
if err != nil {
    panic(err)
}

fmt.Println(analysis.IsFileGenerated(cwd, "testdata/generated_0.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_0.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "testdata/handcrafted_1.go.txt"))
fmt.Println(analysis.IsFileGenerated(cwd, "vendor/github.com/shurcooL/go/analysis/file.go"))
fmt.Println(analysis.IsFileGenerated(cwd, "subpkg/vendor/math/math.go"))

Output:

true <nil>
false <nil>
false <nil>
true <nil>
true <nil>

Package analysis imports 5 packages (graph) and is imported by 1 packages. Updated 2016-07-21. Refresh now. Tools for package owners.