diff --git a/desktopcache/desktopcache.go b/cache/cache.go similarity index 98% rename from desktopcache/desktopcache.go rename to cache/cache.go index 93fc111..65220b4 100644 --- a/desktopcache/desktopcache.go +++ b/cache/cache.go @@ -1,4 +1,4 @@ -package desktopcache +package cache import ( "errors" diff --git a/desktopcache/desktopcache_test.go b/cache/cache_test.go similarity index 98% rename from desktopcache/desktopcache_test.go rename to cache/cache_test.go index 3d942d6..9895364 100644 --- a/desktopcache/desktopcache_test.go +++ b/cache/cache_test.go @@ -1,4 +1,4 @@ -package desktopcache +package cache import ( "os" diff --git a/configkit/configkit.go b/config/config.go similarity index 99% rename from configkit/configkit.go rename to config/config.go index 9803ec8..4b1335f 100644 --- a/configkit/configkit.go +++ b/config/config.go @@ -1,4 +1,4 @@ -package configkit +package config import ( "errors" diff --git a/configkit/configkit_test.go b/config/config_test.go similarity index 99% rename from configkit/configkit_test.go rename to config/config_test.go index df3d71b..8114657 100644 --- a/configkit/configkit_test.go +++ b/config/config_test.go @@ -1,4 +1,4 @@ -package configkit +package config import ( "os" diff --git a/gitshare/gitshare.go b/mirror/mirror.go similarity index 99% rename from gitshare/gitshare.go rename to mirror/mirror.go index 52775a2..347625f 100644 --- a/gitshare/gitshare.go +++ b/mirror/mirror.go @@ -1,4 +1,4 @@ -package gitshare +package mirror import ( "context" diff --git a/gitshare/gitshare_test.go b/mirror/mirror_test.go similarity index 98% rename from gitshare/gitshare_test.go rename to mirror/mirror_test.go index a6bc877..ed31d65 100644 --- a/gitshare/gitshare_test.go +++ b/mirror/mirror_test.go @@ -1,4 +1,4 @@ -package gitshare +package mirror import ( "context" diff --git a/cliout/cliout.go b/output/output.go similarity index 98% rename from cliout/cliout.go rename to output/output.go index 19d7ea6..74a1b5c 100644 --- a/cliout/cliout.go +++ b/output/output.go @@ -1,4 +1,4 @@ -package cliout +package output import ( "encoding/json" diff --git a/cliout/cliout_test.go b/output/output_test.go similarity index 97% rename from cliout/cliout_test.go rename to output/output_test.go index 287acbe..803729b 100644 --- a/cliout/cliout_test.go +++ b/output/output_test.go @@ -1,4 +1,4 @@ -package cliout +package output import ( "bytes" diff --git a/pack/pack.go b/snapshot/snapshot.go similarity index 97% rename from pack/pack.go rename to snapshot/snapshot.go index 8d07e16..827f859 100644 --- a/pack/pack.go +++ b/snapshot/snapshot.go @@ -1,4 +1,4 @@ -package pack +package snapshot import ( "bufio" @@ -15,7 +15,7 @@ import ( "strings" "time" - "github.com/vincentkoc/crawlkit/sqlitekit" + "github.com/vincentkoc/crawlkit/store" ) const ManifestName = "manifest.json" @@ -153,7 +153,7 @@ func Import(ctx context.Context, opts ImportOptions) (Manifest, error) { } continue } - if _, err := tx.ExecContext(ctx, "delete from "+sqlitekit.QuoteIdent(table)); err != nil { + if _, err := tx.ExecContext(ctx, "delete from "+store.QuoteIdent(table)); err != nil { return Manifest{}, fmt.Errorf("clear table %s: %w", table, err) } } @@ -205,7 +205,7 @@ func WriteManifest(rootDir string, manifest Manifest) error { } func exportTable(ctx context.Context, db *sql.DB, rootDir, table string, maxShardBytes int64, filter RowFilter) (TableManifest, error) { - rows, err := db.QueryContext(ctx, "select * from "+sqlitekit.QuoteIdent(table)) + rows, err := db.QueryContext(ctx, "select * from "+store.QuoteIdent(table)) if err != nil { return TableManifest{}, fmt.Errorf("query table %s: %w", table, err) } @@ -324,13 +324,13 @@ func insertRow(ctx context.Context, tx *sql.Tx, table string, row map[string]any holders := make([]string, 0, len(cols)) args := make([]any, 0, len(cols)) for _, col := range cols { - quoted = append(quoted, sqlitekit.QuoteIdent(col)) + quoted = append(quoted, store.QuoteIdent(col)) holders = append(holders, "?") args = append(args, row[col]) } stmt := fmt.Sprintf( "insert or replace into %s(%s) values(%s)", - sqlitekit.QuoteIdent(table), + store.QuoteIdent(table), strings.Join(quoted, ","), strings.Join(holders, ","), ) diff --git a/pack/pack_test.go b/snapshot/snapshot_test.go similarity index 91% rename from pack/pack_test.go rename to snapshot/snapshot_test.go index b7ec88b..9a01c08 100644 --- a/pack/pack_test.go +++ b/snapshot/snapshot_test.go @@ -1,4 +1,4 @@ -package pack +package snapshot import ( "context" @@ -7,12 +7,12 @@ import ( "testing" "time" - "github.com/vincentkoc/crawlkit/sqlitekit" + "github.com/vincentkoc/crawlkit/store" ) func TestExportImportTablesWithFilter(t *testing.T) { ctx := context.Background() - src, err := sqlitekit.Open(ctx, sqlitekit.Options{ + src, err := store.Open(ctx, store.Options{ Path: filepath.Join(t.TempDir(), "src.db"), Schema: ` create table messages(id text primary key, guild_id text not null, body text not null); @@ -44,7 +44,7 @@ create table sync_state(source_name text, entity_type text, entity_id text, valu t.Fatalf("manifest = %+v", manifest) } - dst, err := sqlitekit.Open(ctx, sqlitekit.Options{ + dst, err := store.Open(ctx, store.Options{ Path: filepath.Join(t.TempDir(), "dst.db"), Schema: ` create table messages(id text primary key, guild_id text not null, body text not null); @@ -69,7 +69,7 @@ create table sync_state(source_name text, entity_type text, entity_id text, valu func TestExportRotatesShards(t *testing.T) { ctx := context.Background() - src, err := sqlitekit.Open(ctx, sqlitekit.Options{ + src, err := store.Open(ctx, store.Options{ Path: filepath.Join(t.TempDir(), "src.db"), Schema: `create table things(id integer primary key, value text not null);`, }) @@ -96,7 +96,7 @@ func TestExportRotatesShards(t *testing.T) { func TestImportHooks(t *testing.T) { ctx := context.Background() - src, err := sqlitekit.Open(ctx, sqlitekit.Options{ + src, err := store.Open(ctx, store.Options{ Path: filepath.Join(t.TempDir(), "src.db"), Schema: `create table things(id text primary key, keep integer not null);`, }) @@ -110,7 +110,7 @@ func TestImportHooks(t *testing.T) { t.Fatal(err) } - dst, err := sqlitekit.Open(ctx, sqlitekit.Options{ + dst, err := store.Open(ctx, store.Options{ Path: filepath.Join(t.TempDir(), "dst.db"), Schema: `create table things(id text primary key, keep integer not null); create table audit(event text not null);`, }) @@ -127,7 +127,7 @@ func TestImportHooks(t *testing.T) { return err }, DeleteTable: func(ctx context.Context, tx *sql.Tx, table string) error { - _, err := tx.ExecContext(ctx, `delete from `+sqlitekit.QuoteIdent(table)+` where keep != 0`) + _, err := tx.ExecContext(ctx, `delete from `+store.QuoteIdent(table)+` where keep != 0`) return err }, }); err != nil { diff --git a/syncstate/syncstate.go b/state/state.go similarity index 99% rename from syncstate/syncstate.go rename to state/state.go index 9dbc205..6ccf720 100644 --- a/syncstate/syncstate.go +++ b/state/state.go @@ -1,4 +1,4 @@ -package syncstate +package state import ( "context" diff --git a/syncstate/syncstate_test.go b/state/state_test.go similarity index 98% rename from syncstate/syncstate_test.go rename to state/state_test.go index c259f00..94de38b 100644 --- a/syncstate/syncstate_test.go +++ b/state/state_test.go @@ -1,4 +1,4 @@ -package syncstate +package state import ( "context" diff --git a/sqlitekit/sqlitekit.go b/store/store.go similarity index 99% rename from sqlitekit/sqlitekit.go rename to store/store.go index e608d4f..2cd5767 100644 --- a/sqlitekit/sqlitekit.go +++ b/store/store.go @@ -1,4 +1,4 @@ -package sqlitekit +package store import ( "context" diff --git a/sqlitekit/sqlitekit_test.go b/store/store_test.go similarity index 99% rename from sqlitekit/sqlitekit_test.go rename to store/store_test.go index 1040502..b8a336b 100644 --- a/sqlitekit/sqlitekit_test.go +++ b/store/store_test.go @@ -1,4 +1,4 @@ -package sqlitekit +package store import ( "context" diff --git a/termkit/termkit.go b/tui/tui.go similarity index 99% rename from termkit/termkit.go rename to tui/tui.go index 0072c04..db1e51c 100644 --- a/termkit/termkit.go +++ b/tui/tui.go @@ -1,4 +1,4 @@ -package termkit +package tui import ( "context" diff --git a/termkit/termkit_test.go b/tui/tui_test.go similarity index 97% rename from termkit/termkit_test.go rename to tui/tui_test.go index 9d5b676..8ad1b8d 100644 --- a/termkit/termkit_test.go +++ b/tui/tui_test.go @@ -1,4 +1,4 @@ -package termkit +package tui import ( "strings"