update dependencies (#46)

* update dependencies
This commit is contained in:
T.v.Dein
2025-06-10 16:12:54 +02:00
committed by GitHub
parent f22719a92b
commit aad9b31169
15 changed files with 154 additions and 66 deletions

View File

@@ -53,4 +53,4 @@ jobs:
go-version: 1.23
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8

View File

@@ -22,13 +22,13 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
with:
push: true
tags: ghcr.io/tlinden/anydb:${{ github.ref_name}}
- name: Build and push latest Docker image
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
with:
push: true
tags: ghcr.io/tlinden/anydb:latest

6
.golangci.bck.yaml Normal file
View File

@@ -0,0 +1,6 @@
linters:
exclusions:
rules:
- linters:
- staticcheck
text: "QF1008:"

7
.golangci.yaml Normal file
View File

@@ -0,0 +1,7 @@
version: "2"
linters:
exclusions:
rules:
- linters:
- staticcheck
text: "QF1008:"

View File

@@ -20,6 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"log/slog"
"os"
"path/filepath"
@@ -115,8 +116,10 @@ func (db *DB) Open() error {
return nil
}
func (db *DB) Close() error {
return db.DB.Close()
func (db *DB) Close() {
if err := db.DB.Close(); err != nil {
log.Fatal(err)
}
}
func (db *DB) List(attr *DbAttr, fulltext bool) (DbEntries, error) {
@@ -304,7 +307,7 @@ func (db *DB) Set(attr *DbAttr) error {
// internal DB getter, assumes db.DB has already been
// opened successfully. Do NOT call this w/o valid
// DB handle!
func (db *DB)txGet(attr *DbAttr) (*DbEntry, error) {
func (db *DB) txGet(attr *DbAttr) (*DbEntry, error) {
entry := DbEntry{}
err := db.DB.View(func(tx *bolt.Tx) error {

View File

@@ -20,8 +20,7 @@ import "os"
func cleanError(file string, err error) error {
// remove given [backup] file and forward the given error
os.Remove(file)
return err
return os.Remove(file)
}
func fileExists(filename string) bool {

View File

@@ -1,5 +1,5 @@
/*
Copyright © 2024 Thomas von Dein
Copyright © 2025 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@ import (
"github.com/tlinden/anydb/common"
)
var Version string = "v0.2.2"
var Version string = "v0.2.3"
type BucketConfig struct {
Encrypt bool

View File

@@ -156,7 +156,7 @@ func Del(conf *cfg.Config) *cobra.Command {
Long: `Delete key and value matching key`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("No key specified")
return errors.New("no key specified")
}
// errors at this stage do not cause the usage to be shown

View File

@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
@@ -285,7 +286,11 @@ func editContent(editor string, content string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to create templ file: %w", err)
}
defer os.Remove(tmp.Name())
defer func() {
if err := os.Remove(tmp.Name()); err != nil {
log.Fatal(err)
}
}()
// put the content into a tmp file
_, err = tmp.WriteString(content)
@@ -310,7 +315,11 @@ func editContent(editor string, content string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to open temp file: %w", err)
}
defer modified.Close()
defer func() {
if err := modified.Close(); err != nil {
log.Fatal(err)
}
}()
newcontent, err := io.ReadAll(modified)
if err != nil {

View File

@@ -20,8 +20,7 @@ import "os"
func CleanError(file string, err error) error {
// remove given [backup] file and forward the given error
os.Remove(file)
return err
return os.Remove(file)
}
func FileExists(filename string) bool {

12
go.mod
View File

@@ -6,16 +6,16 @@ toolchain go1.24.1
require (
github.com/dustin/go-humanize v1.0.1
github.com/gofiber/fiber/v2 v2.52.6
github.com/gofiber/fiber/v2 v2.52.8
github.com/inconshreveable/mousetrap v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/olekukonko/tablewriter v1.0.7
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.14.1
github.com/spf13/cobra v1.9.1
github.com/tlinden/yadu v0.1.3
go.etcd.io/bbolt v1.4.0
golang.org/x/crypto v0.37.0
golang.org/x/term v0.31.0
golang.org/x/crypto v0.38.0
golang.org/x/term v0.32.0
google.golang.org/protobuf v1.36.6
)
@@ -27,12 +27,14 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 // indirect
github.com/olekukonko/ll v0.0.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

14
go.sum
View File

@@ -9,6 +9,8 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=
github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/fiber/v2 v2.52.8 h1:xl4jJQ0BV5EJTA2aWiKw/VddRpHrKeZLF0QPUxqn0x4=
github.com/gofiber/fiber/v2 v2.52.8/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -24,8 +26,14 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 h1:r3FaAI0NZK3hSmtTDrBVREhKULp8oUeqLT5Eyl2mSPo=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
github.com/olekukonko/ll v0.0.8 h1:sbGZ1Fx4QxJXEqL/6IG8GEFnYojUSQ45dJVwN2FH2fc=
github.com/olekukonko/ll v0.0.8/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/olekukonko/tablewriter v1.0.7 h1:HCC2e3MM+2g72M81ZcJU11uciw6z/p82aEnm4/ySDGw=
github.com/olekukonko/tablewriter v1.0.7/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -55,13 +63,19 @@ go.etcd.io/bbolt v1.4.0 h1:TU77id3TnN/zKr7CO/uk+fBCwF2jGcMuw2B/FMAzYIk=
go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=

View File

@@ -1,5 +1,5 @@
/*
Copyright © 2024 Thomas von Dein
Copyright © 2025 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,6 +28,8 @@ import (
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
"github.com/tlinden/anydb/app"
"github.com/tlinden/anydb/cfg"
)
@@ -71,7 +73,9 @@ func ListTemplate(writer io.Writer, conf *cfg.Config, entries app.DbEntries) err
}
if buf.Len() > 0 {
fmt.Fprintln(writer, buf.String())
if _, err := fmt.Fprintln(writer, buf.String()); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
}
}
@@ -80,13 +84,46 @@ func ListTemplate(writer io.Writer, conf *cfg.Config, entries app.DbEntries) err
func ListTable(writer io.Writer, conf *cfg.Config, entries app.DbEntries) error {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
styleTSV := tw.NewSymbolCustom("space").WithColumn("\t")
table := tablewriter.NewTable(tableString,
tablewriter.WithRenderer(
renderer.NewBlueprint(tw.Rendition{
Borders: tw.BorderNone,
Symbols: styleTSV,
Settings: tw.Settings{
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.On},
Lines: tw.Lines{ShowFooterLine: tw.Off, ShowHeaderLine: tw.Off},
},
})),
tablewriter.WithConfig(tablewriter.Config{
Header: tw.CellConfig{
Formatting: tw.CellFormatting{
AutoFormat: tw.Off,
},
Padding: tw.CellPadding{
Global: tw.Padding{Left: "", Right: ""},
},
},
Row: tw.CellConfig{
Formatting: tw.CellFormatting{
AutoWrap: tw.WrapNone,
Alignment: tw.AlignLeft,
},
Padding: tw.CellPadding{
Global: tw.Padding{Left: "", Right: ""},
},
},
}),
tablewriter.WithPadding(tw.PaddingNone),
)
if !conf.NoHeaders {
if conf.Mode == "wide" {
table.SetHeader([]string{"KEY", "TAGS", "SIZE", "UPDATED", "VALUE"})
table.Header([]string{"KEY", "TAGS", "SIZE", "UPDATED", "VALUE"})
} else {
table.SetHeader([]string{"KEY", "VALUE"})
table.Header([]string{"KEY", "VALUE"})
}
}
@@ -94,44 +131,42 @@ func ListTable(writer io.Writer, conf *cfg.Config, entries app.DbEntries) error
if conf.Mode == "wide" {
switch conf.NoHumanize {
case true:
table.Append([]string{
row.Key,
strings.Join(row.Tags, ","),
strconv.FormatUint(row.Size, 10),
row.Created.AsTime().Format("02.01.2006T03:04.05"),
row.Preview,
})
if err :=
table.Append([]string{
row.Key,
strings.Join(row.Tags, ","),
strconv.FormatUint(row.Size, 10),
row.Created.AsTime().Format("02.01.2006T03:04.05"),
row.Preview,
}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
default:
table.Append([]string{
if err := table.Append([]string{
row.Key,
strings.Join(row.Tags, ","),
humanize.Bytes(uint64(row.Size)),
humanize.Time(row.Created.AsTime()),
row.Preview,
})
}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
}
} else {
table.Append([]string{row.Key, row.Preview})
if err := table.Append([]string{row.Key, row.Preview}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
}
}
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetNoWhiteSpace(true)
if err := table.Render(); err != nil {
return fmt.Errorf("failed to render table: %w", err)
}
table.SetTablePadding("\t") // pad with tabs
table.Render()
fmt.Fprint(writer, tableString.String())
if _, err := fmt.Fprint(writer, tableString.String()); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
}

View File

@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"reflect"
@@ -43,7 +44,9 @@ func Print(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEn
if isatty {
fmt.Println("binary data omitted")
} else {
os.Stdout.WriteString(entry.Value)
if _, err := os.Stdout.WriteString(entry.Value); err != nil {
return err
}
}
} else {
fmt.Print(string(entry.Value))
@@ -79,7 +82,11 @@ func WriteFile(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.
if err != nil {
return fmt.Errorf("failed to open file %s for writing: %w", attr.File, err)
}
defer fd.Close()
defer func() {
if err := fd.Close(); err != nil {
log.Fatal(err)
}
}()
fileHandle = fd
}
@@ -102,34 +109,45 @@ func WriteFile(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.
}
func Info(writer io.Writer, conf *cfg.Config, info *app.DbInfo) error {
fmt.Fprintf(writer, "Database: %s\n", info.Path)
if _, err := fmt.Fprintf(writer, "Database: %s\n", info.Path); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
for _, bucket := range info.Buckets {
if conf.NoHumanize {
fmt.Fprintf(
if _, err := fmt.Fprintf(
writer,
"%19s: %s\n%19s: %d\n%19s: %d\n%19s: %t\n",
"Bucket", bucket.Name,
"Size", bucket.Size,
"Keys", bucket.Keys,
"Encrypted", conf.Encrypt)
"Encrypted", conf.Encrypt); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
} else {
fmt.Fprintf(
if _, err := fmt.Fprintf(
writer,
"%19s: %s\n%19s: %s\n%19s: %d\n",
"Bucket", bucket.Name,
"Size", humanize.Bytes(uint64(bucket.Size)),
"Keys", bucket.Keys)
"Keys", bucket.Keys); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
}
if conf.Debug {
val := reflect.ValueOf(&bucket.Stats).Elem()
for i := 0; i < val.NumField(); i++ {
fmt.Fprintf(writer, "%19s: %v\n", val.Type().Field(i).Name, val.Field(i))
if _, err := fmt.Fprintf(writer, "%19s: %v\n", val.Type().Field(i).Name, val.Field(i)); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
}
}
fmt.Fprintln(writer)
if _, err := fmt.Fprintln(writer); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
}
return nil
}

View File

@@ -104,11 +104,7 @@ Wrapper to respond with proper json status, message and code,
shall be prepared and called by the handlers directly.
*/
func JsonStatus(c *fiber.Ctx, code int, msg string) error {
success := true
if code != fiber.StatusOK {
success = false
}
success := code == fiber.StatusOK
return c.Status(code).JSON(Result{
Code: code,