mihomo/main.go

40 lines
818 B
Go
Raw Normal View History

2018-06-10 22:50:03 +08:00
package main
import (
"os"
"os/signal"
"syscall"
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"
)
func main() {
2018-07-15 22:23:20 +08:00
if err := tunnel.GetInstance().UpdateConfig(); err != nil {
log.Fatalf("Parse config error: %s", err.Error())
2018-06-10 22:50:03 +08:00
}
2018-07-15 22:23:20 +08:00
if err := proxy.Instance().Run(); err != nil {
log.Fatalf("Proxy listen error: %s", err.Error())
2018-06-10 22:50:03 +08:00
}
2018-07-15 22:23:20 +08:00
// Hub
cfg, err := C.GetConfig()
2018-06-10 22:50:03 +08:00
if err != nil {
2018-07-15 22:23:20 +08:00
log.Fatalf("Read config error: %s", err.Error())
2018-06-10 22:50:03 +08:00
}
2018-07-15 22:23:20 +08:00
section := cfg.Section("General")
2018-06-18 11:31:49 +08:00
if key, err := section.GetKey("external-controller"); err == nil {
go hub.NewHub(key.Value())
}
2018-06-10 22:50:03 +08:00
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
}