2023-06-07 13:18:56 -04:00
|
|
|
package conf
|
|
|
|
|
2023-08-20 03:13:52 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
2023-06-07 13:18:56 -04:00
|
|
|
type CoreConfig struct {
|
2024-02-05 20:59:37 -05:00
|
|
|
Type string `json:"Type"`
|
|
|
|
Name string `json:"Name"`
|
|
|
|
XrayConfig *XrayConfig `json:"-"`
|
|
|
|
SingConfig *SingConfig `json:"-"`
|
|
|
|
Hysteria2Config *Hysteria2Config `json:"-"`
|
2023-08-20 03:13:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type _CoreConfig CoreConfig
|
|
|
|
|
|
|
|
func (c *CoreConfig) UnmarshalJSON(b []byte) error {
|
|
|
|
err := json.Unmarshal(b, (*_CoreConfig)(c))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch c.Type {
|
|
|
|
case "xray":
|
|
|
|
c.XrayConfig = NewXrayConfig()
|
|
|
|
return json.Unmarshal(b, c.XrayConfig)
|
|
|
|
case "sing":
|
|
|
|
c.SingConfig = NewSingConfig()
|
|
|
|
return json.Unmarshal(b, c.SingConfig)
|
2024-02-05 20:59:37 -05:00
|
|
|
case "hysteria2":
|
|
|
|
c.Hysteria2Config = NewHysteria2Config()
|
|
|
|
return json.Unmarshal(b, c.Hysteria2Config)
|
2023-08-20 03:13:52 -04:00
|
|
|
}
|
|
|
|
return nil
|
2023-06-07 13:18:56 -04:00
|
|
|
}
|