mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-27 16:35:19 +08:00
阶段性提交
This commit is contained in:
41
internal/configs/serverconfigs/server_group.go
Normal file
41
internal/configs/serverconfigs/server_group.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package serverconfigs
|
||||
|
||||
import "strings"
|
||||
|
||||
type ServerGroup struct {
|
||||
fullAddr string
|
||||
Servers []*ServerConfig
|
||||
}
|
||||
|
||||
func NewServerGroup(fullAddr string) *ServerGroup {
|
||||
return &ServerGroup{fullAddr: fullAddr}
|
||||
}
|
||||
|
||||
// 添加服务
|
||||
func (this *ServerGroup) Add(server *ServerConfig) {
|
||||
this.Servers = append(this.Servers, server)
|
||||
}
|
||||
|
||||
// 获取完整的地址
|
||||
func (this *ServerGroup) FullAddr() string {
|
||||
return this.fullAddr
|
||||
}
|
||||
|
||||
// 获取当前分组的协议
|
||||
func (this *ServerGroup) Protocol() Protocol {
|
||||
for _, p := range AllProtocols() {
|
||||
if strings.HasPrefix(this.fullAddr, p+":") {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return ProtocolHTTP
|
||||
}
|
||||
|
||||
// 获取当前分组的地址
|
||||
func (this *ServerGroup) Addr() string {
|
||||
protocol := this.Protocol()
|
||||
if protocol == ProtocolUnix {
|
||||
return strings.TrimPrefix(this.fullAddr, protocol+":")
|
||||
}
|
||||
return strings.TrimPrefix(this.fullAddr, protocol+"://")
|
||||
}
|
||||
Reference in New Issue
Block a user