-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
418 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package data | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/golang-module/carbon/v2" | ||
"github.com/spf13/cast" | ||
|
||
"github.com/TheTNB/panel/internal/app" | ||
"github.com/TheTNB/panel/internal/biz" | ||
"github.com/TheTNB/panel/internal/http/request" | ||
) | ||
|
||
type monitorRepo struct { | ||
settingRepo biz.SettingRepo | ||
} | ||
|
||
func NewMonitorRepo() biz.MonitorRepo { | ||
return &monitorRepo{ | ||
settingRepo: NewSettingRepo(), | ||
} | ||
} | ||
|
||
func (r monitorRepo) GetSetting() (*request.MonitorSetting, error) { | ||
monitor, err := r.settingRepo.Get(biz.SettingKeyMonitor) | ||
if err != nil { | ||
return nil, err | ||
} | ||
monitorDays, err := r.settingRepo.Get(biz.SettingKeyMonitorDays) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
setting := new(request.MonitorSetting) | ||
setting.Enabled = cast.ToBool(monitor) | ||
setting.Days = cast.ToInt(monitorDays) | ||
|
||
return setting, nil | ||
} | ||
|
||
func (r monitorRepo) UpdateSetting(setting *request.MonitorSetting) error { | ||
if err := r.settingRepo.Set(biz.SettingKeyMonitor, cast.ToString(setting.Enabled)); err != nil { | ||
return err | ||
} | ||
if err := r.settingRepo.Set(biz.SettingKeyMonitorDays, cast.ToString(setting.Days)); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r monitorRepo) Clear() error { | ||
return app.Orm.Delete(&biz.Monitor{}).Error | ||
} | ||
|
||
func (r monitorRepo) List(start, end carbon.Carbon) ([]*biz.Monitor, error) { | ||
var monitors []*biz.Monitor | ||
if err := app.Orm.Where("created_at BETWEEN ? AND ?", start, end).Find(&monitors).Error; err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(monitors) == 0 { | ||
return nil, errors.New("没有找到数据") | ||
} | ||
|
||
return monitors, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package request | ||
|
||
type MonitorSetting struct { | ||
Enabled bool `json:"enabled"` | ||
Days int `json:"days"` | ||
} | ||
|
||
type MonitorList struct { | ||
Start int64 `json:"start"` | ||
End int64 `json:"end"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package request | ||
|
||
type PanelSetting struct { | ||
Name string `json:"name"` | ||
Language string `json:"language"` | ||
Entrance string `json:"entrance"` | ||
WebsitePath string `json:"website_path"` | ||
BackupPath string `json:"backup_path"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
Email string `json:"email"` | ||
Port string `json:"port"` | ||
HTTPS bool `json:"https"` | ||
Cert string `json:"cert"` | ||
Key string `json:"key"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package request | ||
|
||
type SystemctlService struct { | ||
Service string `json:"service"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.