Documentation
¶
Index ¶
- Constants
- func HttpIngressLBGroup(workerId string, cfg *v1.HTTPProxyConfig) string
- func NewDBManager(defaultDBType string) *dbManagerImpl
- func ParseIPOrCIDRWithNetip(s string) (netip.Addr, netip.Prefix, error)
- type Cert
- type Client
- type ClientEntity
- type Endpoint
- type EndpointEntity
- type GormArray
- type HistoryProxyStats
- type JSON
- type Network
- type NetworkEntity
- type ProxyConfig
- type ProxyConfigEntity
- type ProxyStats
- type ProxyStatsEntity
- type Server
- type ServerEntity
- type User
- type UserEntity
- func (u *UserEntity) GetEmail() string
- func (u *UserEntity) GetHashedPassword() string
- func (u *UserEntity) GetRole() string
- func (u *UserEntity) GetSafeUserInfo() UserEntity
- func (u *UserEntity) GetStatus() int
- func (u *UserEntity) GetTenantID() int
- func (u *UserEntity) GetToken() string
- func (u *UserEntity) GetUserID() int
- func (u *UserEntity) GetUserIDStr() string
- func (u *UserEntity) GetUserName() string
- func (u *UserEntity) IsAdmin() bool
- func (u *UserEntity) Valid() bool
- type UserGroup
- type UserInfo
- type WireGuard
- func (w *WireGuard) AsBasePeerConfig(specifiedEndpoint *Endpoint) (*pb.WireGuardPeerConfig, error)
- func (w *WireGuard) FromPB(pb *pb.WireGuardConfig)
- func (w *WireGuard) GetID() uint
- func (w *WireGuard) GetTags() []string
- func (*WireGuard) TableName() string
- func (w *WireGuard) ToPB() *pb.WireGuardConfig
- type WireGuardEntity
- type WireGuardLink
- type WireGuardLinkEntity
- type Worker
- type WorkerEntity
- type WorkerModel
Constants ¶
View Source
const ( STATUS_UNKNOWN = iota STATUS_NORMAL STATUS_BANED )
Variables ¶
This section is empty.
Functions ¶
func HttpIngressLBGroup ¶ added in v0.1.17
func HttpIngressLBGroup(workerId string, cfg *v1.HTTPProxyConfig) string
func NewDBManager ¶
func NewDBManager(defaultDBType string) *dbManagerImpl
Types ¶
type Cert ¶
type Client ¶
type Client struct {
*ClientEntity
Workers []*Worker `json:"workers,omitempty" gorm:"many2many:worker_clients;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
WireGuard []*WireGuard `json:"wireguard,omitempty" gorm:"foreignKey:ClientID;references:ClientID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}
func BuildClientConfigFromProxyConfig ¶ added in v0.1.0
func BuildClientConfigFromProxyConfig(client *Client, proxyCfgs []*ProxyConfig) (*Client, error)
type ClientEntity ¶
type ClientEntity struct {
ClientID string `json:"client_id" gorm:"uniqueIndex;not null;primaryKey"`
ServerID string `json:"server_id"`
TenantID int `json:"tenant_id" gorm:"not null"`
UserID int `json:"user_id" gorm:"not null"`
ConfigContent []byte `json:"config_content"`
ConnectSecret string `json:"connect_secret" gorm:"not null"`
Stopped bool `json:"stopped"`
Comment string `json:"comment"`
IsShadow bool `json:"is_shadow" gorm:"index"`
OriginClientID string `json:"origin_client_id" gorm:"index"`
FrpsUrl string `json:"frps_url" gorm:"index"`
Ephemeral bool `json:"ephemeral" gorm:"index"`
LastSeenAt *time.Time `json:"last_seen_at" gorm:"index"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (*ClientEntity) GetConfigContent ¶
func (c *ClientEntity) GetConfigContent() (*v1.ClientConfig, error)
func (*ClientEntity) MarshalJSONConfig ¶ added in v0.1.0
func (c *ClientEntity) MarshalJSONConfig() ([]byte, error)
func (*ClientEntity) SetConfigContent ¶
func (c *ClientEntity) SetConfigContent(cfg v1.ClientConfig) error
func (*ClientEntity) ToPB ¶ added in v0.1.14
func (c *ClientEntity) ToPB() *pb.Client
type Endpoint ¶ added in v0.1.25
type Endpoint struct {
gorm.Model
*EndpointEntity
WireGuard *WireGuard `json:"wireguard,omitempty" gorm:"foreignKey:WireGuardID;references:ID"`
Client *Client `json:"client,omitempty" gorm:"foreignKey:ClientID;references:ClientID"`
}
type EndpointEntity ¶ added in v0.1.25
type EndpointEntity struct {
Host string `gorm:"uniqueIndex:idx_client_id_host_port_type"`
Port uint32 `gorm:"uniqueIndex:idx_client_id_host_port_type"`
Uri string
Type string `gorm:"type:varchar(255);index;uniqueIndex:idx_client_id_host_port_type"`
WireGuardID uint `gorm:"index"`
ClientID string `gorm:"type:varchar(255);uniqueIndex:idx_client_id_host_port_type"`
}
type HistoryProxyStats ¶ added in v0.0.31
type HistoryProxyStats struct {
gorm.Model
ProxyID int `json:"proxy_id" gorm:"index"`
ServerID string `json:"server_id" gorm:"index"`
ClientID string `json:"client_id" gorm:"index"`
OriginClientID string `json:"origin_client_id" gorm:"index"`
Name string `json:"name"`
Type string `json:"type"`
UserID int `json:"user_id" gorm:"index"`
TenantID int `json:"tenant_id" gorm:"index"`
TrafficIn int64 `json:"traffic_in"`
TrafficOut int64 `json:"traffic_out"`
}
HistoryProxyStats 历史流量统计,不保证精准,只是为了展示。精准请使用 proxies 表中的 history_traffic_in/history_traffic_out 后续看看是否要改成时序类数据 https://github.com/nakabonne/tstorage
func (*HistoryProxyStats) TableName ¶ added in v0.0.31
func (*HistoryProxyStats) TableName() string
type Network ¶ added in v0.1.25
type Network struct {
gorm.Model
*NetworkEntity
WireGuard []*WireGuard `json:"wireguard,omitempty" gorm:"foreignKey:NetworkID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}
type NetworkEntity ¶ added in v0.1.25
type ProxyConfig ¶ added in v0.1.0
type ProxyConfig struct {
*gorm.Model
*ProxyConfigEntity
WorkerID string `gorm:"type:varchar(255);index"` // 引用的worker
Worker Worker
}
func (*ProxyConfig) FillClientConfig ¶ added in v0.1.14
func (p *ProxyConfig) FillClientConfig(cli *ClientEntity) error
func (*ProxyConfig) FillTypedProxyConfig ¶ added in v0.1.14
func (p *ProxyConfig) FillTypedProxyConfig(cfg v1.TypedProxyConfig) error
func (*ProxyConfig) GetTypedProxyConfig ¶ added in v0.1.14
func (p *ProxyConfig) GetTypedProxyConfig() (v1.TypedProxyConfig, error)
func (*ProxyConfig) TableName ¶ added in v0.1.0
func (*ProxyConfig) TableName() string
func (*ProxyConfig) ToPB ¶ added in v0.1.14
func (p *ProxyConfig) ToPB() *pb.ProxyConfig
type ProxyConfigEntity ¶ added in v0.1.0
type ProxyConfigEntity struct {
ServerID string `json:"server_id" gorm:"index"`
ClientID string `json:"client_id" gorm:"index"`
Name string `json:"name" gorm:"index"`
Type string `json:"type" gorm:"index"`
UserID int `json:"user_id" gorm:"index"`
TenantID int `json:"tenant_id" gorm:"index"`
OriginClientID string `json:"origin_client_id" gorm:"index"`
Content []byte `json:"content"`
Stopped bool `json:"stopped" gorm:"index"`
}
func ParseProxyConfigFromClient ¶ added in v0.1.0
func ParseProxyConfigFromClient(client *Client) ([]*ProxyConfigEntity, error)
func (*ProxyConfigEntity) FillClientConfig ¶ added in v0.1.0
func (p *ProxyConfigEntity) FillClientConfig(cli *ClientEntity) error
func (*ProxyConfigEntity) FillTypedProxyConfig ¶ added in v0.1.0
func (p *ProxyConfigEntity) FillTypedProxyConfig(cfg v1.TypedProxyConfig) error
func (*ProxyConfigEntity) GetTypedProxyConfig ¶ added in v0.1.13
func (p *ProxyConfigEntity) GetTypedProxyConfig() (v1.TypedProxyConfig, error)
type ProxyStats ¶ added in v0.1.0
type ProxyStats struct {
*ProxyStatsEntity
}
func (*ProxyStats) TableName ¶ added in v0.1.0
func (*ProxyStats) TableName() string
type ProxyStatsEntity ¶ added in v0.1.0
type ProxyStatsEntity struct {
ProxyID int `json:"proxy_id" gorm:"primary_key;auto_increment"`
ServerID string `json:"server_id" gorm:"index"`
ClientID string `json:"client_id" gorm:"index"`
OriginClientID string `json:"origin_client_id" gorm:"index"`
Name string `json:"name"`
Type string `json:"type"`
UserID int `json:"user_id" gorm:"index"`
TenantID int `json:"tenant_id" gorm:"index"`
TodayTrafficIn int64 `json:"today_traffic_in"`
TodayTrafficOut int64 `json:"today_traffic_out"`
HistoryTrafficIn int64 `json:"history_traffic_in"`
HistoryTrafficOut int64 `json:"history_traffic_out"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
type Server ¶
type Server struct {
*ServerEntity
}
type ServerEntity ¶
type ServerEntity struct {
ServerID string `json:"client_id" gorm:"uniqueIndex;not null;primaryKey"`
TenantID int `json:"tenant_id" gorm:"not null,index"`
UserID int `json:"user_id" gorm:"not null"`
ServerIP string `json:"server_ip"`
ConfigContent []byte `json:"config_content"`
ConnectSecret string `json:"connect_secret" gorm:"not null"`
Comment string `json:"comment"`
FrpsUrls GormArray[string] `json:"frps_urls"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (*ServerEntity) ConfigEqual ¶ added in v0.0.41
func (s *ServerEntity) ConfigEqual(cfg *v1.ServerConfig) bool
func (*ServerEntity) GetConfigContent ¶
func (s *ServerEntity) GetConfigContent() (*v1.ServerConfig, error)
func (*ServerEntity) SetConfigContent ¶
func (s *ServerEntity) SetConfigContent(cfg *v1.ServerConfig) error
type User ¶
type User struct {
*UserEntity
}
type UserEntity ¶
type UserEntity struct {
UserID int `json:"user_id" gorm:"primaryKey"`
UserName string `json:"user_name" gorm:"type:varchar(255);uniqueIndex;not null"`
Password string `json:"password"`
Email string `json:"email" gorm:"type:varchar(255);uniqueIndex;not null"`
Status int `json:"status"`
Role string `json:"role"`
TenantID int `json:"tenant_id"`
Token string `json:"token"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
Groups []*UserGroup `json:"groups,omitempty" gorm:"many2many:user_group_memberships;"`
}
func (*UserEntity) GetEmail ¶
func (u *UserEntity) GetEmail() string
func (*UserEntity) GetHashedPassword ¶
func (u *UserEntity) GetHashedPassword() string
func (*UserEntity) GetRole ¶
func (u *UserEntity) GetRole() string
func (*UserEntity) GetSafeUserInfo ¶
func (u *UserEntity) GetSafeUserInfo() UserEntity
func (*UserEntity) GetStatus ¶
func (u *UserEntity) GetStatus() int
func (*UserEntity) GetTenantID ¶
func (u *UserEntity) GetTenantID() int
func (*UserEntity) GetToken ¶
func (u *UserEntity) GetToken() string
func (*UserEntity) GetUserID ¶
func (u *UserEntity) GetUserID() int
func (*UserEntity) GetUserIDStr ¶
func (u *UserEntity) GetUserIDStr() string
func (*UserEntity) GetUserName ¶
func (u *UserEntity) GetUserName() string
func (*UserEntity) IsAdmin ¶
func (u *UserEntity) IsAdmin() bool
func (*UserEntity) Valid ¶
func (u *UserEntity) Valid() bool
type UserGroup ¶ added in v0.1.12
type UserGroup struct {
GroupID string `json:"group_id" gorm:"primaryKey"`
GroupName string `json:"group_name" gorm:"type:varchar(255);uniqueIndex:idx_group_tenant_name;not null"`
TenantID int `json:"tenant_id" gorm:"uniqueIndex:idx_group_tenant_name;not null"`
Comment string `json:"comment"`
CreatedAt time.Time
UpdatedAt time.Time
Users []*User `json:"users,omitempty" gorm:"many2many:user_group_memberships;"`
}
type WireGuard ¶ added in v0.1.25
type WireGuard struct {
gorm.Model
*WireGuardEntity
Client *Client `json:"client,omitempty" gorm:"foreignKey:ClientID;references:ClientID"`
Network *Network `json:"network,omitempty" gorm:"foreignKey:NetworkID;references:ID"`
AdvertisedEndpoints []*Endpoint `json:"advertised_endpoints,omitempty" gorm:"foreignKey:WireGuardID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
WireGuardLinks []*WireGuardLink `json:"wireguard_links,omitempty" gorm:"foreignKey:FromWireGuardID;references:ID"`
}
func (*WireGuard) AsBasePeerConfig ¶ added in v0.1.25
func (w *WireGuard) AsBasePeerConfig(specifiedEndpoint *Endpoint) (*pb.WireGuardPeerConfig, error)
AsBasePeerConfig 将 WireGuard 配置转换为 Peer 配置 specifiedEndpoint: 可选参数,用于指定使用的 Endpoint。如果为 nil,则使用第一个 AdvertisedEndpoint
func (*WireGuard) FromPB ¶ added in v0.1.25
func (w *WireGuard) FromPB(pb *pb.WireGuardConfig)
func (*WireGuard) ToPB ¶ added in v0.1.25
func (w *WireGuard) ToPB() *pb.WireGuardConfig
type WireGuardEntity ¶ added in v0.1.25
type WireGuardEntity struct {
Name string `gorm:"type:varchar(255);uniqueIndex:idx_client_id_name"`
UserId uint32 `gorm:"index"`
TenantId uint32 `gorm:"index"`
PrivateKey string `json:"private_key" gorm:"type:varchar(255)"`
LocalAddress string `json:"local_address" gorm:"type:varchar(255)"`
ListenPort uint32 `json:"listen_port" gorm:"uniqueIndex:idx_client_id_listen_port"`
InterfaceMtu uint32 `json:"interface_mtu"`
DnsServers GormArray[string] `json:"dns_servers" gorm:"type:varchar(255)"`
ClientID string `` /* 133-byte string literal not displayed */
NetworkID uint `gorm:"index"`
Tags GormArray[string] `json:"tags" gorm:"type:varchar(255)"`
WsListenPort uint32 `json:"ws_listen_port" gorm:"uniqueIndex:idx_client_id_ws_listen_port"`
UseGvisorNet bool `json:"use_gvisor_net"`
}
type WireGuardLink ¶ added in v0.1.25
type WireGuardLink struct {
gorm.Model
*WireGuardLinkEntity
FromWireGuard *WireGuard `json:"from_wireguard,omitempty" gorm:"foreignKey:FromWireGuardID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
ToWireGuard *WireGuard `json:"to_wireguard,omitempty" gorm:"foreignKey:ToWireGuardID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
ToEndpoint *Endpoint `json:"to_endpoint,omitempty" gorm:"foreignKey:ToEndpointID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}
WireGuardLink 描述同一 Network 下两个 WireGuard 节点之间的有向链路与其指标。 语义:从 FromWireGuardID 指向 ToWireGuardID 的传输路径, UpBandwidthMbps 表示从 From -> To 的可用上行带宽;LatencyMs 为单向时延。 如需双向链路,请创建两条对向记录。
func (*WireGuardLink) FromPB ¶ added in v0.1.25
func (w *WireGuardLink) FromPB(pbData *pb.WireGuardLink)
func (*WireGuardLink) TableName ¶ added in v0.1.25
func (*WireGuardLink) TableName() string
func (*WireGuardLink) ToPB ¶ added in v0.1.25
func (w *WireGuardLink) ToPB() *pb.WireGuardLink
type WireGuardLinkEntity ¶ added in v0.1.25
type WireGuardLinkEntity struct {
// 多租户
UserId uint32 `gorm:"index"`
TenantId uint32 `gorm:"index"`
// 归属网络
NetworkID uint `gorm:"index"`
// 有向边两端
FromWireGuardID uint `gorm:"index"`
ToWireGuardID uint `gorm:"index"`
ToEndpointID uint `gorm:"index"`
// 链路指标
UpBandwidthMbps uint32
DownBandwidthMbps uint32
LatencyMs uint32
// 状态
Active bool `gorm:"index"`
}
type Worker ¶ added in v0.1.14
type Worker struct {
*WorkerModel
*WorkerEntity
Clients []Client `gorm:"many2many:worker_clients;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}
type WorkerEntity ¶ added in v0.1.14
type WorkerEntity struct {
ID string `gorm:"type:varchar(255);uniqueIndex;not null;primaryKey"`
Name string `gorm:"type:varchar(255);index"`
UserId uint32 `gorm:"index"`
TenantId uint32 `gorm:"index"`
Socket JSON[*pb.Socket]
CodeEntry string
Code string
ConfigTemplate string
}
func (*WorkerEntity) FromPB ¶ added in v0.1.14
func (w *WorkerEntity) FromPB(worker *pb.Worker) *WorkerEntity
func (*WorkerEntity) ToPB ¶ added in v0.1.14
func (w *WorkerEntity) ToPB() *pb.Worker
Click to show internal directories.
Click to hide internal directories.