forked from Yohann0617/tgNetDisc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (56 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"net"
"net/http"
"os"
"yohann/tgNetDisc/conf"
"yohann/tgNetDisc/control"
"yohann/tgNetDisc/utils"
)
var webPort string
var OptApi = true
func main() {
//判断是否设置参数
if conf.BotToken == "" || conf.ChannelName == "" {
fmt.Println("请先设置Bot Token和对象")
return
}
go utils.BotDo()
web()
}
func web() {
http.HandleFunc(conf.FileRoute, control.D)
if OptApi {
if conf.Pass != "" && conf.Pass != "none" {
http.HandleFunc("/pwd", control.Pwd)
}
http.HandleFunc("/api", control.Middleware(control.UploadImageAPI))
http.HandleFunc("/", control.Middleware(control.Index))
}
if listener, err := net.Listen("tcp", ":"+webPort); err != nil {
fmt.Printf("端口 %s 已被占用\n", webPort)
} else {
defer listener.Close()
fmt.Printf("启动Web服务器,监听端口 %s\n", webPort)
if err := http.Serve(listener, nil); err != nil {
fmt.Println(err)
}
}
}
func init() {
flag.StringVar(&webPort, "port", "8088", "Web Port")
flag.StringVar(&conf.BotToken, "token", os.Getenv("TOKEN"), "Bot Token")
flag.StringVar(&conf.ChannelName, "channel", os.Getenv("CHANNEL"), "Channel Name")
flag.StringVar(&conf.Pass, "pass", os.Getenv("PASS"), "Visit Password")
flag.StringVar(&conf.Mode, "mode", os.Getenv("MODE"), "Run mode")
flag.StringVar(&conf.Domain, "domain", os.Getenv("DOMAIN"), "domain name")
flag.Parse()
if conf.Mode == "m" {
OptApi = false
}
if conf.Mode != "pan" && conf.Mode != "m" {
conf.Mode = "pan"
}
}