package main import ( "aufs/config" "aufs/core" "fmt" "log" "net/http" "os" ) // 启动web服务 func startWeb() { //创建一个文件服务器,会去www目录下找index.html fileServer := http.FileServer(http.Dir("./fsw")) // 将 "/" 路径映射到文件服务器 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("/dtmem", core.Dtmem) fmt.Printf("Starting server at port 9099\n") // 启动HTTP服务器并监听端口 80,如果出现错误,则打印错误信息并退出 if err := http.ListenAndServe(":9099", 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") fmt.Printf("Usage: ./fss -t /home/\n") 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 } // web service startWeb() }