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.
91 lines
1.7 KiB
91 lines
1.7 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
|
|
"xtcfs/config"
|
|
"xtcfs/handler"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var (
|
|
port string
|
|
)
|
|
|
|
// 初始化配置
|
|
func initConfig(c *cli.Context) error {
|
|
return config.G.SetConf(port)
|
|
}
|
|
|
|
// 目标接收端,接收发送来的文件
|
|
func receiveClient() error {
|
|
// 加入udp 监听
|
|
//go discovery.Listen()
|
|
|
|
// 显示状态等
|
|
http.HandleFunc("/", handler.ReceiveHandler)
|
|
// 服务信息
|
|
http.HandleFunc("/sc", handler.SerInfo)
|
|
// 开启web 服务,
|
|
return http.ListenAndServe(config.G.WildcardAddress, nil)
|
|
}
|
|
|
|
// 入口函数
|
|
/**
|
|
* 保留接收的功能,用来做接收端
|
|
fs
|
|
**/
|
|
func main() {
|
|
app := &cli.App{
|
|
Name: "fstc",
|
|
Usage: "fstc --t|--h|--v",
|
|
UsageText: "fstc [global options] [filename|foldername]",
|
|
Description: "fstc is a command-line tool",
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "port",
|
|
Value: "9099",
|
|
Usage: "server port",
|
|
Aliases: []string{"p"},
|
|
Destination: &port,
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "version",
|
|
Aliases: []string{"v"},
|
|
Usage: "v1.02",
|
|
},
|
|
// 监听的目录位置
|
|
&cli.StringFlag{
|
|
Name: "target",
|
|
Aliases: []string{"t"},
|
|
Usage: "eg:fstc --t /home",
|
|
},
|
|
},
|
|
Action: func(c *cli.Context) error {
|
|
// 接收输入的 监听目录的位置
|
|
tgdir := c.String("t")
|
|
if tgdir == "" {
|
|
dir, err := os.Getwd()
|
|
if err == nil {
|
|
tgdir = dir
|
|
}
|
|
//
|
|
fmt.Printf("work diretctory is:%s\n", tgdir)
|
|
}
|
|
|
|
// 工作目录
|
|
config.G.FilePath = tgdir
|
|
return receiveClient()
|
|
|
|
},
|
|
Before: initConfig,
|
|
}
|
|
|
|
err := app.Run(os.Args)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
}
|
|
|