6 changed files with 157 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||
HELP.md |
|||
target/ |
|||
!.mvn/wrapper/maven-wrapper.jar |
|||
!**/src/main/**/target/ |
|||
!**/src/test/**/target/ |
|||
|
|||
### STS ### |
|||
.apt_generated |
|||
.classpath |
|||
.factorypath |
|||
.project |
|||
.settings |
|||
.springBeans |
|||
.sts4-cache |
|||
|
|||
### IntelliJ IDEA ### |
|||
.idea |
|||
*.iws |
|||
*.iml |
|||
*.ipr |
|||
|
|||
### NetBeans ### |
|||
/nbproject/private/ |
|||
/nbbuild/ |
|||
/dist/ |
|||
/nbdist/ |
|||
/.nb-gradle/ |
|||
build/ |
|||
!**/src/main/**/build/ |
|||
!**/src/test/**/build/ |
|||
|
|||
### VS Code ### |
|||
.vscode/ |
|||
|
|||
logs/ |
|||
files/ |
|||
@ -0,0 +1,22 @@ |
|||
## 功能说明 |
|||
|
|||
客户端和服务端使用同一套执行脚本。 |
|||
|
|||
|
|||
### 服务端 |
|||
|
|||
1、启动需要参数 |
|||
2、可以通过install /uninstall 安装/卸载服务 |
|||
3、可以通过--config 配置文件路径 来指定配置文件路径 |
|||
4、可以通过--log 日志文件路径 来指定日志文件路径 |
|||
|
|||
|
|||
|
|||
### 客户端 |
|||
|
|||
|
|||
1、客户端执行过程中不需要携带配置参数,服务端需要携带参数。 |
|||
2、服务端执行过程中写入到服务中。输入--uninstall 可以卸载服务。 |
|||
3、作为客户端的时候,需要登录。登录密码可以重置默认密码。 |
|||
4、选定文件对比的时候,展示左右两列 |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
color 87 |
|||
set GOOS=linux |
|||
set GOARCH=amd64 |
|||
set CGO_ENABLED=0 |
|||
go build -o aufs main.go |
|||
@ -0,0 +1,49 @@ |
|||
package config |
|||
|
|||
import ( |
|||
"fmt" |
|||
"net" |
|||
) |
|||
|
|||
type Config struct { |
|||
DeviceName string |
|||
Port string |
|||
LocalIP string |
|||
FilePath string |
|||
Version string |
|||
} |
|||
|
|||
var G Config |
|||
|
|||
// 本地ip
|
|||
func GetLocalIP() (string, error) { |
|||
addrs, err := net.InterfaceAddrs() |
|||
if err != nil { |
|||
return "", err |
|||
} |
|||
var ips []string |
|||
for _, address := range addrs { |
|||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { |
|||
if ipnet.IP.To4() != nil { |
|||
ips = append(ips, ipnet.IP.String()) |
|||
} |
|||
} |
|||
} |
|||
if len(ips) == 0 { |
|||
return "", fmt.Errorf("get local ip failed") |
|||
} else if len(ips) == 1 { |
|||
return ips[0], nil |
|||
} else { |
|||
// Select the one connected to the network
|
|||
// when there are multiple network interfaces
|
|||
|
|||
// Is there a better way?
|
|||
c, err := net.Dial("udp", "8.8.8.8:80") |
|||
if err != nil { |
|||
return ips[0], nil |
|||
} |
|||
defer c.Close() |
|||
return c.LocalAddr().(*net.UDPAddr).IP.String(), nil |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
module aufs |
|||
|
|||
go 1.22.1 |
|||
@ -0,0 +1,42 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"aufs/config" |
|||
"fmt" |
|||
"os" |
|||
) |
|||
|
|||
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 |
|||
} |
|||
} |
|||
Loading…
Reference in new issue