mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
42 lines
830 B
Go
42 lines
830 B
Go
|
package libbox
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
)
|
||
|
|
||
|
func GenerateRemoteProfileImportLink(name string, remoteURL string) string {
|
||
|
importLink := &url.URL{
|
||
|
Scheme: "sing-box",
|
||
|
Host: "import-remote-profile",
|
||
|
RawQuery: url.Values{"url": []string{remoteURL}}.Encode(),
|
||
|
Fragment: name,
|
||
|
}
|
||
|
return importLink.String()
|
||
|
}
|
||
|
|
||
|
type ImportRemoteProfile struct {
|
||
|
Name string
|
||
|
URL string
|
||
|
Host string
|
||
|
}
|
||
|
|
||
|
func ParseRemoteProfileImportLink(importLink string) (*ImportRemoteProfile, error) {
|
||
|
importURL, err := url.Parse(importLink)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
remoteURL, err := url.Parse(importURL.Query().Get("url"))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
name := importURL.Fragment
|
||
|
if name == "" {
|
||
|
name = remoteURL.Host
|
||
|
}
|
||
|
return &ImportRemoteProfile{
|
||
|
Name: name,
|
||
|
URL: remoteURL.String(),
|
||
|
Host: remoteURL.Host,
|
||
|
}, nil
|
||
|
}
|