2024-03-10 15:13:42 -04:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Proxy struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
Shadowsocks `json:"-"`
|
|
|
|
VMess `json:"-"`
|
|
|
|
VLESS `json:"-"`
|
|
|
|
Trojan `json:"-"`
|
|
|
|
TUIC `json:"-"`
|
|
|
|
Hysteria `json:"-"`
|
|
|
|
Hysteria2 `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Proxy) MarshalJSON() ([]byte, error) {
|
|
|
|
switch p.Type {
|
|
|
|
case "shadowsocks":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
Shadowsocks
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
Shadowsocks: p.Shadowsocks,
|
|
|
|
})
|
|
|
|
case "vmess":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
VMess
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
VMess: p.VMess,
|
|
|
|
})
|
|
|
|
case "vless":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
VLESS
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
VLESS: p.VLESS,
|
|
|
|
})
|
|
|
|
case "trojan":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
Trojan
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
Trojan: p.Trojan,
|
|
|
|
})
|
|
|
|
case "tuic":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
TUIC
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
TUIC: p.TUIC,
|
|
|
|
})
|
|
|
|
case "hysteria":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
Hysteria
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
Hysteria: p.Hysteria,
|
|
|
|
})
|
|
|
|
case "hysteria2":
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
Type string `json:"type"`
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag string `json:"tag,omitempty"`
|
2024-03-10 15:13:42 -04:00
|
|
|
Hysteria2
|
|
|
|
}{
|
|
|
|
Type: p.Type,
|
2024-03-11 09:00:13 -04:00
|
|
|
Tag: p.Tag,
|
2024-03-10 15:13:42 -04:00
|
|
|
Hysteria2: p.Hysteria2,
|
|
|
|
})
|
|
|
|
default:
|
|
|
|
return json.Marshal(p)
|
|
|
|
}
|
|
|
|
}
|