/
proxy.go
65 lines (56 loc) · 2.21 KB
/
proxy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Copyright 2021 The KodeRover Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package models
import (
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Proxy struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
// http或socks5 暂时只支持http代理
Type string `bson:"type" json:"type"`
Address string `bson:"address" json:"address"`
Port int `bson:"port" json:"port"`
NeedPassword bool `bson:"need_password" json:"need_password"`
Username string `bson:"username" json:"username"`
Password string `bson:"password" json:"password"`
// 代理用途,app表示应用代理,repo表示代码库代理。保留字段,暂时默认设置为default,以后可能用到。
Usage string `bson:"usage" json:"usage"`
EnableRepoProxy bool `bson:"enable_repo_proxy" json:"enable_repo_proxy"`
EnableApplicationProxy bool `bson:"enable_application_proxy" json:"enable_application_proxy"`
CreateTime int64 `bson:"create_time" json:"create_time"`
UpdateTime int64 `bson:"update_time" json:"update_time"`
UpdateBy string `bson:"update_by" json:"update_by"`
}
func (Proxy) TableName() string {
return "proxy"
}
func (p *Proxy) GetProxyURL() string {
var uri string
if p.NeedPassword {
uri = fmt.Sprintf("%s://%s:%s@%s:%d",
p.Type,
p.Username,
p.Password,
p.Address,
p.Port,
)
} else {
uri = fmt.Sprintf("%s://%s:%d",
p.Type,
p.Address,
p.Port,
)
}
return uri
}