1 Star 0 Fork 54

LEE0771 / foot

forked from aoe5188 / foot 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
FG001.go 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"bufio"
"fmt"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"io"
"log"
"tesou.io/platform/foot-parent/foot-api/common/base"
"tesou.io/platform/foot-parent/foot-core/common/utils"
"os"
"strings"
"tesou.io/platform/foot-parent/foot-core/launch"
launch2 "tesou.io/platform/foot-parent/foot-spider/launch"
"time"
)
func init() {
}
func main() {
//buildWinForm()
test()
}
func buildWinForm() {
var inTE *walk.TextEdit
window := MainWindow{
Title: "FOOT000GUI",
MinSize: Size{400, 300},
Layout: VBox{},
Children: []Widget{
TextEdit{AssignTo: &inTE, ReadOnly: true, HScroll: false, VScroll: true},
HSplitter{
Children: []Widget{
PushButton{
Text: "Spider数据",
OnClicked: func() {
inTE.SetText("Spider数据...\r\n")
go launch2.Spider()
go showConsole(inTE)
},
},
PushButton{
Text: "分析数据",
OnClicked: func() {
inTE.SetText("分析数据...\r\n")
go launch.Analy(false)
go showConsole(inTE)
},
},
PushButton{
Text: "清理数据库",
OnClicked: func() {
inTE.SetText("清理数据库...\r\n")
go showConsole(inTE)
},
},
PushButton{
Text: "清空日志",
OnClicked: func() {
inTE.SetText("清空日志...\r\n")
logFile, err := os.OpenFile(base.output_Path, os.O_WRONLY|os.O_TRUNC, 0777)
if err != nil {
log.Fatal(err)
}
logFile.WriteString("")
defer logFile.Close()
},
},
},
},
},
}
window.Run()
}
func showConsole(edit *walk.TextEdit) {
utils.FileMonitoring(base.output_Path, func(bytes []byte) {
str := string(bytes)
if strings.TrimSpace(str) == "" {
return
}
str = str + "\r\n"
edit.AppendText(str)
})
}
func test() {
logFile, err := os.OpenFile(base.output_Path, os.O_RDONLY, 0777)
if err != nil {
log.Fatal(err)
}
reader := bufio.NewReader(logFile)
for {
var i int
i += 1
var str string
line, _, err := reader.ReadLine()
if err == io.EOF {
time.Sleep(200)
} else if nil != err {
str = "发生错误:" + err.Error()
} else {
str = string(line)
}
if strings.TrimSpace(str) == "" {
continue
}
fmt.Println(str)
}
}
Go
1
https://gitee.com/lee0771/foot.git
git@gitee.com:lee0771/foot.git
lee0771
foot
foot
master

搜索帮助