package main import ( "fmt" "fss/config" "fss/core" "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) fmt.Printf("Starting server at port 9099\n") // 启动HTTP服务器并监听端口 80,如果出现错误,则打印错误信息并退出 if err := http.ListenAndServe(":9099", nil); err != nil { log.Fatal(err) } } // 主函数 func main() { // 判断输入 args := os.Args if args == nil || len(args) < 2 { fmt.Printf("Usage: ./fss -t /home/\n") os.Exit(1) } // 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() }