2018-06-10 22:50:03 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2018-10-16 13:12:36 +08:00
|
|
|
"flag"
|
|
|
|
"path"
|
2018-06-10 22:50:03 +08:00
|
|
|
|
2018-07-26 00:04:59 +08:00
|
|
|
"github.com/Dreamacro/clash/config"
|
2018-06-18 11:31:49 +08:00
|
|
|
"github.com/Dreamacro/clash/hub"
|
2018-07-15 22:23:20 +08:00
|
|
|
"github.com/Dreamacro/clash/proxy"
|
2018-06-10 22:50:03 +08:00
|
|
|
"github.com/Dreamacro/clash/tunnel"
|
2018-10-16 13:12:36 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2018-06-10 22:50:03 +08:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2018-10-16 13:12:36 +08:00
|
|
|
var (
|
|
|
|
homedir string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&homedir, "d", "", "set configuration directory")
|
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2018-06-10 22:50:03 +08:00
|
|
|
func main() {
|
2018-07-26 00:04:59 +08:00
|
|
|
tunnel.Instance().Run()
|
|
|
|
proxy.Instance().Run()
|
|
|
|
hub.Run()
|
2018-06-10 22:50:03 +08:00
|
|
|
|
2018-10-16 13:12:36 +08:00
|
|
|
if (homedir != "") {
|
|
|
|
if !path.IsAbs(homedir) {
|
|
|
|
currentDir, _ := os.Getwd()
|
|
|
|
homedir = path.Join(currentDir, homedir)
|
|
|
|
}
|
|
|
|
C.SetHomeDir(homedir)
|
|
|
|
}
|
|
|
|
|
2018-07-31 17:54:16 +08:00
|
|
|
config.Init()
|
2018-07-26 00:04:59 +08:00
|
|
|
err := config.Instance().Parse()
|
2018-06-10 22:50:03 +08:00
|
|
|
if err != nil {
|
2018-07-26 00:04:59 +08:00
|
|
|
log.Fatalf("Parse config error: %s", err.Error())
|
2018-06-18 11:31:49 +08:00
|
|
|
}
|
|
|
|
|
2018-06-10 22:50:03 +08:00
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-sigCh
|
|
|
|
}
|