个人笔记

专注互联网

Golang第三方工具

360EntSecGroup-Skylar/goreporter

A Golang tool that does static analysis, unit testing, code review and generate code quality report.

go get -u github.com/360EntSecGroup-Skylar/goreporter

安装之后,为了支持生成图表,需要

sudo apt-get install graphviz

运行

由于360EntSecGroup-Skylar/goreporter 不会自动查找和排除vendor目录,所以这里取巧,将vendor/src做一个软连接到vendor目录

ln -s github.com/qjw/git-notify/vendor/ github.com/qjw/git-notify/vendor/src
# html结果文件在当前目录,可以参数另行指定
./goreporter -p ../src/github.com/qjw/git-notify/ -e ../src/github.com/qjw/git-notify/vendor/ -f html

感觉没有什么比较有价值的东西,生成的报表界面倒是挺好看

stringer

根据一个( unsigned )int的别名生成fmt.Stringer接口的方法

Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface. Given the name of a (signed or unsigned) integer type T that has constants defined, stringer will create a new self-contained Go source file implementing

go get golang.org/x/tools/cmd/stringer

安装完了会编译出一个stringer命令,在$GOPATH/bin

待生成方法的int别名Pill

package painkiller

type Pill int

const (
Placebo Pill = iota
Aspirin
Ibuprofen
Paracetamol
Acetaminophen = Paracetamol
)

运行命令

stringer -type=Pill

结果

// Code generated by "stringer -type=Pill"; DO NOT EDIT.

package painkiller

import "fmt"

const _Pill_name = "PlaceboAspirinIbuprofenParacetamol"

var _Pill_index = [...]uint8{0, 7, 14, 23, 34}

func (i Pill) String() string {
if i < 0 || i >= Pill(len(_Pill_index)-1) {
return fmt.Sprintf("Pill(%d)", i)
}
return _Pill_name[_Pill_index[i]:_Pill_index[i+1]]
}

go-callvis

生成调用图

Purpose of this tool is to provide a visual overview of your program by using the data from call graph and its relations with packages and types. This is especially useful in larger projects where the complexity of the code rises or when you are just simply trying to understand code structure of somebody else.

安装

go get -u github.com/TrueFurby/go-callvis
cd $GOPATH/src/github.com/TrueFurby/go-callvis && make

使用

必须包含main package

go-callvis github.com/qjw/kelly/sample | dot -Tpng -o output.png

生成的png图片可能很大

gometalinter

执行各种静态检查,支持各种第三方的lint tools

Concurrently run Go lint tools and normalise their output

go get -u gopkg.in/alecthomas/gometalinter.v1
gometalinter.v1 --install
gometalinter.v1 --vendor --skip=vendor...

depth

查看依赖树

king@king:~/code/go/src/bb$ depth github.com/qjw/kelly
github.com/qjw/kelly
├ github.com/qjw/kelly/binding
└ gopkg.in/go-playground/validator.v9
└ github.com/go-playground/universal-translator
└ github.com/go-playground/locales
└ github.com/go-playground/locales/currency
├ github.com/qjw/kelly/render
├ github.com/julienschmidt/httprouter
├ github.com/urfave/negroni