diff options
| author | Gibheer <gibheer+git@zero-knowledge.org> | 2024-09-05 19:38:25 +0200 | 
|---|---|---|
| committer | Gibheer <gibheer+git@zero-knowledge.org> | 2024-09-05 19:38:25 +0200 | 
| commit | 6ea4d2c82de80efc87708e5e182034b7c6c2019e (patch) | |
| tree | 35c0856a929040216c82153ca62d43b27530a887 /cmd | |
| parent | 6f64eeace1b66639b9380b44e88a8d54850a4306 (diff) | |
lib/pq is out of maintenance for some time now, so switch to the newer
more active library. Looks like it finally stabilized after a long time.
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/moncheck/main.go | 3 | ||||
| -rw-r--r-- | cmd/monfront/checks.go | 6 | ||||
| -rw-r--r-- | cmd/monfront/main.go | 14 | ||||
| -rw-r--r-- | cmd/monwork/main.go | 6 | 
4 files changed, 14 insertions, 15 deletions
| diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index c9d3180..d8f0a74 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -18,6 +18,7 @@ import (  	"time"  	"git.zero-knowledge.org/gibheer/monzero" +	_ "github.com/jackc/pgx/v5/stdlib"  )  var ( @@ -73,7 +74,7 @@ func main() {  		os.Exit(1)  	} -	db, err := sql.Open("postgres", config.DB) +	db, err := sql.Open("pgx", config.DB)  	if err != nil {  		logger.Error("could not open database connection", "error", err)  		os.Exit(1) diff --git a/cmd/monfront/checks.go b/cmd/monfront/checks.go index e6668fd..75af748 100644 --- a/cmd/monfront/checks.go +++ b/cmd/monfront/checks.go @@ -4,8 +4,6 @@ import (  	"database/sql"  	"net/http"  	"time" - -	"github.com/lib/pq"  )  type ( @@ -62,7 +60,7 @@ type (  		State        int  		Output       string  		Inserted     time.Time -		Sent         pq.NullTime +		Sent         sql.NullTime  		NotifierName string  		MappingId    int  	} @@ -91,7 +89,7 @@ func showCheck(con *Context) {  	err := DB.QueryRow(query, id[0]).Scan(&cd.Id, &cd.Name, &cd.Message, &cd.Enabled,  		&cd.Updated, &cd.LastRefresh, &cd.MappingId, &cd.MappingName, &cd.NodeId,  		&cd.NodeName, &cd.NodeMessage, &cd.CommandId, &cd.CommandName, &cd.CommandMessage, -		pq.Array(&cd.CommandLine), pq.Array(&cd.States), &cd.Notice, &cd.NextTime, +		&cd.CommandLine, &cd.States, &cd.Notice, &cd.NextTime,  		&cd.CheckerID, &cd.CheckerName, &cd.CheckerMsg)  	if err != nil && err == sql.ErrNoRows {  		con.w.Header()["Location"] = []string{"/"} diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index f8d8ee7..8943744 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -18,7 +18,7 @@ import (  	"time"  	"github.com/BurntSushi/toml" -	"github.com/lib/pq" +	_ "github.com/jackc/pgx/v5/stdlib"  	"golang.org/x/term"  ) @@ -107,7 +107,7 @@ func main() {  	logger := parseLogger(config) -	db, err := sql.Open("postgres", config.DB) +	db, err := sql.Open("pgx", config.DB)  	if err != nil {  		log.Fatalf("could not open database connection: %s", err)  	} @@ -278,7 +278,7 @@ func checkAction(con *Context) {  	case "disable":  		setClause = "enabled = false, updated = now()"  	case "delete_check": -		if _, err := DB.Exec(`delete from checks where id = any ($1::bigint[])`, pq.Array(checks)); err != nil { +		if _, err := DB.Exec(`delete from checks where id = any ($1::bigint[])`, checks); err != nil {  			con.log.Info("could not delete checks", "checks", checks, "error", err)  			con.Error = "could not delete checks"  			returnError(http.StatusInternalServerError, con, con.w) @@ -321,7 +321,7 @@ func checkAction(con *Context) {  			cn.notifier_id, $2  			from checks_notify cn  			join active_checks ac on cn.check_id = ac.check_id -			where cn.check_id = any ($1::bigint[])`, pq.Array(&checks), &hostname); err != nil { +			where cn.check_id = any ($1::bigint[])`, &checks, &hostname); err != nil {  			con.log.Info("could not acknowledge check", "error", err)  			con.Error = "could not acknowledge check"  			returnError(http.StatusInternalServerError, con, con.w) @@ -334,7 +334,7 @@ func checkAction(con *Context) {  		}  		_, err := DB.Exec(  			"update active_checks set notice = $2 where check_id = any ($1::bigint[]);", -			pq.Array(&checks), +			&checks,  			comment)  		if err != nil {  			con.w.WriteHeader(http.StatusInternalServerError) @@ -346,7 +346,7 @@ func checkAction(con *Context) {  		return  	case "uncomment":  		_, err := DB.Exec(`update active_checks set notice = null where check_id = any($1::bigint[]);`, -			pq.Array(&checks)) +			&checks)  		if err != nil {  			con.Error = "could not uncomment checks"  			returnError(http.StatusInternalServerError, con, con.w) @@ -366,7 +366,7 @@ func checkAction(con *Context) {  	}  	sql := "update " + setTable + " set " + setClause + " where " + whereColumn + " = any($1::bigint[])" -	whereVals = append([]any{pq.Array(&checks)}, whereVals...) +	whereVals = append([]any{&checks}, whereVals...)  	if len(whereFields) > 0 {  		for i, column := range whereFields {  			sql = sql + " and " + column + fmt.Sprintf(" = $%d", i+1) diff --git a/cmd/monwork/main.go b/cmd/monwork/main.go index 4271213..1e8d69f 100644 --- a/cmd/monwork/main.go +++ b/cmd/monwork/main.go @@ -11,7 +11,7 @@ import (  	"text/template"  	"time" -	"github.com/lib/pq" +	_ "github.com/jackc/pgx/v5/stdlib"  )  var ( @@ -42,7 +42,7 @@ func main() {  		log.Fatalf("could not parse check interval: %s", err)  	} -	db, err := sql.Open("postgres", config.DB) +	db, err := sql.Open("pgx", config.DB)  	if err != nil {  		log.Fatalf("could not open database connection: %s", err)  	} @@ -167,7 +167,7 @@ func startConfigGen(db *sql.DB, checkInterval time.Duration) {  			time.Sleep(checkInterval)  			continue  		} -		if _, err := tx.Exec(SQLRefreshActiveCheck, check_id, pq.Array(stringToShellFields(cmd.Bytes()))); err != nil { +		if _, err := tx.Exec(SQLRefreshActiveCheck, check_id, stringToShellFields(cmd.Bytes())); err != nil {  			tx.Rollback()  			log.Printf("could not refresh check '%d': %s", check_id, err)  			continue | 
