Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/api/handle_databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func handleCreateDatabase(w http.ResponseWriter, r *http.Request) {
renderErr(w, err)
return
}
defer r.Body.Close()
defer func() { _ = r.Body.Close() }()

if err := admin.CreateDatabase(ctx, conn, input.Name); err != nil {
renderErr(w, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/handle_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func handleCreateUser(w http.ResponseWriter, r *http.Request) {
renderErr(w, err)
return
}
defer r.Body.Close()
defer func() { _ = r.Body.Close() }()

err = admin.CreateUser(ctx, conn, input.Username, input.Password)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"errors"
"net/http"

"log"

"github.com/jackc/pgconn"
"github.com/jackc/pgx/v5"
)

func renderJSON(w http.ResponseWriter, data interface{}, status int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)
if err := json.NewEncoder(w).Encode(data); err != nil {
log.Printf("failed to write json response: %s", err)
}
}

func renderErr(w http.ResponseWriter, err error) {
Expand Down
9 changes: 7 additions & 2 deletions internal/flycheck/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -96,10 +97,14 @@ func handleCheckResponse(w http.ResponseWriter, suite *check.CheckSuite, raw boo
handleError(w, errors.New(result))
return
}
io.WriteString(w, result)
if _, err := io.WriteString(w, result); err != nil {
log.Printf("failed to handle check response: %s", err)
}
}

func handleError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, err.Error())
if _, err := io.WriteString(w, err.Error()); err != nil {
log.Printf("failed to handle check error: %s", err)
}
}
4 changes: 2 additions & 2 deletions internal/flycheck/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func CheckPostgreSQL(ctx context.Context, checks *check.CheckSuite) (*check.Chec

// Cleanup connections
checks.OnCompletion = func() {
localConn.Close(ctx)
repConn.Close(ctx)
_ = localConn.Close(ctx)
_ = repConn.Close(ctx)
}

checks.AddCheck("connections", func() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/flycheck/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func PostgreSQLRole(ctx context.Context, checks *check.CheckSuite) (*check.Check

// Cleanup connections
checks.OnCompletion = func() {
conn.Close(ctx)
_ = conn.Close(ctx)
}

checks.AddCheck("role", func() (string, error) {
Expand Down
5 changes: 4 additions & 1 deletion internal/flycheck/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ func checkPressure(name string) (string, error) {
return "", err
}

fmt.Sscanf(
_, err = fmt.Sscanf(
string(raw),
"some avg10=%f avg60=%f avg300=%f total=%f",
&avg10, &avg60, &avg300, &counter,
)
if err != nil {
return "", err
}

avg10Dur, err := pressureToDuration(avg10, 10.0)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions internal/flypg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ func writeInternalConfigFile(c Config) error {

for key, value := range internal {
entry := fmt.Sprintf("%s = %v\n", key, value)
file.Write([]byte(entry))
if _, err := file.Write([]byte(entry)); err != nil {
return fmt.Errorf("failed to write to file: %s", err)
}
}

if err := file.Sync(); err != nil {
Expand All @@ -169,7 +171,9 @@ func writeUserConfigFile(c Config) error {

for key, value := range c.UserConfig() {
entry := fmt.Sprintf("%s = %v\n", key, value)
file.Write([]byte(entry))
if _, err := file.Write([]byte(entry)); err != nil {
return fmt.Errorf("failed to write to file: %s", err)
}
}

if err := file.Sync(); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions internal/flypg/readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

const (
readOnlyLockFile = "/data/readonly.lock"
readOnlyEnabled = "on"
readOnlyDisabled = "off"

ReadOnlyStateEndpoint = "commands/admin/readonly/state"
BroadcastEnableEndpoint = "commands/admin/readonly/enable"
Expand Down
5 changes: 4 additions & 1 deletion internal/flypg/zombie.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ func handleZombieLock(ctx context.Context, n *Node) error {
}

// Ensure the single instance created with the --force-rewind process is cleaned up properly.
utils.RunCommand("pg_ctl -D /data/postgresql/ stop", "postgres")
_, err = utils.RunCommand("pg_ctl -D /data/postgresql/ stop", "postgres")
if err != nil {
return fmt.Errorf("failed to stop postgres: %s", err)
}
} else {
// TODO - Provide link to documention on how to address this
fmt.Println("Zombie lock file does not contain a hostname.")
Expand Down
4 changes: 2 additions & 2 deletions internal/supervisor/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (m *multiOutput) PipeOutput(proc *process) {

func (m *multiOutput) ClosePipe(proc *process) {
if pipe := m.pipes[proc]; pipe != nil {
pipe.pty.Close()
pipe.tty.Close()
_ = pipe.pty.Close()
_ = pipe.tty.Close()
}
}

Expand Down