clash/main.go

51 lines
884 B
Go
Raw Normal View History

2018-06-10 22:50:03 +08:00
package main
import (
2018-11-14 20:58:10 +08:00
"flag"
2018-06-10 22:50:03 +08:00
"os"
"os/signal"
2018-11-14 20:58:10 +08:00
"path/filepath"
2018-06-10 22:50:03 +08:00
"syscall"
"github.com/Dreamacro/clash/config"
2018-11-14 20:58:10 +08:00
C "github.com/Dreamacro/clash/constant"
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"
log "github.com/sirupsen/logrus"
)
var (
homedir string
)
func init() {
flag.StringVar(&homedir, "d", "", "set configuration directory")
flag.Parse()
}
2018-06-10 22:50:03 +08:00
func main() {
tunnel.Instance().Run()
proxy.Instance().Run()
hub.Run()
2018-06-10 22:50:03 +08:00
2018-11-14 20:58:10 +08:00
if homedir != "" {
if !filepath.IsAbs(homedir) {
currentDir, _ := os.Getwd()
2018-11-14 20:58:10 +08:00
homedir = filepath.Join(currentDir, homedir)
}
C.SetHomeDir(homedir)
}
config.Init()
err := config.Instance().Parse()
2018-06-10 22:50:03 +08:00
if err != nil {
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
}