From 1a73a67a4ca2be654e2c45b80c071e2d22d20077 Mon Sep 17 00:00:00 2001 From: coward Date: Tue, 5 Mar 2024 17:28:18 +0800 Subject: [PATCH] :construction: --- constant/wireguard.go | 1 + go.mod | 1 + go.sum | 2 ++ main.go | 1 - model/entity/base.go | 21 ++++++++++++++++++++ model/entity/wireguard.go | 40 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 constant/wireguard.go create mode 100644 model/entity/base.go create mode 100644 model/entity/wireguard.go diff --git a/constant/wireguard.go b/constant/wireguard.go new file mode 100644 index 0000000..3f2495e --- /dev/null +++ b/constant/wireguard.go @@ -0,0 +1 @@ +package constant diff --git a/go.mod b/go.mod index b3cce71..32c27d7 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.4.3 // indirect diff --git a/go.sum b/go.sum index de1ed75..f38d80e 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= diff --git a/main.go b/main.go index 1a93471..2dd8b90 100644 --- a/main.go +++ b/main.go @@ -25,5 +25,4 @@ func main() { if err := httpServe.ListenAndServe(); err != nil { log.Panicf("启动http服务端失败: %v", err.Error()) } - } diff --git a/model/entity/base.go b/model/entity/base.go new file mode 100644 index 0000000..2fc49d7 --- /dev/null +++ b/model/entity/base.go @@ -0,0 +1,21 @@ +package entity + +import ( + "github.com/google/uuid" + "gorm.io/datatypes" + "gorm.io/gorm" +) + +type Base struct { + Id string `json:"id" gorm:"primaryKey;type:varchar(36);not null;comment:'主键'"` + CreatedAt datatypes.Time + UpdatedAt datatypes.Time +} + +func (b *Base) BeforeCreate(*gorm.DB) (err error) { + if b.Id == "" { + b.Id = uuid.NewString() + } + + return +} diff --git a/model/entity/wireguard.go b/model/entity/wireguard.go new file mode 100644 index 0000000..8c905b5 --- /dev/null +++ b/model/entity/wireguard.go @@ -0,0 +1,40 @@ +package entity + +// Server +// @description: 服务端 +type Server struct { + Base + IpScope string `json:"ipScope" gorm:"type:varchar(30);not null;comment:'ip范围'"` + ListenPort int `json:"listenPort" gorm:"type:int(10);not null;comment:'服务监听端口'"` + PrivateKey string `json:"privateKey" gorm:"type:text;not null;comment:'密钥'"` + PublicKey string `json:"publicKey" gorm:"type:text;not null;comment:'公钥'"` + PostUpScript string `json:"postUpScript" gorm:"type:text;default null;comment:'postUpScript'"` + PreDownScript string `json:"preDownScript" gorm:"type:text;default null;comment:'preDownScript'"` + PostDownScript string `json:"postDownScript" gorm:"type:text;default null;comment:postDownScript"` + Clients []Client `json:"clients" gorm:"foreignKey:ServerId"` +} + +func (*Server) TableName() string { + return "t_wg_server" +} + +// Client +// @description: 客户端 +type Client struct { + Base + ServerId string `json:"serverId" gorm:"type:varchar(36);not null;comment:'服务端id'"` + Name string `json:"name" gorm:"type:varchar(100);not null;comment:'客户端名称'"` + Email string `json:"email" gorm:"type:varchar(100);default null;comment:'联系邮箱'"` + SubnetRange string `json:"subnetRange" gorm:"type:varchar(255);default null;comment:'子网范围'"` + IpAllocation string `json:"ipAllocation" gorm:"type:varchar(30);not null;comment:'客户端ip'"` + AllowedIps string `json:"allowedIps" gorm:"type:varchar(30);not null;comment:'允许访问的ip'"` + ExtraAllowedIps string `json:"extraAllowedIps" gorm:"type:varchar(30);default null;comment:'额外允许的ip范围'"` + Endpoint string `json:"endpoint" gorm:"type:varchar(255);default null;comment:'端点'"` + UseServerDns int `json:"useServerDns" gorm:"type:int(1);default 1;comment:'是否使用服务端dns'"` + EnableAfterCreation int `json:"enableAfterCreation" gorm:"type:int(1);default 1;comment:'是否创建后启用'"` + Keys string `json:"keys" gorm:"type:text;default null;comment:'公钥和密钥的json串'"` +} + +func (*Client) TableName() string { + return "t_wg_client" +}