3 Star 21 Fork 9

精进之道系列/Go语言工程精选

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.go 959 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhaopuming 提交于 4年前 . 初步筛选
package main
import (
"bufio"
"fmt"
"net/url"
"os"
"regexp"
"strings"
)
func addBanner(line string) string {
re := regexp.MustCompile("\\[[^\\]]*\\]\\(([^\\)]*)\\)")
matches := re.FindStringSubmatch(line)
if len(matches) > 1 {
u, e := url.Parse(matches[1])
if e != nil {
return line
}
vs := strings.Split(u.Path, "/")
if len(vs) == 3 {
rep := matches[0] + " ![](https://img.shields.io/github/stars/" + vs[1] + "/" + vs[2] + "?style=social)"
rep = re.ReplaceAllString(line, rep)
return rep
} else {
return line
}
} else { // 标题
return line
}
}
func main() {
print("hello")
f, e := os.Open("README.md")
defer f.Close()
if e != nil {
fmt.Println("error open file")
}
buf := bufio.NewScanner(f)
for {
if !buf.Scan() {
break
}
line := buf.Text()
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "*") {
line = addBanner(line)
}
fmt.Printf("%v\n", line)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/learning_path_series/go_oss_collection.git
git@gitee.com:learning_path_series/go_oss_collection.git
learning_path_series
go_oss_collection
Go语言工程精选
master

搜索帮助