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


gocloc 代码统计算法

 

 

说明

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

参考资料

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

相关文章:

  • 2021-06-30
  • 2021-06-12
  • 2022-12-23
  • 2021-04-20
  • 2021-06-14
  • 2021-11-18
猜你喜欢
  • 2021-04-09
  • 2021-10-11
  • 2022-02-17
  • 2021-05-18
  • 2022-12-23
相关资源
相似解决方案