Skip to content

Commit

Permalink
cleanup of unneeded args.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Aug 13, 2024
1 parent 1128509 commit 1b636bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
2 changes: 0 additions & 2 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

### Recommendations

- [ ] Create only one DB connection sitewide, and use .Ping() to test the connection on startup.
- [ ]
- [ ] Use DigitalOcean API to display Estimated Droplet Transfer Pool usage and remaining balance.
https://pkg.go.dev/github.com/digitalocean/godo https://docs.digitalocean.com/reference/api/api-reference/#operation/droplets_get
- [ ] After a successful demozoo/pouet upload, defer a sync for the data to the artifact record.
Expand Down
35 changes: 15 additions & 20 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func main() {
if err := database.Query(db); err != nil {
logger.Errorf("postgres version query: %w", err)
}
if db != nil {
repairs(ctx, db, configs)
}
repairs(ctx, db, configs)
sanityChecks(ctx, configs)
sanityTmpDir()

Expand All @@ -105,20 +103,21 @@ func main() {

go func() {
// get the owner and group of the current process and print them to the console.
if groups, usr, err := helper.Owner(); err != nil {
groups, usr, err := helper.Owner()
if err != nil {
logger.Errorf("owner in main: %s", err)
} else {
clean := slices.DeleteFunc(groups, func(e string) bool {
return e == ""
})
fmt.Fprintf(w, "Running as %s for the groups, %s.\n", usr, strings.Join(clean, ","))
}
clean := slices.DeleteFunc(groups, func(e string) bool {
return e == ""
})
fmt.Fprintf(w, "Running as %s for the groups, %s.\n",
usr, strings.Join(clean, ","))
// get the local IP addresses and print them to the console.
if localIPs, err := configs.Addresses(); err != nil {
localIPs, err := configs.Addresses()
if err != nil {
logger.Errorf("configs addresses in main: %s", err)
} else {
fmt.Fprintf(w, "%s\n", localIPs)
}
fmt.Fprintf(w, "%s\n", localIPs)
}()

// shutdown the web server.
Expand Down Expand Up @@ -249,23 +248,19 @@ func checks(logger *zap.SugaredLogger, readonly bool) {
// repairs is used to fix any known issues with the file assets and the database entries.
// These are skipped if the Production mode environment variable is set to false.
func repairs(ctx context.Context, db *sql.DB, configs config.Config) {
if !configs.ProdMode {
if !configs.ProdMode || db == nil {
return
}
logger := helper.Logger(ctx)
if db == nil {
logger.Errorf("repairs is missing a required parameter")
return
}
if err := configs.RepairAssets(ctx, db); err != nil {
logger.Errorf("asset repairs: %s", err)
}
if err := repairDatabase(ctx, db); err != nil {
err := repairDatabase(ctx, db)
if err != nil {
if errors.Is(err, ErrVer) {
logger.Warnf("A %s, is the database server down?", ErrVer)
} else {
logger.Errorf("repair database could not initialize the database data: %s", err)
}
logger.Errorf("repair database could not initialize the database data: %s", err)
}
}

Expand Down

0 comments on commit 1b636bd

Please sign in to comment.