You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.3 KiB
104 lines
2.3 KiB
package main
|
|
|
|
import (
|
|
"aufs/config"
|
|
"aufs/core"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// 启动web服务
|
|
func startWeb() {
|
|
//创建一个文件服务器,会去www目录下找index.html
|
|
fileServer := http.FileServer(http.Dir("./www"))
|
|
// 将 "/" 路径映射到文件服务器
|
|
http.Handle("/", fileServer)
|
|
//扫描指定的目录
|
|
http.HandleFunc("/sc", core.SerInfo)
|
|
// 数据库基础信息
|
|
http.HandleFunc("/bs", core.BfsInfo)
|
|
// 硬件信息
|
|
http.HandleFunc("/hd", core.Hdinfo)
|
|
|
|
// sse 推送
|
|
http.HandleFunc("/sse", core.SseHandler)
|
|
// 文件接收
|
|
// http.HandleFunc("/rc", core.ReceiveHandler)
|
|
// 发送zip文件
|
|
// http.HandleFunc("/sendZip", core.SendZip)
|
|
// 系统监控
|
|
http.HandleFunc("/sysinfo", core.SysMonitor)
|
|
//保存监听的服务器
|
|
http.HandleFunc("/scdb", core.Settdb)
|
|
// 服务器详情
|
|
http.HandleFunc("/scdetail", core.Scdetail)
|
|
// 编辑
|
|
http.HandleFunc("/scedit", core.Scedit)
|
|
|
|
// 内存信息
|
|
http.HandleFunc("/dtmem", core.Dtmem)
|
|
|
|
// 启动HTTP服务器并监听端口 80,如果出现错误,则打印错误信息并退出
|
|
fmt.Printf("Starting server at port:%v\n", config.G.Port)
|
|
sport := fmt.Sprintf(":%v", config.G.Port)
|
|
if err := http.ListenAndServe(sport, nil); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
// 执行的时候,没有附带参数默认为客户端
|
|
// 获取ip地址
|
|
lcip, err := config.GetLocalIP()
|
|
// 错误异常不为空,就输出
|
|
if err != nil {
|
|
fmt.Printf("get server ip faild %v", err)
|
|
}
|
|
// 判断输入
|
|
args := os.Args
|
|
if args == nil || len(args) < 2 {
|
|
// 编程客户端
|
|
fmt.Printf("run as client\n")
|
|
startWeb()
|
|
// 提示
|
|
os.Exit(1)
|
|
}
|
|
config.G.LocalIP = lcip
|
|
// 监控目录
|
|
flag := args[1]
|
|
if flag == "-t" {
|
|
wkdir := args[2]
|
|
// 赋值给全局
|
|
config.G.FilePath = wkdir
|
|
} else {
|
|
//
|
|
curdir, err := os.Getwd()
|
|
if err != nil {
|
|
fmt.Printf("initlizer faild %v", err)
|
|
}
|
|
// current work directory
|
|
config.G.FilePath = curdir
|
|
}
|
|
// 使用帮助
|
|
if flag == "-h" {
|
|
fmt.Printf("Usage: ./fss -t /home/\n")
|
|
os.Exit(1)
|
|
}
|
|
|
|
// args 长度大于4 才有意思
|
|
if len(args) > 4 {
|
|
config.G.Port = args[4]
|
|
// 监控端口
|
|
tpflag := args[3]
|
|
if tpflag == "-p" {
|
|
config.G.Port = args[4]
|
|
}
|
|
} else {
|
|
config.G.Port = "9099"
|
|
}
|
|
|
|
// web service
|
|
startWeb()
|
|
}
|
|
|