-
Notifications
You must be signed in to change notification settings - Fork 33
/
vendor.go
48 lines (39 loc) · 1.03 KB
/
vendor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package local
import (
"context"
"fmt"
"net"
"github.com/miaokobot/miaospeed/interfaces"
)
type Local struct {
name string
info string
}
func (c *Local) Type() interfaces.VendorType {
return interfaces.VendorLocal
}
func (c *Local) Status() interfaces.VendorStatus {
return interfaces.VStatusOperational
}
func (c *Local) Build(proxyName string, proxyInfo string) interfaces.Vendor {
c.name = proxyName
c.info = proxyInfo
return c
}
func (c *Local) DialTCP(ctx context.Context, url string, network interfaces.RequestOptionsNetwork) (net.Conn, error) {
if hostname, port, err := urlToMetadata(url); err != nil {
return nil, err
} else {
return net.Dial(network.String(), fmt.Sprintf("%s:%d", hostname, port))
}
}
func (c *Local) DialUDP(ctx context.Context, url string) (net.PacketConn, error) {
return nil, fmt.Errorf("local test does not support udp yet")
}
func (c *Local) ProxyInfo() interfaces.ProxyInfo {
return interfaces.ProxyInfo{
Name: c.name,
Address: "127.0.0.1",
Type: interfaces.Parse("Invalid"),
}
}