diff --git a/.gitignore b/.gitignore index 243b118a..047f55ea 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,8 @@ _cgo_export.* *.exe *.o *.so -# 在此添加你的项目名(如果需要) +panel +panel.exe # 压缩包 # Git 自带压缩,如果这些压缩包里有代码,建议解压后 commit diff --git a/cmd/cli/main.go b/cmd/cli/main.go index d400e5b4..76ae199a 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -17,8 +17,9 @@ along with this program. If not, see . package main import ( - "github.com/TheTNB/panel/internal/bootstrap" _ "time/tzdata" + + "github.com/TheTNB/panel/internal/bootstrap" ) func main() { diff --git a/cmd/web/main.go b/cmd/web/main.go index 8651109c..96b58e19 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -17,8 +17,9 @@ along with this program. If not, see . package main import ( - "github.com/TheTNB/panel/internal/bootstrap" _ "time/tzdata" + + "github.com/TheTNB/panel/internal/bootstrap" ) func main() { diff --git a/go.mod b/go.mod index 500b21b3..17a31dbf 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/go-rat/utils v1.0.3 github.com/go-resty/resty/v2 v2.15.3 github.com/go-sql-driver/mysql v1.8.1 - github.com/golang-module/carbon/v2 v2.3.12 github.com/gookit/color v1.5.4 github.com/gorilla/websocket v1.5.3 github.com/hashicorp/go-version v1.7.0 diff --git a/go.sum b/go.sum index e01a8b11..51ad3f3c 100644 --- a/go.sum +++ b/go.sum @@ -115,8 +115,6 @@ github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAp github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-module/carbon/v2 v2.3.12 h1:VC1DwN1kBwJkh5MjXmTFryjs5g4CWyoM8HAHffZPX/k= -github.com/golang-module/carbon/v2 v2.3.12/go.mod h1:HNsedGzXGuNciZImYP2OMnpiwq/vhIstR/vn45ib5cI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -271,14 +269,9 @@ github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.597 h1:C0GHdLTfikLVoEzfhgPfrZ7LwlG0xiCmk6iwNKE+xs0= diff --git a/internal/apps/postgresql/service.go b/internal/apps/postgresql/service.go index b21fdb51..66e83096 100644 --- a/internal/apps/postgresql/service.go +++ b/internal/apps/postgresql/service.go @@ -3,8 +3,7 @@ package postgresql import ( "fmt" "net/http" - - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/panel" "github.com/TheTNB/panel/internal/service" @@ -94,7 +93,7 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) { return } - time, err := shell.Execf(`echo "select pg_postmaster_start_time();" | su - postgres -c "psql" | sed -n 3p | cut -d'.' -f1`) + start, err := shell.Execf(`echo "select pg_postmaster_start_time();" | su - postgres -c "psql" | sed -n 3p | cut -d'.' -f1`) if err != nil { service.Error(w, http.StatusInternalServerError, "获取PostgreSQL启动时间失败") return @@ -121,7 +120,7 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) { } data := []types.NV{ - {Name: "启动时间", Value: carbon.Parse(time).ToDateTimeString()}, + {Name: "启动时间", Value: start}, {Name: "进程 PID", Value: pid}, {Name: "进程数", Value: process}, {Name: "总连接数", Value: connections}, @@ -133,7 +132,7 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) { // Log 获取日志 func (s *Service) Log(w http.ResponseWriter, r *http.Request) { - log, err := shell.Execf("tail -n 100 %s/server/postgresql/logs/postgresql-%s.log", panel.Root, carbon.Now().ToDateString()) + log, err := shell.Execf("tail -n 100 %s/server/postgresql/logs/postgresql-%s.log", panel.Root, time.Now().Format(time.DateOnly)) if err != nil { service.Error(w, http.StatusInternalServerError, log) return diff --git a/internal/apps/s3fs/service.go b/internal/apps/s3fs/service.go index 11e48a16..010ca651 100644 --- a/internal/apps/s3fs/service.go +++ b/internal/apps/s3fs/service.go @@ -4,9 +4,9 @@ import ( "encoding/json" "net/http" "strings" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/spf13/cast" "github.com/TheTNB/panel/internal/biz" @@ -92,7 +92,7 @@ func (s *Service) Create(w http.ResponseWriter, r *http.Request) { } } - id := carbon.Now().TimestampMilli() + id := time.Now().UnixMicro() password := req.Ak + ":" + req.Sk if err = io.Write("/etc/passwd-s3fs-"+cast.ToString(id), password, 0600); err != nil { service.Error(w, http.StatusInternalServerError, "添加 S3fs 挂载失败") diff --git a/internal/biz/app.go b/internal/biz/app.go index 1cc3d16d..e42f2161 100644 --- a/internal/biz/app.go +++ b/internal/biz/app.go @@ -1,19 +1,19 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/pkg/api" ) type App struct { - ID uint `gorm:"primaryKey" json:"id"` - Slug string `gorm:"not null;unique" json:"slug"` - Version string `gorm:"not null" json:"version"` - Show bool `gorm:"not null" json:"show"` - ShowOrder int `gorm:"not null" json:"show_order"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Slug string `gorm:"not null;unique" json:"slug"` + Version string `gorm:"not null" json:"version"` + Show bool `gorm:"not null" json:"show"` + ShowOrder int `gorm:"not null" json:"show_order"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type AppRepo interface { diff --git a/internal/biz/cache.go b/internal/biz/cache.go index 78ece624..cd3faf75 100644 --- a/internal/biz/cache.go +++ b/internal/biz/cache.go @@ -1,6 +1,6 @@ package biz -import "github.com/golang-module/carbon/v2" +import "time" type CacheKey string @@ -10,10 +10,10 @@ const ( ) type Cache struct { - Key CacheKey `gorm:"primaryKey" json:"key"` - Value string `gorm:"not null" json:"value"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + Key CacheKey `gorm:"primaryKey" json:"key"` + Value string `gorm:"not null" json:"value"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type CacheRepo interface { diff --git a/internal/biz/cert.go b/internal/biz/cert.go index 664a85f5..c3001152 100644 --- a/internal/biz/cert.go +++ b/internal/biz/cert.go @@ -1,25 +1,25 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/acme" ) type Cert struct { - ID uint `gorm:"primaryKey" json:"id"` - AccountID uint `gorm:"not null" json:"account_id"` // 关联的 ACME 账户 ID - WebsiteID uint `gorm:"not null" json:"website_id"` // 关联的网站 ID - DNSID uint `gorm:"not null" json:"dns_id"` // 关联的 DNS ID - Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096) - Domains []string `gorm:"not null;serializer:json" json:"domains"` - AutoRenew bool `gorm:"not null" json:"auto_renew"` // 自动续签 - CertURL string `gorm:"not null" json:"cert_url"` // 证书 URL (续签时使用) - Cert string `gorm:"not null" json:"cert"` // 证书内容 - Key string `gorm:"not null" json:"key"` // 私钥内容 - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + AccountID uint `gorm:"not null" json:"account_id"` // 关联的 ACME 账户 ID + WebsiteID uint `gorm:"not null" json:"website_id"` // 关联的网站 ID + DNSID uint `gorm:"not null" json:"dns_id"` // 关联的 DNS ID + Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096) + Domains []string `gorm:"not null;serializer:json" json:"domains"` + AutoRenew bool `gorm:"not null" json:"auto_renew"` // 自动续签 + CertURL string `gorm:"not null" json:"cert_url"` // 证书 URL (续签时使用) + Cert string `gorm:"not null" json:"cert"` // 证书内容 + Key string `gorm:"not null" json:"key"` // 私钥内容 + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` Website *Website `gorm:"foreignKey:WebsiteID" json:"website"` Account *CertAccount `gorm:"foreignKey:AccountID" json:"account"` diff --git a/internal/biz/cert_account.go b/internal/biz/cert_account.go index 80482ee3..c74385fd 100644 --- a/internal/biz/cert_account.go +++ b/internal/biz/cert_account.go @@ -1,21 +1,21 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" ) type CertAccount struct { - ID uint `gorm:"primaryKey" json:"id"` - Email string `gorm:"not null" json:"email"` - CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass) - Kid string `gorm:"not null" json:"kid"` - HmacEncoded string `gorm:"not null" json:"hmac_encoded"` - PrivateKey string `gorm:"not null" json:"private_key"` - KeyType string `gorm:"not null" json:"key_type"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Email string `gorm:"not null" json:"email"` + CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass) + Kid string `gorm:"not null" json:"kid"` + HmacEncoded string `gorm:"not null" json:"hmac_encoded"` + PrivateKey string `gorm:"not null" json:"private_key"` + KeyType string `gorm:"not null" json:"key_type"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` Certs []*Cert `gorm:"foreignKey:AccountID" json:"-"` } diff --git a/internal/biz/cert_dns.go b/internal/biz/cert_dns.go index df84a737..9f4a2295 100644 --- a/internal/biz/cert_dns.go +++ b/internal/biz/cert_dns.go @@ -1,19 +1,19 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/acme" ) type CertDNS struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null" json:"name"` // 备注名称 - Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, tencent, aliyun, cloudflare) - Data acme.DNSParam `gorm:"not null;serializer:json" json:"dns_param"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"not null" json:"name"` // 备注名称 + Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, tencent, aliyun, cloudflare) + Data acme.DNSParam `gorm:"not null;serializer:json" json:"dns_param"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` Certs []*Cert `gorm:"foreignKey:DNSID" json:"-"` } diff --git a/internal/biz/cron.go b/internal/biz/cron.go index 46b982f1..433638ad 100644 --- a/internal/biz/cron.go +++ b/internal/biz/cron.go @@ -1,21 +1,21 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" ) type Cron struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` - Status bool `gorm:"not null" json:"status"` - Type string `gorm:"not null" json:"type"` - Time string `gorm:"not null" json:"time"` - Shell string `gorm:"not null" json:"shell"` - Log string `gorm:"not null" json:"log"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"not null;unique" json:"name"` + Status bool `gorm:"not null" json:"status"` + Type string `gorm:"not null" json:"type"` + Time string `gorm:"not null" json:"time"` + Shell string `gorm:"not null" json:"shell"` + Log string `gorm:"not null" json:"log"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type CronRepo interface { diff --git a/internal/biz/database.go b/internal/biz/database.go index f43ac4ab..44ebada1 100644 --- a/internal/biz/database.go +++ b/internal/biz/database.go @@ -1,16 +1,16 @@ package biz -import "github.com/golang-module/carbon/v2" +import "time" type Database struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` - Type string `gorm:"not null" json:"type"` - Host string `gorm:"not null" json:"host"` - Port int `gorm:"not null" json:"port"` - Username string `gorm:"not null" json:"username"` - Password string `gorm:"not null" json:"password"` - Remark string `gorm:"not null" json:"remark"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"not null;unique" json:"name"` + Type string `gorm:"not null" json:"type"` + Host string `gorm:"not null" json:"host"` + Port int `gorm:"not null" json:"port"` + Username string `gorm:"not null" json:"username"` + Password string `gorm:"not null" json:"password"` + Remark string `gorm:"not null" json:"remark"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } diff --git a/internal/biz/monitor.go b/internal/biz/monitor.go index cc60ac6f..dff495c6 100644 --- a/internal/biz/monitor.go +++ b/internal/biz/monitor.go @@ -1,7 +1,7 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/tools" @@ -10,13 +10,13 @@ import ( type Monitor struct { ID uint `gorm:"primaryKey" json:"id"` Info tools.MonitoringInfo `gorm:"not null;serializer:json" json:"info"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type MonitorRepo interface { GetSetting() (*request.MonitorSetting, error) UpdateSetting(setting *request.MonitorSetting) error Clear() error - List(start, end carbon.Carbon) ([]*Monitor, error) + List(start, end time.Time) ([]*Monitor, error) } diff --git a/internal/biz/setting.go b/internal/biz/setting.go index 589dc784..e4860d7c 100644 --- a/internal/biz/setting.go +++ b/internal/biz/setting.go @@ -1,7 +1,7 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" ) @@ -23,11 +23,11 @@ const ( ) type Setting struct { - ID uint `gorm:"primaryKey" json:"id"` - Key SettingKey `gorm:"not null;unique" json:"key"` - Value string `gorm:"not null" json:"value"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Key SettingKey `gorm:"not null;unique" json:"key"` + Value string `gorm:"not null" json:"value"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type SettingRepo interface { diff --git a/internal/biz/task.go b/internal/biz/task.go index b76c0a72..35a8d586 100644 --- a/internal/biz/task.go +++ b/internal/biz/task.go @@ -1,6 +1,6 @@ package biz -import "github.com/golang-module/carbon/v2" +import "time" type TaskStatus string @@ -12,13 +12,13 @@ const ( ) type Task struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;index" json:"name"` - Status TaskStatus `gorm:"not null;default:'waiting'" json:"status"` - Shell string `gorm:"not null" json:"-"` - Log string `gorm:"not null" json:"log"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"not null;index" json:"name"` + Status TaskStatus `gorm:"not null;default:'waiting'" json:"status"` + Shell string `gorm:"not null" json:"-"` + Log string `gorm:"not null" json:"log"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type TaskRepo interface { diff --git a/internal/biz/user.go b/internal/biz/user.go index a6fad865..9a038860 100644 --- a/internal/biz/user.go +++ b/internal/biz/user.go @@ -1,18 +1,19 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" + "gorm.io/gorm" ) type User struct { - ID uint `gorm:"primaryKey" json:"id"` - Username string `gorm:"not null;unique" json:"username"` - Password string `gorm:"not null" json:"password"` - Email string `gorm:"not null" json:"email"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` + ID uint `gorm:"primaryKey" json:"id"` + Username string `gorm:"not null;unique" json:"username"` + Password string `gorm:"not null" json:"password"` + Email string `gorm:"not null" json:"email"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` } type UserRepo interface { diff --git a/internal/biz/website.go b/internal/biz/website.go index 7f5edba6..e8abd7cf 100644 --- a/internal/biz/website.go +++ b/internal/biz/website.go @@ -1,22 +1,22 @@ package biz import ( - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/types" ) type Website struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `gorm:"not null;unique" json:"name"` - Status bool `gorm:"not null;default:true" json:"status"` - Path string `gorm:"not null" json:"path"` - PHP int `gorm:"not null" json:"php"` - SSL bool `gorm:"not null" json:"ssl"` - Remark string `gorm:"not null" json:"remark"` - CreatedAt carbon.DateTime `json:"created_at"` - UpdatedAt carbon.DateTime `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"not null;unique" json:"name"` + Status bool `gorm:"not null;default:true" json:"status"` + Path string `gorm:"not null" json:"path"` + PHP int `gorm:"not null" json:"php"` + SSL bool `gorm:"not null" json:"ssl"` + Remark string `gorm:"not null" json:"remark"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"` } diff --git a/internal/bootstrap/conf.go b/internal/bootstrap/conf.go index 61db330c..3ae5c05a 100644 --- a/internal/bootstrap/conf.go +++ b/internal/bootstrap/conf.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/golang-module/carbon/v2" "github.com/knadh/koanf/parsers/yaml" "github.com/knadh/koanf/providers/file" "github.com/knadh/koanf/v2" @@ -30,10 +29,4 @@ func initGlobal() { panic(fmt.Sprintf("failed to load timezone: %v", err)) } time.Local = loc - carbon.SetDefault(carbon.Default{ - Layout: carbon.DateTimeLayout, - Timezone: carbon.PRC, - WeekStartsAt: carbon.Sunday, - Locale: "zh-CN", - }) } diff --git a/internal/data/cron.go b/internal/data/cron.go index 85a9d71c..7d947975 100644 --- a/internal/data/cron.go +++ b/internal/data/cron.go @@ -6,8 +6,7 @@ import ( "path/filepath" "regexp" "strconv" - - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/http/request" @@ -104,7 +103,7 @@ panel cutoff ${name} ${save} if !io.Exists(shellLogDir) { return errors.New("计划任务日志目录不存在") } - shellFile := strconv.Itoa(int(carbon.Now().Timestamp())) + str.RandomString(16) + shellFile := strconv.Itoa(int(time.Now().Unix())) + str.RandomString(16) if err := io.Write(filepath.Join(shellDir, shellFile+".sh"), script, 0700); err != nil { return errors.New(err.Error()) } diff --git a/internal/data/monitor.go b/internal/data/monitor.go index 5d677b89..f7088818 100644 --- a/internal/data/monitor.go +++ b/internal/data/monitor.go @@ -2,8 +2,8 @@ package data import ( "errors" + "time" - "github.com/golang-module/carbon/v2" "github.com/spf13/cast" "github.com/TheTNB/panel/internal/biz" @@ -53,7 +53,7 @@ func (r monitorRepo) Clear() error { return panel.Orm.Delete(&biz.Monitor{}).Error } -func (r monitorRepo) List(start, end carbon.Carbon) ([]*biz.Monitor, error) { +func (r monitorRepo) List(start, end time.Time) ([]*biz.Monitor, error) { var monitors []*biz.Monitor if err := panel.Orm.Where("created_at BETWEEN ? AND ?", start, end).Find(&monitors).Error; err != nil { return nil, err diff --git a/internal/route/http.go b/internal/route/http.go index 94091126..84280873 100644 --- a/internal/route/http.go +++ b/internal/route/http.go @@ -6,10 +6,11 @@ import ( "strings" "time" + "github.com/go-chi/chi/v5" + "github.com/TheTNB/panel/internal/embed" "github.com/TheTNB/panel/internal/http/middleware" "github.com/TheTNB/panel/internal/service" - "github.com/go-chi/chi/v5" ) func Http(r chi.Router) { diff --git a/internal/service/container.go b/internal/service/container.go index 1653ba6d..b5d54631 100644 --- a/internal/service/container.go +++ b/internal/service/container.go @@ -3,9 +3,9 @@ package service import ( "net/http" "strings" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/data" @@ -41,7 +41,7 @@ func (s *ContainerService) List(w http.ResponseWriter, r *http.Request) { "image": item.Image, "image_id": item.ImageID, "command": item.Command, - "created": carbon.CreateFromTimestamp(item.Created).ToDateTimeString(), + "created": time.Unix(item.Created, 0).Format(time.DateTime), "ports": item.Ports, "labels": item.Labels, "state": item.State, diff --git a/internal/service/container_image.go b/internal/service/container_image.go index 2cba1daf..4f907d3c 100644 --- a/internal/service/container_image.go +++ b/internal/service/container_image.go @@ -2,9 +2,9 @@ package service import ( "net/http" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/data" @@ -35,7 +35,7 @@ func (s *ContainerImageService) List(w http.ResponseWriter, r *http.Request) { for _, item := range paged { items = append(items, map[string]any{ "id": item.ID, - "created": carbon.CreateFromTimestamp(item.Created).ToDateTimeString(), + "created": time.Unix(item.Created, 0).Format(time.DateTime), "containers": item.Containers, "size": str.FormatBytes(float64(item.Size)), "labels": item.Labels, diff --git a/internal/service/container_network.go b/internal/service/container_network.go index c5b7d286..343be3f3 100644 --- a/internal/service/container_network.go +++ b/internal/service/container_network.go @@ -2,9 +2,9 @@ package service import ( "net/http" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/data" @@ -57,7 +57,7 @@ func (s *ContainerNetworkService) List(w http.ResponseWriter, r *http.Request) { "driver": item.IPAM.Driver, "options": item.IPAM.Options, }, - "created": carbon.CreateFromStdTime(item.Created).ToDateTimeString(), + "created": item.Created.Format(time.DateTime), }) } diff --git a/internal/service/container_volume.go b/internal/service/container_volume.go index 6bbe8704..d02a6e9c 100644 --- a/internal/service/container_volume.go +++ b/internal/service/container_volume.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/data" @@ -42,7 +41,7 @@ func (s *ContainerVolumeService) List(w http.ResponseWriter, r *http.Request) { } items = append(items, map[string]any{ "id": item.Name, - "created": carbon.Parse(item.CreatedAt).ToDateTimeString(), + "created": item.CreatedAt, "driver": item.Driver, "mount": item.Mountpoint, "labels": item.Labels, diff --git a/internal/service/file.go b/internal/service/file.go index 4cb7e363..5cce209d 100644 --- a/internal/service/file.go +++ b/internal/service/file.go @@ -10,9 +10,9 @@ import ( "strconv" "strings" "syscall" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/io" @@ -217,7 +217,7 @@ func (s *FileService) Info(w http.ResponseWriter, r *http.Request) { "mode_str": info.Mode().String(), "mode": fmt.Sprintf("%04o", info.Mode().Perm()), "dir": info.IsDir(), - "modify": carbon.CreateFromStdTime(info.ModTime()).ToDateTimeString(), + "modify": info.ModTime().Format(time.DateTime), }) } @@ -336,7 +336,7 @@ func (s *FileService) List(w http.ResponseWriter, r *http.Request) { "symlink": io.IsSymlink(info.Mode()), "link": io.GetSymlink(filepath.Join(req.Path, info.Name())), "dir": info.IsDir(), - "modify": carbon.CreateFromStdTime(info.ModTime()).ToDateTimeString(), + "modify": info.ModTime().Format(time.DateTime), }) } diff --git a/internal/service/file_windows.go b/internal/service/file_windows.go index d2b34f4e..1f2280d9 100644 --- a/internal/service/file_windows.go +++ b/internal/service/file_windows.go @@ -11,9 +11,9 @@ import ( "path/filepath" "strconv" "strings" + "time" "github.com/go-rat/chix" - "github.com/golang-module/carbon/v2" "github.com/TheTNB/panel/internal/http/request" "github.com/TheTNB/panel/pkg/io" @@ -217,7 +217,7 @@ func (s *FileService) Info(w http.ResponseWriter, r *http.Request) { "mode_str": info.Mode().String(), "mode": fmt.Sprintf("%04o", info.Mode().Perm()), "dir": info.IsDir(), - "modify": carbon.CreateFromStdTime(info.ModTime()).ToDateTimeString(), + "modify": info.ModTime().Format(time.DateTime), }) } @@ -335,7 +335,7 @@ func (s *FileService) List(w http.ResponseWriter, r *http.Request) { "symlink": io.IsSymlink(info.Mode()), "link": io.GetSymlink(filepath.Join(req.Path, info.Name())), "dir": info.IsDir(), - "modify": carbon.CreateFromStdTime(info.ModTime()).ToDateTimeString(), + "modify": info.ModTime().Format(time.DateTime), }) } diff --git a/internal/service/monitor.go b/internal/service/monitor.go index 38b60b0e..98af3616 100644 --- a/internal/service/monitor.go +++ b/internal/service/monitor.go @@ -3,8 +3,7 @@ package service import ( "fmt" "net/http" - - "github.com/golang-module/carbon/v2" + "time" "github.com/TheTNB/panel/internal/biz" "github.com/TheTNB/panel/internal/data" @@ -65,7 +64,7 @@ func (s *MonitorService) List(w http.ResponseWriter, r *http.Request) { return } - monitors, err := s.monitorRepo.List(carbon.CreateFromTimestampMilli(req.Start), carbon.CreateFromTimestampMilli(req.End)) + monitors, err := s.monitorRepo.List(time.UnixMilli(req.Start), time.UnixMilli(req.End)) if err != nil { Error(w, http.StatusInternalServerError, err.Error()) return @@ -98,7 +97,7 @@ func (s *MonitorService) List(w http.ResponseWriter, r *http.Request) { bytesSent2 += net.BytesSent bytesRecv2 += net.BytesRecv } - list.Times = append(list.Times, monitor.CreatedAt.ToDateTimeString()) + list.Times = append(list.Times, monitor.CreatedAt.Format(time.DateTime)) list.Load.Load1 = append(list.Load.Load1, monitor.Info.Load.Load1) list.Load.Load5 = append(list.Load.Load5, monitor.Info.Load.Load5) list.Load.Load15 = append(list.Load.Load15, monitor.Info.Load.Load15) diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go index 6216feb6..6764f137 100644 --- a/pkg/tools/tools.go +++ b/pkg/tools/tools.go @@ -9,7 +9,6 @@ import ( "time" "github.com/go-resty/resty/v2" - "github.com/golang-module/carbon/v2" "github.com/gookit/color" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/disk" @@ -371,7 +370,7 @@ func UpdatePanel(panelInfo PanelInfo) error { color.Greenln("备份面板数据...") // 备份面板 - if err := io.Compress([]string{"/www/panel"}, fmt.Sprintf("/www/backup/panel/panel-%s.zip", carbon.Now().ToShortDateTimeString()), io.Zip); err != nil { + if err := io.Compress([]string{"/www/panel"}, fmt.Sprintf("/www/backup/panel/panel-%s.zip", time.Now().Format("20060102150405")), io.Zip); err != nil { color.Redln("备份面板失败") return err }