代码拉取完成,页面将自动刷新
//++++++++++++++++++++++++++++++++++++++++
// 《Go Web编程实战派从入门到精通》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 仓库地址:https://gitee.com/shirdonl/goWebActualCombat
// 仓库地址:https://github.com/shirdonl/goWebActualCombat
//++++++++++++++++++++++++++++++++++++++++
package main
import (
"bufio"
"io"
"os"
"strings"
)
func main() {
f, err := os.Open("index.html")
buf := bufio.NewReader(f)
var rep = []string{"<meta name=\"testkey\" content=\"", arg1, "\" /> "}
var result = ""
for {
a, _, c := buf.ReadLine()
if c == io.EOF {
break
}
if strings.Contains(string(a), "baidu-site-verification") {
result += strings.Join(rep, "") + "\n"
} else {
result += string(a) + "\n"
}
}
fw, err := os.OpenFile("index.html", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) //os.O_TRUNC清空文件重新写入,否则原文件内容可能残留
w := bufio.NewWriter(fw)
w.WriteString(result)
if err != nil {
panic(err)
}
w.Flush()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。