gocloc 代码统计算法

gocloc是一个支持代码统计的golang 包,同时也可以基于cli 运行

参考使用

  • 环境准备
    go.mod
 
module demoapp
go 1.15
require github.com/hhatto/gocloc v0.3.3
  • main.go
package main
import (
    "bytes"
    "fmt"
    "io/ioutil"
    "github.com/hhatto/gocloc"
)
func main() {
    var filename string = "./app.html"
    contents, _ := ioutil.ReadFile(filename)
    locfile := gocloc.AnalyzeReader(filename, gocloc.NewLanguage("HTML", []string{"//", "<!--"}, [][]string{{"<!--", "-->"}}), bytes.NewReader(contents), &gocloc.ClocOptions{})
    fmt.Printf("%v", locfile)
}

app.html

wget -O app.html https://pkgs.alpinelinux.org/packages?name=zcollect2&branch=edge

运行效果

go  run main.go


 

 

说明

gitbase 内部就基于了gocloc进行loc 算法的支持,可以进行代码的统计,当然类似的loc 包还是比较多的,都是不错的选择

参考资料

https://github.com/hhatto/gocloc
https://github.com/AlDanial/cloc
https://github.com/XAMPPRocky/tokei

posted on 2021-01-15 20:20  荣锋亮  阅读(660)  评论(0编辑  收藏  举报

导航