1 Star 0 Fork 3

源码大数据(codebigdata)/goWebActualCombat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
modify_file.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 5年前 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《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()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/codebigdata/goWebActualCombat.git
git@gitee.com:codebigdata/goWebActualCombat.git
codebigdata
goWebActualCombat
goWebActualCombat
b84124f40e18

搜索帮助