Update to new shutdowner version

pull/7/head
Jan-Lukas Else 1 year ago
parent 4bbb1a29b1
commit 10ab12764a
  1. 17
      database.go
  2. 2
      go.mod
  3. 4
      go.sum
  4. 6
      healthcheck.go
  5. 8
      main.go

@ -1,7 +1,6 @@
package main
import (
"context"
"database/sql"
"errors"
"log"
@ -15,8 +14,6 @@ import (
type database struct {
db *sql.DB
c context.Context
cf context.CancelFunc
stmts map[string]*sql.Stmt
g singleflight.Group
pc singleflight.Group
@ -103,12 +100,9 @@ func (a *goBlog) openDatabase(file string, logging bool) (*database, error) {
if err != nil {
return nil, err
}
c, cf := context.WithCancel(context.Background())
return &database{
db: db,
stmts: map[string]*sql.Stmt{},
c: c,
cf: cf,
}, nil
}
@ -126,7 +120,6 @@ func (db *database) dump(file string) {
}
func (db *database) close() error {
db.cf()
return db.db.Close()
}
@ -136,7 +129,7 @@ func (db *database) prepare(query string) (*sql.Stmt, error) {
if ok && stmt != nil {
return stmt, nil
}
stmt, err := db.db.PrepareContext(db.c, query)
stmt, err := db.db.Prepare(query)
if err != nil {
return nil, err
}
@ -154,12 +147,12 @@ func (db *database) exec(query string, args ...interface{}) (sql.Result, error)
if err != nil {
return nil, err
}
return stmt.ExecContext(db.c, args...)
return stmt.Exec(args...)
}
func (db *database) execMulti(query string, args ...interface{}) (sql.Result, error) {
// Can't prepare the statement
return db.db.ExecContext(db.c, query, args...)
return db.db.Exec(query, args...)
}
func (db *database) query(query string, args ...interface{}) (*sql.Rows, error) {
@ -167,7 +160,7 @@ func (db *database) query(query string, args ...interface{}) (*sql.Rows, error)
if err != nil {
return nil, err
}
return stmt.QueryContext(db.c, args...)
return stmt.Query(args...)
}
func (db *database) queryRow(query string, args ...interface{}) (*sql.Row, error) {
@ -175,7 +168,7 @@ func (db *database) queryRow(query string, args ...interface{}) (*sql.Row, error
if err != nil {
return nil, err
}
return stmt.QueryRowContext(db.c, args...), nil
return stmt.QueryRow(args...), nil
}
// Other things

@ -4,7 +4,7 @@ go 1.16
require (
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210617195814-5da00556182e
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210619211856-8953b4bd5490
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4
git.jlel.se/jlelse/template-strings v0.0.0-20210617205924-cfa3bd35ae40
github.com/PuerkitoBio/goquery v1.7.0

@ -40,8 +40,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6 h1:d7k1NKd9fr+Eq7EtUrqUly+HDqDzpx9T9v8Gl2jJvpo=
git.jlel.se/jlelse/go-geouri v0.0.0-20210525190615-a9c1d50f42d6/go.mod h1:eKL81ZHiGWZ4cdv9MI0ADmPiG9p0C+ajkSldNTr2ftQ=
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210617195814-5da00556182e h1:XSqtYqjBPgdMAqYIBNiohFKtAyRjmlh8TgOZcfxqNVE=
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210617195814-5da00556182e/go.mod h1:C4E+E1LpDuayNCX7fJKUx5ERKpBw//2NSna9aeiS5yE=
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210619211856-8953b4bd5490 h1:rRO0tKBlDBBNE5XvjCoRXnuZnwYvWFeRUy5mv/hWV28=
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210619211856-8953b4bd5490/go.mod h1:C4E+E1LpDuayNCX7fJKUx5ERKpBw//2NSna9aeiS5yE=
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4 h1:p3c/vCY6MUADNXWCYI/hsZ8ZEvN7LtvwHzK2B8Y6BSk=
git.jlel.se/jlelse/goldmark-mark v0.0.0-20210522162520-9788c89266a4/go.mod h1:ZFhxwbX+afhgbzh5rpkSJUp6vIduNPtIGDrsWpIcHTE=
git.jlel.se/jlelse/template-strings v0.0.0-20210617205924-cfa3bd35ae40 h1:xFR5EREcB9FHX2/HXgM3KueC7EJEFiPcuoC+jIZttQw=

@ -1,13 +1,17 @@
package main
import (
"context"
"fmt"
"io"
"net/http"
"time"
)
func (a *goBlog) healthcheck() bool {
req, err := http.NewRequest(http.MethodGet, a.getFullAddress("/ping"), nil)
timeoutContext, cancelFunc := context.WithTimeout(context.Background(), 10*time.Second)
defer cancelFunc()
req, err := http.NewRequestWithContext(timeoutContext, http.MethodGet, a.getFullAddress("/ping"), nil)
if err != nil {
fmt.Println(err.Error())
return false

@ -59,7 +59,7 @@ func main() {
if len(os.Args) >= 2 && os.Args[1] == "healthcheck" {
// Connect to public address + "/ping" and exit with 0 when successful
health := app.healthcheckExitCode()
app.shutdown.Shutdown()
app.shutdown.ShutdownAndWait()
os.Exit(health)
return
}
@ -75,7 +75,7 @@ func main() {
return
}
log.Println("TOTP-Secret:", key.Secret())
app.shutdown.Shutdown()
app.shutdown.ShutdownAndWait()
return
}
@ -98,7 +98,7 @@ func main() {
// Link check tool after init of markdown
if len(os.Args) >= 2 && os.Args[1] == "check" {
app.checkAllExternalLinks()
app.shutdown.Shutdown()
app.shutdown.ShutdownAndWait()
return
}
@ -154,6 +154,6 @@ func main() {
func (a *goBlog) logErrAndQuit(v ...interface{}) {
log.Println(v...)
a.shutdown.Shutdown()
a.shutdown.ShutdownAndWait()
os.Exit(1)
}

Loading…
Cancel
Save