refactor: Fix linter errors by auto-apply

- Apply automated linter fixes
- Manually reformat fields in model/service.go
- Resolve code complexity issues
This commit is contained in:
2025-11-04 19:59:17 +03:00
parent 180a5c2a90
commit fc8b723114
11 changed files with 60 additions and 32 deletions

16
main.go
View File

@@ -27,16 +27,19 @@ func main() {
if appArgs.Migration != nil && appArgs.Migration.Create != nil {
runMigrationCreateCommand()
return
}
if appArgs.Server != nil {
runServerCommand()
return
}
if appArgs.Docs != nil {
runDocumentationCommand()
return
}
}
@@ -57,11 +60,13 @@ func runServerCommand() {
func runDocumentationCommand() {
if appArgs.Docs.Generate != nil {
runDocsGenerationCommand()
return
}
if appArgs.Docs.Serve != nil {
runDocsServingCommand()
return
}
}
@@ -70,6 +75,7 @@ func runDocsGenerationCommand() {
documentate, err := router.Documentate()
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
@@ -83,6 +89,7 @@ func runDocsGenerationCommand() {
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
@@ -90,14 +97,17 @@ func runDocsGenerationCommand() {
_, err = os.Stdout.Write(file)
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
return
}
err = os.WriteFile(appArgs.Docs.Generate.Out, file, os.ModeAppend)
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
}
@@ -106,18 +116,21 @@ func runDocsServingCommand() {
documentate, err := router.Documentate()
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
docsJson, err := documentate.MarshalJSON()
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
html, err := htmlFolder.ReadFile("html/redoc.html")
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
@@ -127,6 +140,7 @@ func runDocsServingCommand() {
_, err = c.Writer.Write(docsJson)
if err != nil {
c.Writer.WriteHeader(http.StatusInternalServerError)
return
}
})
@@ -136,12 +150,14 @@ func runDocsServingCommand() {
_, err = c.Writer.Write(html)
if err != nil {
c.Writer.WriteHeader(http.StatusInternalServerError)
return
}
})
if err = g.Run(fmt.Sprintf(":%s", appArgs.Docs.Serve.Port)); err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(err)
return
}
}

View File

@@ -7,33 +7,34 @@ type HTTPConfig struct {
Headers map[string]string `json:"headers"`
}
// ServiceTypeCheckConfig
// MaxFails - max "ping" fails, after with the service marked as unavailable
// Interval - interval between "ping" in seconds
// Timeout - interval after which the task will be canceled
type ServiceTypeCheckConfig struct {
Version string `json:"version"`
HTTPConfig *HTTPConfig `json:"httpConfig"`
// MaxFails - max "ping" fails, after with the service marked as unavailable
MaxFails uint8 `json:"maxFails"`
// Interval - interval between "ping" in seconds
Interval uint64 `json:"interval"`
// Timeout - interval after which the task will be canceled
Timeout uint64 `json:"timeout"`
MaxFails uint8 `json:"maxFails"`
Interval uint64 `json:"interval"`
Timeout uint64 `json:"timeout"`
}
// Service
// ID Unique ID for entity
// Name Human-readable service name
// Description Human-readable service description
// Host to check, for example 192.168.1.44 or https://google.com
// Type for check, for now is TCP or HTTP or something else
type Service struct {
// Unique ID for entity
ID uint64 `gorm:"primary_key;auto_increment" json:"id"`
// Human-readable service name
Name string `gorm:"size:255;not null" json:"name"`
// Human-readable service description
Description string `gorm:"size:255" json:"description"`
PublicDescription string `gorm:"size:255" json:"publicDescription"`
Public *bool `gorm:"default:false" json:"public"`
// Host to check, for example 192.168.1.44 or https://google.com
Host string `gorm:"size:255;not null" json:"host"`
// Type for check, for now is TCP or HTTP or something else
Type string `gorm:"size:255;not null" json:"type"`
Config *ServiceTypeCheckConfig `gorm:"serializer:json;column:type_config" json:"typeConfig"`
Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"`
ID uint64 `gorm:"primary_key;auto_increment" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
Description string `gorm:"size:255" json:"description"`
PublicDescription string `gorm:"size:255" json:"publicDescription"`
Public *bool `gorm:"default:false" json:"public"`
Host string `gorm:"size:255;not null" json:"host"`
Type string `gorm:"size:255;not null" json:"type"`
Config *ServiceTypeCheckConfig `gorm:"serializer:json;column:type_config" json:"typeConfig"`
Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"`
}
func (Service) TableName() string {

View File

@@ -18,8 +18,8 @@ const (
type Status struct {
ID uint64 `gorm:"primary_key;auto_increment" json:"-"`
ServiceID uint64 `json:"-"`
Status StatusCode `gorm:"size:255;not null" json:"status"`
Description *string `gorm:"size:255" json:"description"`
Status StatusCode `gorm:"size:255;not null" json:"status"`
Description *string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"createdAt"`
ResponseTime uint64 `json:"responseTime"`
}

View File

@@ -3,7 +3,7 @@ package args
import "git.ostiwe.com/ostiwe-com/status/version"
type ServerCmd struct {
Port string `arg:"-p,--port,env:APP_PORT" help:"Port to listen on" default:"8080"`
Port string `arg:"-p,--port,env:APP_PORT" default:"8080" help:"Port to listen on"`
}
type MigrationCreate struct {
@@ -15,22 +15,22 @@ type Migration struct {
}
type ServerDocumentationCmd struct {
Port string `arg:"-p,--port,env:APP_PORT_DOCS" help:"Port to listen on" default:"8081"`
Port string `arg:"-p,--port,env:APP_PORT_DOCS" default:"8081" help:"Port to listen on"`
}
type GenerateDocumentationCmd struct {
Format string `arg:"--format,-f" help:"Set output format (json, yaml)" default:"yaml"`
Out string `arg:"--out,-o" help:"Output file name (or stdout)" default:"stdout"`
Format string `arg:"--format,-f" default:"yaml" help:"Set output format (json, yaml)"`
Out string `arg:"--out,-o" default:"stdout" help:"Output file name (or stdout)"`
}
type DocsCmd struct {
Serve *ServerDocumentationCmd `arg:"subcommand:serve" help:"Generate and serve the documentation server"`
Serve *ServerDocumentationCmd `arg:"subcommand:serve" help:"Generate and serve the documentation server"`
Generate *GenerateDocumentationCmd `arg:"subcommand:generate" help:"Generate documentation to file"`
}
type AppArgs struct {
Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"`
Docs *DocsCmd `arg:"subcommand:docs" help:"Generate documentation to file or run documentation server"`
Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"`
Docs *DocsCmd `arg:"subcommand:docs" help:"Generate documentation to file or run documentation server"`
Migration *Migration `arg:"subcommand:migration" help:"Migration utils"`
}

View File

@@ -58,11 +58,13 @@ func (r readyResponseErr) Send(response http.ResponseWriter) error {
func (r responseErrBuilder) WithTrace(s string) ResponseErrBuilder {
r.trace = s
return r
}
func (r responseErrBuilder) WithStatusCode(i int) ResponseErrBuilder {
r.status = i
return r
}
@@ -72,11 +74,13 @@ func NewResponseErrBuilder() ResponseErrBuilder {
func (r responseErrBuilder) WithDetails(m map[string]any) ResponseErrBuilder {
r.details = m
return r
}
func (r responseErrBuilder) WithMessage(s string) ResponseErrBuilder {
r.message = s
return r
}

View File

@@ -26,6 +26,7 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc {
Send(ginCtx)
if sendErr != nil {
ginCtx.Writer.WriteHeader(http.StatusInternalServerError)
return
}
@@ -41,6 +42,7 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc {
Send(ginCtx)
if sendErr != nil {
ginCtx.Writer.WriteHeader(http.StatusInternalServerError)
return
}

View File

@@ -30,6 +30,7 @@ func (c *Controller) Handler() gin.HandlerFunc {
_, err := ginCtx.Writer.Write([]byte("pong"))
if err != nil {
log.Global.Get(log.SERVER).Error(err)
return
}
}

View File

@@ -23,6 +23,7 @@ func SetUserFromJWT() gin.HandlerFunc {
subject, err := token.Claims.GetSubject()
if err != nil {
c.Writer.WriteHeader(http.StatusUnauthorized)
return
}

View File

@@ -89,7 +89,6 @@ func Documentate() (*openapi3.Spec, error) {
if err != nil {
return nil, err
}
}
return reflector.Spec, nil

View File

@@ -18,6 +18,7 @@ func Run(serverArgs *args.ServerCmd) {
connect, err := db.Connect()
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed connect to database: %v", err))
return
}
@@ -26,6 +27,7 @@ func Run(serverArgs *args.ServerCmd) {
scheduler.GlobalAppScheduler, err = scheduler.NewAppScheduler()
if err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create scheduler: %v", err))
return
}
@@ -34,11 +36,13 @@ func Run(serverArgs *args.ServerCmd) {
if err = service.GlobalCheckService.RegisterTasks(context.Background()); err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create observe jobs: %v", err))
return
}
if err = scheduler.GlobalAppScheduler.StartJobs(); err != nil {
appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed start jobs: %v", err))
return
}

View File

@@ -33,7 +33,6 @@ func PublicServices(items ...model.Service) []dto.PublicService {
}
wg.Wait()
}
return result
@@ -57,6 +56,7 @@ func PublicService(item model.Service) dto.PublicService {
}
slices.Reverse(statuses)
return dto.PublicService{
ID: int(item.ID),
Name: item.Name,