代码拉取完成,页面将自动刷新
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] + " "
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)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。