1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-25 02:14:41 -05:00
sub2sing-box/internal/model/v2ray_transport.go

86 lines
2.5 KiB
Go
Raw Normal View History

2024-03-10 15:13:42 -04:00
package model
import (
"encoding/json"
)
type V2RayTransportOptions struct {
Type string `json:"type"`
HTTPOptions V2RayHTTPOptions `json:"-"`
WebsocketOptions V2RayWebsocketOptions `json:"-"`
QUICOptions V2RayQUICOptions `json:"-"`
GRPCOptions V2RayGRPCOptions `json:"-"`
HTTPUpgradeOptions V2RayHTTPUpgradeOptions `json:"-"`
}
func (o *V2RayTransportOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case "ws":
return json.Marshal(&struct {
Type string `json:"type"`
*V2RayWebsocketOptions
}{
Type: o.Type,
V2RayWebsocketOptions: &o.WebsocketOptions,
})
case "quic":
return json.Marshal(&struct {
Type string `json:"type"`
*V2RayQUICOptions
}{
Type: o.Type,
V2RayQUICOptions: &o.QUICOptions,
})
case "grpc":
return json.Marshal(&struct {
Type string `json:"type"`
*V2RayGRPCOptions
}{
Type: o.Type,
V2RayGRPCOptions: &o.GRPCOptions,
})
case "http":
return json.Marshal(&struct {
Type string `json:"type"`
*V2RayHTTPOptions
}{
Type: o.Type,
V2RayHTTPOptions: &o.HTTPOptions,
})
default:
return json.Marshal(&struct{}{})
}
}
type V2RayHTTPOptions struct {
2024-03-11 12:13:59 -04:00
Host Listable[string] `json:"host,omitempty"`
2024-03-10 15:13:42 -04:00
Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
2024-03-11 05:31:29 -04:00
IdleTimeout string `json:"idle_timeout,omitempty"`
PingTimeout string `json:"ping_timeout,omitempty"`
2024-03-10 15:13:42 -04:00
}
type V2RayWebsocketOptions struct {
Path string `json:"path,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
MaxEarlyData uint32 `json:"max_early_data,omitempty"`
EarlyDataHeaderName string `json:"early_data_header_name,omitempty"`
}
type V2RayQUICOptions struct{}
type V2RayGRPCOptions struct {
2024-03-11 05:31:29 -04:00
ServiceName string `json:"service_name,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
PingTimeout string `json:"ping_timeout,omitempty"`
PermitWithoutStream bool `json:"permit_without_stream,omitempty"`
ForceLite bool `json:"-"` // for test
2024-03-10 15:13:42 -04:00
}
type V2RayHTTPUpgradeOptions struct {
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}