mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
49 lines
883 B
Go
49 lines
883 B
Go
package ssr
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/nadoo/glider/common/log"
|
|
)
|
|
|
|
// SSR .
|
|
type SSR struct {
|
|
addr string
|
|
|
|
EncryptMethod string
|
|
EncryptPassword string
|
|
Obfs string
|
|
ObfsParam string
|
|
ObfsData interface{}
|
|
Protocol string
|
|
ProtocolParam string
|
|
ProtocolData interface{}
|
|
}
|
|
|
|
// NewSSR returns a shadowsocksr proxy, ssr://method:pass@host:port/query
|
|
func NewSSR(s string) (*SSR, error) {
|
|
u, err := url.Parse(s)
|
|
if err != nil {
|
|
log.F("parse err: %s", err)
|
|
return nil, err
|
|
}
|
|
|
|
addr := u.Host
|
|
method := u.User.Username()
|
|
pass, _ := u.User.Password()
|
|
|
|
p := &SSR{
|
|
addr: addr,
|
|
EncryptMethod: method,
|
|
EncryptPassword: pass,
|
|
}
|
|
|
|
query := u.Query()
|
|
p.Protocol = query.Get("protocol")
|
|
p.ProtocolParam = query.Get("protocol_param")
|
|
p.Obfs = query.Get("obfs")
|
|
p.ObfsParam = query.Get("obfs_param")
|
|
|
|
return p, nil
|
|
}
|