mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
Standardized: use recommend extension & forward compatibility before 1.0
This commit is contained in:
parent
368fc53279
commit
6a3284ba68
|
@ -64,7 +64,7 @@ If you have Docker installed, you can run clash directly using `docker-compose`.
|
||||||
|
|
||||||
The default configuration directory is `$HOME/.config/clash`
|
The default configuration directory is `$HOME/.config/clash`
|
||||||
|
|
||||||
The name of the configuration file is `config.yml`
|
The name of the configuration file is `config.yaml`
|
||||||
|
|
||||||
If you want to use another directory, you can use `-d` to control the configuration directory
|
If you want to use another directory, you can use `-d` to control the configuration directory
|
||||||
|
|
||||||
|
|
|
@ -87,11 +87,26 @@ type rawConfig struct {
|
||||||
Rule []string `yaml:"Rule"`
|
Rule []string `yaml:"Rule"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forward compatibility before 1.0
|
||||||
|
func readRawConfig(path string) ([]byte, error) {
|
||||||
|
data, err := ioutil.ReadFile(path)
|
||||||
|
if err == nil && len(data) != 0 {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Ext(path) != ".yaml" {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
path = path[:len(path)-5] + ".yml"
|
||||||
|
return ioutil.ReadFile(path)
|
||||||
|
}
|
||||||
|
|
||||||
func readConfig(path string) (*rawConfig, error) {
|
func readConfig(path string) (*rawConfig, error) {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := readRawConfig(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func Init(dir string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initial config.yml
|
// initial config.yaml
|
||||||
if _, err := os.Stat(C.Path.Config()); os.IsNotExist(err) {
|
if _, err := os.Stat(C.Path.Config()); os.IsNotExist(err) {
|
||||||
log.Info("Can't find config, create an empty file")
|
log.Info("Can't find config, create an empty file")
|
||||||
os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644)
|
os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (p *path) HomeDir() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *path) Config() string {
|
func (p *path) Config() string {
|
||||||
return P.Join(p.homedir, "config.yml")
|
return P.Join(p.homedir, "config.yaml")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *path) MMDB() string {
|
func (p *path) MMDB() string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user