mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-22 23:57:26 +08:00
7f588935ea
* feat: host support domain and multiple ips * chore: append local address via `clash` * chore: update hosts demo * chore: unified parse mixed string and array * fix: flatten cname * chore: adjust logic * chore: reuse code * chore: use cname in tunnel * chore: try use domain mapping when normal dns * chore: format code
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package hub
|
|
|
|
import (
|
|
"github.com/Dreamacro/clash/config"
|
|
"github.com/Dreamacro/clash/hub/executor"
|
|
"github.com/Dreamacro/clash/hub/route"
|
|
"github.com/Dreamacro/clash/log"
|
|
)
|
|
|
|
type Option func(*config.Config)
|
|
|
|
func WithExternalUI(externalUI string) Option {
|
|
return func(cfg *config.Config) {
|
|
cfg.General.ExternalUI = externalUI
|
|
}
|
|
}
|
|
|
|
func WithExternalController(externalController string) Option {
|
|
return func(cfg *config.Config) {
|
|
cfg.General.ExternalController = externalController
|
|
}
|
|
}
|
|
|
|
func WithSecret(secret string) Option {
|
|
return func(cfg *config.Config) {
|
|
cfg.General.Secret = secret
|
|
}
|
|
}
|
|
|
|
// Parse call at the beginning of clash
|
|
func Parse(options ...Option) error {
|
|
cfg, err := executor.Parse()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, option := range options {
|
|
option(cfg)
|
|
}
|
|
|
|
if cfg.General.ExternalUI != "" {
|
|
route.SetUIPath(cfg.General.ExternalUI)
|
|
}
|
|
|
|
if cfg.General.ExternalController != "" {
|
|
go route.Start(cfg.General.ExternalController, cfg.General.ExternalControllerTLS,
|
|
cfg.General.Secret, cfg.TLS.Certificate, cfg.TLS.PrivateKey, cfg.General.LogLevel == log.DEBUG)
|
|
}
|
|
|
|
executor.ApplyConfig(cfg, true)
|
|
return nil
|
|
}
|