From 09b82df959cdf1d7a0f452c618615d7705450603 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 14:46:09 +0200 Subject: [PATCH 01/18] Removes bruno files as the endpoints will be deleted as long as the CLI is not finished --- bruno/bruno.json | 9 --------- bruno/environments/local.bru | 6 ------ bruno/feeds/Create feed.bru | 21 --------------------- bruno/users/Create user.bru | 22 ---------------------- 4 files changed, 58 deletions(-) delete mode 100644 bruno/bruno.json delete mode 100644 bruno/environments/local.bru delete mode 100644 bruno/feeds/Create feed.bru delete mode 100644 bruno/users/Create user.bru diff --git a/bruno/bruno.json b/bruno/bruno.json deleted file mode 100644 index c8b8e39..0000000 --- a/bruno/bruno.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": "1", - "name": "freed", - "type": "collection", - "ignore": [ - "node_modules", - ".git" - ] -} \ No newline at end of file diff --git a/bruno/environments/local.bru b/bruno/environments/local.bru deleted file mode 100644 index c3e2449..0000000 --- a/bruno/environments/local.bru +++ /dev/null @@ -1,6 +0,0 @@ -vars { - base_url: http://127.0.0.1:42069 -} -vars:secret [ - api_key -] diff --git a/bruno/feeds/Create feed.bru b/bruno/feeds/Create feed.bru deleted file mode 100644 index 9993002..0000000 --- a/bruno/feeds/Create feed.bru +++ /dev/null @@ -1,21 +0,0 @@ -meta { - name: Create feed - type: http - seq: 1 -} - -post { - url: {{base_url}}/api/v1/users/14515861-7ab1-442e-a1f8-7229ef849996/feeds - body: json - auth: none -} - -headers { - x-api-key: {{api_key}} -} - -body:json { - { - "url": "https://google.com" - } -} diff --git a/bruno/users/Create user.bru b/bruno/users/Create user.bru deleted file mode 100644 index 04f8135..0000000 --- a/bruno/users/Create user.bru +++ /dev/null @@ -1,22 +0,0 @@ -meta { - name: Create user - type: http - seq: 1 -} - -post { - url: {{base_url}}/api/v1/users - body: json - auth: none -} - -headers { - x-api-key: {{api_key}} -} - -body:json { - { - "firstName": "Dennis", - "email": "me@dnsc.io" - } -} From dc1cd468154ce3fe1ae5d71c576b0043fb3adcc0 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 14:46:15 +0200 Subject: [PATCH 02/18] Updates documentation --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43f960b..582f741 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # freed -A unique feed aggregator and bookmarking service that tries to free you from too much content. + +A unique feed aggregator and bookmarking service that tries to free you from too much content. Currently only a CLI program, but I plan to add a web server and frontend in the future. In active development. + +## Installation + +The easiest way to install the program is by using `go install`: + +```sh +go install ... +``` + +## Usage + +- [ ] Document usage after commands are set up From e903e9e3a4aeb591d02249afa43f6a1450b05bf5 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 14:59:36 +0200 Subject: [PATCH 03/18] Removes api handlers --- internal/api/api.go | 34 ----------------- internal/api/auth.go | 56 --------------------------- internal/api/feed.go | 58 ---------------------------- internal/api/handler.go | 13 ------- internal/api/user.go | 80 --------------------------------------- internal/api/validator.go | 40 -------------------- 6 files changed, 281 deletions(-) delete mode 100644 internal/api/api.go delete mode 100644 internal/api/auth.go delete mode 100644 internal/api/feed.go delete mode 100644 internal/api/handler.go delete mode 100644 internal/api/user.go delete mode 100644 internal/api/validator.go diff --git a/internal/api/api.go b/internal/api/api.go deleted file mode 100644 index a4294e7..0000000 --- a/internal/api/api.go +++ /dev/null @@ -1,34 +0,0 @@ -package api - -import ( - "database/sql" - "errors" - "os" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/keyauth" -) - -func Setup(app *fiber.App, db *sql.DB) error { - apiKey := os.Getenv("API_KEY") - - if apiKey == "" { - return errors.New("Could not read API_KEY from ENV file.") - } - - api := app.Group("/api", keyauth.New(keyauth.Config{ - SuccessHandler: successHandler, - ErrorHandler: errHandler, - KeyLookup: "header:x-api-key", - ContextKey: "apiKey", - Validator: apiKeyValidator(apiKey), - })) - - apiHandler := NewHandler(db) - - v1 := api.Group("/v1") - v1.Post("/users", apiHandler.createUser) - v1.Post("/users/:userID/feeds", apiHandler.createFeed) - - return nil -} diff --git a/internal/api/auth.go b/internal/api/auth.go deleted file mode 100644 index b8221f8..0000000 --- a/internal/api/auth.go +++ /dev/null @@ -1,56 +0,0 @@ -package api - -import ( - "crypto/sha256" - "crypto/subtle" - "regexp" - "strings" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/keyauth" -) - -var ( - apiKey = "willbechanged" - protectedURLs = []*regexp.Regexp{ - regexp.MustCompile("^/api$"), - } - errForbidden = &fiber.Error{ - Code: 403, - Message: "API Key is missing or invalid", - } -) - -func apiKeyValidator(apiKey string) func(*fiber.Ctx, string) (bool, error) { - return func(_ *fiber.Ctx, key string) (bool, error) { - hashedAPIKey := sha256.Sum256([]byte(apiKey)) - hashedKey := sha256.Sum256([]byte(key)) - - if subtle.ConstantTimeCompare(hashedAPIKey[:], hashedKey[:]) == 1 { - return true, nil - } - - return false, keyauth.ErrMissingOrMalformedAPIKey - } -} - -func protectedRoutesFilter(ctx *fiber.Ctx) bool { - originalURL := strings.ToLower(ctx.OriginalURL()) - - for _, pattern := range protectedURLs { - if pattern.MatchString(originalURL) { - return false - } - } - return true -} - -func successHandler(ctx *fiber.Ctx) error { - return ctx.Next() -} - -func errHandler(ctx *fiber.Ctx, err error) error { - ctx.Status(fiber.StatusForbidden) - - return ctx.JSON(errForbidden) -} diff --git a/internal/api/feed.go b/internal/api/feed.go deleted file mode 100644 index 4e11628..0000000 --- a/internal/api/feed.go +++ /dev/null @@ -1,58 +0,0 @@ -package api - -import ( - "fmt" - "freed/internal/model" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" - "github.com/mattn/go-sqlite3" -) - -func (h *Handler) createFeed(c *fiber.Ctx) error { - userID := c.Params("userID") - feed := new(model.Feed) - - if parseErr := c.BodyParser(feed); parseErr != nil { - log.Warn(parseErr) - return defaultUserError - } - - validationErr := ValidateModel(feed) - - if validationErr != nil { - return fiber.NewError(fiber.ErrInternalServerError.Code, validationErr.Message) - } - - userExists := h.userExists(userID) - fmt.Printf("exists? %v", userExists) - - if h.userExists(userID) == false { - return fiber.NewError(fiber.ErrInternalServerError.Code, "No existing user found, check user id path param.") - } - - // TODO: Get name from feed - // TODO: Get type from feed - // TODO: Either schedule or request items from feed immediately - - sqlResult, insertErr := h.db.Exec("INSERT INTO feed (userId, name, url) VALUES (?, ?, ?)", userID, feed.Url, feed.Url) - - if sqliteErr, ok := insertErr.(sqlite3.Error); ok { - log.Warn(insertErr) - - if sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique { - return fiber.NewError(fiber.StatusBadRequest, "Feed with url already exists") - } - - return fiber.NewError(fiber.ErrInternalServerError.Code, "Could not create feed") - } - - feedID, idErr := sqlResult.LastInsertId() - - if idErr != nil { - return fiber.NewError(fiber.ErrInternalServerError.Code, "Created feed, but could not retrieve its ID, check database.") - } - - c.SendStatus(201) - return c.JSON(&fiber.Map{"id": feedID}) -} diff --git a/internal/api/handler.go b/internal/api/handler.go deleted file mode 100644 index 2b75080..0000000 --- a/internal/api/handler.go +++ /dev/null @@ -1,13 +0,0 @@ -package api - -import ( - "database/sql" -) - -type Handler struct { - db *sql.DB -} - -func NewHandler(db *sql.DB) *Handler { - return &Handler{db: db} -} diff --git a/internal/api/user.go b/internal/api/user.go deleted file mode 100644 index d8dfd5d..0000000 --- a/internal/api/user.go +++ /dev/null @@ -1,80 +0,0 @@ -package api - -import ( - "database/sql" - "errors" - "fmt" - "freed/internal/model" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/log" - "github.com/google/uuid" - "github.com/mattn/go-sqlite3" -) - -var defaultUserError = fiber.NewError(fiber.ErrInternalServerError.Code, "Could not create user") - -func (h *Handler) createUser(c *fiber.Ctx) error { - user := new(model.User) - - userId, idErr := uuid.NewRandom() - - if idErr != nil { - log.Warn(idErr) - return defaultUserError - } - - user.ID = userId.String() - - if parseErr := c.BodyParser(user); parseErr != nil { - log.Warn(parseErr) - return defaultUserError - } - - validationErr := ValidateModel(user) - - if validationErr != nil { - return fiber.NewError(fiber.ErrInternalServerError.Code, validationErr.Message) - } - - _, insertErr := h.db.Exec("INSERT INTO user (id, first_name, email) VALUES (?, ?, ?)", user.ID, user.FirstName, user.Email) - - if sqliteErr, ok := insertErr.(sqlite3.Error); ok { - log.Warn(insertErr) - - if sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique { - return fiber.NewError(fiber.StatusBadRequest, "User with email already exists") - } - - return defaultUserError - } - - c.SendStatus(201) - return c.JSON(&fiber.Map{"userId": userId}) -} - -func (h *Handler) getUserByID(id string) (*model.User, error) { - var user *model.User - - if err := h.db.QueryRow("SELECT * FROM user WHERE id = ?", id).Scan(&user); err != nil { - if err == sql.ErrNoRows { - notFoundErrMessage := fmt.Sprintf("No user found with ID: %s", id) - return nil, errors.New(notFoundErrMessage) - } - - unexpectedErrMessage := fmt.Sprintf("Unexpected error occured, could not get user with ID: %s", id) - return nil, errors.New(unexpectedErrMessage) - } - - return user, nil -} - -func (h *Handler) userExists(id string) bool { - var userID string - - if err := h.db.QueryRow("SELECT id FROM user WHERE id = ?", id).Scan(&userID); err != nil { - return false - } - - return true -} diff --git a/internal/api/validator.go b/internal/api/validator.go deleted file mode 100644 index 283fefc..0000000 --- a/internal/api/validator.go +++ /dev/null @@ -1,40 +0,0 @@ -package api - -import ( - "fmt" - "freed/internal/model" - "strings" - - "github.com/go-playground/validator/v10" - "github.com/gofiber/fiber/v2" -) - -type ModelConstraint interface { - *model.User | *model.Feed -} - -type ValidationError struct { - FailedField string - Tag string - Value string -} - -func ValidateModel[T ModelConstraint](s T) *fiber.Error { - var errorMessages []string - validate := validator.New() - err := validate.Struct(s) - - fmt.Printf("%#v", err) - - if err == nil { - return nil - } - - for _, err := range err.(validator.ValidationErrors) { - err := fmt.Sprintf("Field %s is invalid, reason: %s", err.StructNamespace(), err.Tag()) - - errorMessages = append(errorMessages, err) - } - - return fiber.NewError(fiber.StatusBadRequest, strings.Join(errorMessages, ". ")) -} From 489d3b88463d80a9ac1d6459f4465e8bfcf09fd4 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 14:59:54 +0200 Subject: [PATCH 04/18] Removes json annotated model structs --- internal/model/article.go | 13 ------------- internal/model/feed.go | 16 ---------------- internal/model/user.go | 7 ------- 3 files changed, 36 deletions(-) delete mode 100644 internal/model/article.go delete mode 100644 internal/model/feed.go delete mode 100644 internal/model/user.go diff --git a/internal/model/article.go b/internal/model/article.go deleted file mode 100644 index 616d150..0000000 --- a/internal/model/article.go +++ /dev/null @@ -1,13 +0,0 @@ -package model - -import "time" - -// TODO: Tag for article? -type Article struct { - ID int64 `json:"id"` - Name string `json:"name"` - Url string `json:"url" validate:"required,url"` - Read bool `json:"read"` - ReadAt time.Time `json:"readAt"` - FeedID *int64 `json:"feedId"` -} diff --git a/internal/model/feed.go b/internal/model/feed.go deleted file mode 100644 index acf8b49..0000000 --- a/internal/model/feed.go +++ /dev/null @@ -1,16 +0,0 @@ -package model - -type FeedType int - -const ( - Rss FeedType = iota - Youtube -) - -type Feed struct { - ID int64 `json:"id"` - Name string `json:"name"` - Url string `json:"url" validate:"required,url"` - UserID string `json:"userId"` - Type FeedType `json:"type"` -} diff --git a/internal/model/user.go b/internal/model/user.go deleted file mode 100644 index 14d05c5..0000000 --- a/internal/model/user.go +++ /dev/null @@ -1,7 +0,0 @@ -package model - -type User struct { - ID string `json:"id"` - FirstName string `json:"firstName" validate:"required"` - Email string `json:"email" validate:"required,email"` -} From 0b5fc090776252bd7bd54802538cb24122436e07 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 15:05:54 +0200 Subject: [PATCH 05/18] Removes fiber --- .air.toml | 46 ----------- go.mod | 81 +++--------------- go.sum | 242 +++--------------------------------------------------- main.go | 23 ++---- 4 files changed, 29 insertions(+), 363 deletions(-) delete mode 100644 .air.toml diff --git a/.air.toml b/.air.toml deleted file mode 100644 index eb2986f..0000000 --- a/.air.toml +++ /dev/null @@ -1,46 +0,0 @@ -root = "." -testdata_dir = "testdata" -tmp_dir = ".tmp" - -[build] - args_bin = [] - bin = "./.tmp/main" - cmd = "go build -o ./.tmp/main ." - delay = 1000 - exclude_dir = ["assets", ".tmp", "tmp", "vendor", "testdata", "internal/database/tmp"] - exclude_file = [] - exclude_regex = ["_test.go"] - exclude_unchanged = false - follow_symlink = false - full_bin = "" - include_dir = [] - include_ext = ["go", "tpl", "tmpl", "html", "env"] - include_file = [] - kill_delay = "0s" - log = "build-errors.log" - poll = false - poll_interval = 0 - post_cmd = [] - pre_cmd = [] - rerun = false - rerun_delay = 500 - send_interrupt = false - stop_on_error = false - -[color] - app = "" - build = "yellow" - main = "magenta" - runner = "green" - watcher = "cyan" - -[log] - main_only = false - time = false - -[misc] - clean_on_exit = true - -[screen] - clear_on_rebuild = false - keep_scroll = true diff --git a/go.mod b/go.mod index e811521..852f907 100644 --- a/go.mod +++ b/go.mod @@ -3,75 +3,14 @@ module freed go 1.21.5 require ( - filippo.io/edwards25519 v1.1.0 // indirect - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect - github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/andybalholm/brotli v1.0.5 // indirect - github.com/armon/go-radix v1.0.0 // indirect - github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/bytedance/sonic v1.11.6 // indirect - github.com/bytedance/sonic/loader v0.1.1 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect - github.com/cloudwego/base64x v0.1.4 // indirect - github.com/cloudwego/iasm v0.2.0 // indirect - github.com/denisenkom/go-mssqldb v0.9.0 // indirect - github.com/fatih/color v1.13.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/gin-gonic/gin v1.9.1 // indirect - github.com/go-gorp/gorp/v3 v3.1.0 // indirect - github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.19.0 // indirect - github.com/go-sql-driver/mysql v1.8.1 // indirect - github.com/goccy/go-json v0.10.2 // indirect - github.com/godror/godror v0.40.4 // indirect - github.com/godror/knownpb v0.1.1 // indirect - github.com/gofiber/fiber/v2 v2.52.4 // indirect - github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/huandu/xstrings v1.4.0 // indirect - github.com/imdario/mergo v0.3.13 // indirect - github.com/jmoiron/sqlx v1.4.0 // indirect - github.com/joho/godotenv v1.5.1 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.17.0 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect - github.com/leodido/go-urn v1.4.0 // indirect - github.com/lib/pq v1.10.9 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-oci8 v0.1.1 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/mattn/go-sqlite3 v1.14.22 // indirect - github.com/mitchellh/cli v1.1.5 // indirect - github.com/mitchellh/copystructure v1.2.0 // indirect - github.com/mitchellh/reflectwalk v1.0.2 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/pelletier/go-toml/v2 v2.2.1 // indirect - github.com/posener/complete v1.2.3 // indirect - github.com/rivo/uniseg v0.2.0 // indirect - github.com/rubenv/sql-migrate v1.6.1 // indirect - github.com/shopspring/decimal v1.3.1 // indirect - github.com/spf13/cast v1.5.0 // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.51.0 // indirect - github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/arch v0.7.0 // indirect - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + github.com/joho/godotenv v1.5.1 + github.com/mattn/go-sqlite3 v1.14.22 + github.com/rubenv/sql-migrate v1.6.1 +) + +require ( + github.com/go-gorp/gorp/v3 v3.1.0 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect + github.com/lib/pq v1.10.9 // indirect + github.com/stretchr/testify v1.9.0 // indirect ) diff --git a/go.sum b/go.sum index 4855395..d2fd754 100644 --- a/go.sum +++ b/go.sum @@ -1,248 +1,32 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= -github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= -github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= -github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= -github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= -github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= -github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= -github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= -github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= -github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= -github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/denisenkom/go-mssqldb v0.9.0 h1:RSohk2RsiZqLZ0zCjtfn3S4Gp4exhpBWHyQ7D0yGjAk= -github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= -github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs= github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw= -github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= -github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= -github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= -github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= -github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/godror/godror v0.40.4 h1:X1e7hUd02GDaLWKZj40Z7L0CP0W9TrGgmPQZw6+anBg= -github.com/godror/godror v0.40.4/go.mod h1:i8YtVTHUJKfFT3wTat4A9UoqScUtZXiYB9Rf3SVARgc= -github.com/godror/knownpb v0.1.1 h1:A4J7jdx7jWBhJm18NntafzSC//iZDHkDi1+juwQ5pTI= -github.com/godror/knownpb v0.1.1/go.mod h1:4nRFbQo1dDuwKnblRXDxrfCFYeT4hjg3GjMqef58eRE= -github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= -github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= -github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= -github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= -github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= -github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= -github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= -github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= -github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-oci8 v0.1.1 h1:aEUDxNAyDG0tv8CA3TArnDQNyc4EhnWlsfxRgDHABHM= -github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= -github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= -github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= -github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= -github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -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/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= -github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= +github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rubenv/sql-migrate v1.6.1 h1:bo6/sjsan9HaXAsNxYP/jCEDUGibHp8JmOBw7NTGRos= github.com/rubenv/sql-migrate v1.6.1/go.mod h1:tPzespupJS0jacLfhbwto/UjSX+8h2FdWB7ar+QlHa0= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= -github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= -github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= -github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= -github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= -github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= -github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= -github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= -golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/main.go b/main.go index 506567f..c4c1a0c 100644 --- a/main.go +++ b/main.go @@ -2,38 +2,27 @@ package main import ( _ "embed" - "freed/internal/api" + "fmt" "freed/internal/database" "log" "os" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/middleware/logger" _ "github.com/joho/godotenv/autoload" ) func main() { - dbFile := os.Getenv("DB_FILE") + dbFile := os.Getenv("DB_PATH") if dbFile == "" { - log.Fatalf("No ENV value set for 'DB_FILE', could not initialize database. Please provide a valid path and filename") + log.Fatalf("No ENV value set for 'DB_PATH', could not initialize database. Please provide a valid path and filename") } - db, err := database.Connect(dbFile) + _, err := database.Connect(dbFile) if err != nil { log.Fatalf("Could not initialize database: %v", err) } - app := fiber.New() - - // Global Middlewares - app.Use(logger.New()) - - // Try to set up API routes - if err := api.Setup(app, db); err != nil { - log.Printf("Could not setup /api routes: %s", err) - } - - app.Listen(":42069") + fmt.Println("Setup finished") + os.Exit(1) } From f2187d8559f3b30bf27fbf7d437c130bc25a3e37 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 15:06:00 +0200 Subject: [PATCH 06/18] Ignores sqlite3 files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3212c93..1099cd1 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ go.work # SQLite *.db* +*.sqlite3 .tmp/ tmp From db7ed2fa3b513824b1e4a42a53e25ac0de8d5d59 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:06:43 +0200 Subject: [PATCH 07/18] Adds subcommands --- cmd/add.go | 40 ++++++++++++++++++++++++++++++++++++++++ cmd/today.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 cmd/add.go create mode 100644 cmd/today.go diff --git a/cmd/add.go b/cmd/add.go new file mode 100644 index 0000000..297a546 --- /dev/null +++ b/cmd/add.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// addCmd represents the add command +var addCmd = &cobra.Command{ + Use: "add", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("add called") + }, +} + +func init() { + rootCmd.AddCommand(addCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // addCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/today.go b/cmd/today.go new file mode 100644 index 0000000..af27a57 --- /dev/null +++ b/cmd/today.go @@ -0,0 +1,42 @@ +/* +Copyright © 2024 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// todayCmd represents the today command +var todayCmd = &cobra.Command{ + Use: "today", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + dbPath := viper.GetString("path") + fmt.Println(dbPath) + fmt.Println("today called") + }, +} + +func init() { + rootCmd.AddCommand(todayCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // todayCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // todayCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} From b70a232343e729e09289a66b50fec58917c63115 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:07:14 +0200 Subject: [PATCH 08/18] Restructures database access Makes it simpler as long as the application is just the CLI --- internal/database/database.go | 17 +++++++---------- internal/database/feed.go | 8 ++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 internal/database/feed.go diff --git a/internal/database/database.go b/internal/database/database.go index d4d342d..281ed50 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -3,21 +3,22 @@ package database import ( "database/sql" "embed" - "fmt" _ "github.com/mattn/go-sqlite3" migrate "github.com/rubenv/sql-migrate" ) +var db *sql.DB + //go:embed migrations/* var dbMigrations embed.FS -func Connect(filename string) (*sql.DB, error) { +func Init(filename string) error { dbOptions := "?_fk=on&_journal=WAL&sync=normal" db, err := sql.Open("sqlite3", filename+dbOptions) if err != nil { - return nil, err + return err } migrations := migrate.EmbedFileSystemMigrationSource{ @@ -25,13 +26,9 @@ func Connect(filename string) (*sql.DB, error) { Root: "migrations", } - _, migrateErr := migrate.Exec(db, "sqlite3", migrations, migrate.Up) - - if migrateErr != nil { - return nil, err + if _, err := migrate.Exec(db, "sqlite3", migrations, migrate.Up); err != nil { + return err } - fmt.Println("Applied migrations - Database is ready!") - - return db, nil + return db.Ping() } diff --git a/internal/database/feed.go b/internal/database/feed.go new file mode 100644 index 0000000..de11ffb --- /dev/null +++ b/internal/database/feed.go @@ -0,0 +1,8 @@ +package database + +import "fmt" + +func AddFeed(url string) error { + fmt.Printf("Trying to add new feed by URL: %s", url) + return nil +} From 727a788d44d44bb4cda03562b45e5db508eda14b Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:07:38 +0200 Subject: [PATCH 09/18] Cobra initialization in main.go --- main.go | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index c4c1a0c..b86a455 100644 --- a/main.go +++ b/main.go @@ -1,28 +1,22 @@ +/* +Copyright © 2024 Dennis Schoepf dev@dnsc.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ package main -import ( - _ "embed" - "fmt" - "freed/internal/database" - "log" - "os" - - _ "github.com/joho/godotenv/autoload" -) +import "freed/cmd" func main() { - dbFile := os.Getenv("DB_PATH") - - if dbFile == "" { - log.Fatalf("No ENV value set for 'DB_PATH', could not initialize database. Please provide a valid path and filename") - } - - _, err := database.Connect(dbFile) - - if err != nil { - log.Fatalf("Could not initialize database: %v", err) - } - - fmt.Println("Setup finished") - os.Exit(1) + cmd.Execute() } From dd075aaf630695febef8d377fac15548d8a527bb Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:57:46 +0200 Subject: [PATCH 10/18] Reverts back to old Connect style database access --- internal/database/database.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 281ed50..dad6563 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -8,17 +8,15 @@ import ( migrate "github.com/rubenv/sql-migrate" ) -var db *sql.DB - //go:embed migrations/* var dbMigrations embed.FS -func Init(filename string) error { +func Connect(path string) (*sql.DB, error) { dbOptions := "?_fk=on&_journal=WAL&sync=normal" - db, err := sql.Open("sqlite3", filename+dbOptions) + db, err := sql.Open("sqlite3", path+dbOptions) if err != nil { - return err + return nil, err } migrations := migrate.EmbedFileSystemMigrationSource{ @@ -27,8 +25,12 @@ func Init(filename string) error { } if _, err := migrate.Exec(db, "sqlite3", migrations, migrate.Up); err != nil { - return err + return nil, err } - return db.Ping() + if err := db.Ping(); err != nil { + return nil, err + } + + return db, nil } From fcac7b16a72a6b7e5292d99e6c6ef49b9c5d7109 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:58:17 +0200 Subject: [PATCH 11/18] Removes unused packages and adds cli packages --- go.mod | 24 +++++++++++++++++++-- go.sum | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 852f907..e094552 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,34 @@ module freed go 1.21.5 require ( - github.com/joho/godotenv v1.5.1 github.com/mattn/go-sqlite3 v1.14.22 github.com/rubenv/sql-migrate v1.6.1 + github.com/spf13/cobra v1.8.1 + github.com/spf13/viper v1.19.0 ) require ( + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-gorp/gorp/v3 v3.1.0 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lib/pq v1.10.9 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d2fd754..e3ea6ee 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,91 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs= github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rubenv/sql-migrate v1.6.1 h1:bo6/sjsan9HaXAsNxYP/jCEDUGibHp8JmOBw7NTGRos= github.com/rubenv/sql-migrate v1.6.1/go.mod h1:tPzespupJS0jacLfhbwto/UjSX+8h2FdWB7ar+QlHa0= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 46fb4356940265c1c2bfa0212dd5757f6a6b21b6 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:59:20 +0200 Subject: [PATCH 12/18] Fixes license --- main.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/main.go b/main.go index b86a455..0b67ac8 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,7 @@ /* Copyright © 2024 Dennis Schoepf dev@dnsc.io -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +Licensed under GNU GPL v3 */ package main From fcdc3228a03bcb2733c3d53c35d01ed89f5dedc4 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 17:59:57 +0200 Subject: [PATCH 13/18] Implements reading config file in root command --- cmd/root.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 cmd/root.go diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..ea00bb7 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,95 @@ +/* +Copyright © 2024 Dennis Schoepf dev@dnsc.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +type DatabaseConfig struct { + Path string `mapstructure:"path"` +} + +type Config struct { + Db DatabaseConfig `mapstructure:"database"` +} + +var cfgFile string + +var rootCmd = &cobra.Command{ + Use: "freed", + Short: "A f[r]eed aggregator with an intentionally reduced discovery mechanism.", + Long: `A f[r]eed aggregator with an intentionally reduced discovery mechanism. + +f[r]eed aims to handle all sort of different inputs that emit recurring content. This includes: RSS feeds, youtube channels, and more. If there is a type of input that you wish to be handled (or you find a bug), open an issue at https://github.com/dennisschoepf/freed/issues. + +Where f[r]eed is different to other feed aggregators or bookmarking services is in its discovery mechanism. Due to the overwhelming amount of content created every day, the constant stream of input can be overwhelming. That is why only a set amount of new content from your input feeds is shown to you when discovering new items. The amount is going to be configurable in the future. + +The application also includes a set of recommended "Small Web" and topic-specific curated feeds. These are also available through the configuration. + `, +} + +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + cobra.OnInitialize(initConfig) + + // rootCmd.SetHelpFunc(internal.HelpFunc) + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default: ~/.config/freed/config.toml)") +} + +// initConfig reads in config file and ENV variables if set. +func initConfig() { + if cfgFile != "" { + viper.SetConfigFile(cfgFile) + } else { + homeDir, err := os.UserHomeDir() + cobra.CheckErr(err) + + userConfigDir, err := os.UserConfigDir() + cobra.CheckErr(err) + + freedXdgConfigDir := filepath.Join(userConfigDir, "freed") + freedConfigDir := filepath.Join(homeDir, ".config", "freed") + + viper.AddConfigPath(freedXdgConfigDir) + viper.AddConfigPath(freedConfigDir) + viper.SetConfigType("toml") + viper.SetConfigName("config") + } + + if err := viper.ReadInConfig(); err != nil { + fmt.Printf("Could not load config file: %s", err) + os.Exit(1) + } + + var c Config + + if err := viper.Unmarshal(&c); err != nil { + fmt.Printf("Could not read config file: %s", err) + os.Exit(1) + } +} From e6fae146a5b6e963c02670fc036ea2d624388dd9 Mon Sep 17 00:00:00 2001 From: Dennis Date: Fri, 30 Aug 2024 19:21:13 +0200 Subject: [PATCH 14/18] Adapts license headers --- cmd/add.go | 14 +++++++++++++- cmd/root.go | 21 +++++++++++---------- cmd/today.go | 15 ++++++++++++++- main.go | 15 +++++++++++++-- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 297a546..c3e055b 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -1,6 +1,18 @@ /* -Copyright © 2024 NAME HERE +Copyright © 2024 Dennis Schoepf +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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ package cmd diff --git a/cmd/root.go b/cmd/root.go index ea00bb7..037eacc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,17 +1,18 @@ /* -Copyright © 2024 Dennis Schoepf dev@dnsc.io +Copyright © 2024 Dennis Schoepf -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. - http://www.apache.org/licenses/LICENSE-2.0 +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ package cmd diff --git a/cmd/today.go b/cmd/today.go index af27a57..ff0aa7c 100644 --- a/cmd/today.go +++ b/cmd/today.go @@ -1,5 +1,18 @@ /* -Copyright © 2024 NAME HERE +Copyright © 2024 Dennis Schoepf + +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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ package cmd diff --git a/main.go b/main.go index 0b67ac8..01c938c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,18 @@ /* -Copyright © 2024 Dennis Schoepf dev@dnsc.io +Copyright © 2024 Dennis Schoepf -Licensed under GNU GPL v3 +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 +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ package main From 051e84de868641bca5e2ad7737cfd1494b10a81d Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 31 Aug 2024 01:41:44 +0200 Subject: [PATCH 15/18] Removes unused migrations --- dbconfig.yml | 5 ----- internal/database/migrations/{2_feed.sql => 1_feed.sql} | 3 +-- internal/database/migrations/1_initial.sql | 9 --------- .../database/migrations/{3_article.sql => 2_article.sql} | 0 internal/database/migrations/4_add-type-to-feed.sql | 7 ------- 5 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 dbconfig.yml rename internal/database/migrations/{2_feed.sql => 1_feed.sql} (68%) delete mode 100644 internal/database/migrations/1_initial.sql rename internal/database/migrations/{3_article.sql => 2_article.sql} (100%) delete mode 100644 internal/database/migrations/4_add-type-to-feed.sql diff --git a/dbconfig.yml b/dbconfig.yml deleted file mode 100644 index 197215a..0000000 --- a/dbconfig.yml +++ /dev/null @@ -1,5 +0,0 @@ -local: - dialect: sqlite3 - datasource: freed.db - dir: internal/database/migrations - table: gorp_migrations diff --git a/internal/database/migrations/2_feed.sql b/internal/database/migrations/1_feed.sql similarity index 68% rename from internal/database/migrations/2_feed.sql rename to internal/database/migrations/1_feed.sql index 304103b..1440b11 100644 --- a/internal/database/migrations/2_feed.sql +++ b/internal/database/migrations/1_feed.sql @@ -3,8 +3,7 @@ CREATE table feed ( id INTEGER PRIMARY KEY, name text NOT NULL, url text NOT NULL UNIQUE, - userId text NOT NULL, - FOREIGN KEY (userId) REFERENCES user(id) + type text NOT NULL ); -- +migrate Down diff --git a/internal/database/migrations/1_initial.sql b/internal/database/migrations/1_initial.sql deleted file mode 100644 index 70fa1a0..0000000 --- a/internal/database/migrations/1_initial.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +migrate Up -CREATE table user ( - id text PRIMARY KEY, - first_name text NOT NULL, - email text NOT NULL UNIQUE -); - --- +migrate Down -DROP TABLE user; diff --git a/internal/database/migrations/3_article.sql b/internal/database/migrations/2_article.sql similarity index 100% rename from internal/database/migrations/3_article.sql rename to internal/database/migrations/2_article.sql diff --git a/internal/database/migrations/4_add-type-to-feed.sql b/internal/database/migrations/4_add-type-to-feed.sql deleted file mode 100644 index 44c4dc4..0000000 --- a/internal/database/migrations/4_add-type-to-feed.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +migrate Up -ALTER TABLE feed -ADD COLUMN type text; - --- +migrate Down -ALTER TABLE feed -DROP COLUMN type; From fc59ecbee543169da6271eaaca65a997d5b646a4 Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 31 Aug 2024 01:42:00 +0200 Subject: [PATCH 16/18] Temporarily removes ping for DB --- internal/database/database.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index dad6563..25f2740 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -28,9 +28,5 @@ func Connect(path string) (*sql.DB, error) { return nil, err } - if err := db.Ping(); err != nil { - return nil, err - } - return db, nil } From 0f54c090bbab5e51dc2c59da7916e9985c35cf0c Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 31 Aug 2024 01:42:15 +0200 Subject: [PATCH 17/18] Removes temp database handler --- internal/database/feed.go | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 internal/database/feed.go diff --git a/internal/database/feed.go b/internal/database/feed.go deleted file mode 100644 index de11ffb..0000000 --- a/internal/database/feed.go +++ /dev/null @@ -1,8 +0,0 @@ -package database - -import "fmt" - -func AddFeed(url string) error { - fmt.Printf("Trying to add new feed by URL: %s", url) - return nil -} From ad4bb08eb200a1a1d920749ca785a98b74ac796c Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 31 Aug 2024 01:42:31 +0200 Subject: [PATCH 18/18] Implements database connection with config data --- cmd/add.go | 19 ++++++++++++------- cmd/root.go | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index c3e055b..ea4acd4 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -22,18 +22,23 @@ import ( "github.com/spf13/cobra" ) +type Feed struct { + ID int + URL string +} + // addCmd represents the add command var addCmd = &cobra.Command{ Use: "add", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: + Args: cobra.MinimumNArgs(1), + Short: "Adds a new feed to the application.", + Long: `Validates and stores a feed in the application's database. Depending on the feed type, articles, videos, or updates are fetched right away. -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, +Supported types currently are: +- RSS +- Youtube Channel links`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("add called") + fmt.Println("Not implemented. Feed will be added here") }, } diff --git a/cmd/root.go b/cmd/root.go index 037eacc..ab8236d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,9 @@ along with this program. If not, see . package cmd import ( + "database/sql" "fmt" + "freed/internal/database" "os" "path/filepath" @@ -30,15 +32,21 @@ type DatabaseConfig struct { } type Config struct { - Db DatabaseConfig `mapstructure:"database"` + DB DatabaseConfig `mapstructure:"database"` } -var cfgFile string +type AppContext struct { + Config Config + DB *sql.DB +} -var rootCmd = &cobra.Command{ - Use: "freed", - Short: "A f[r]eed aggregator with an intentionally reduced discovery mechanism.", - Long: `A f[r]eed aggregator with an intentionally reduced discovery mechanism. +var ( + appContext = &AppContext{} + cfgFile string + rootCmd = &cobra.Command{ + Use: "freed", + Short: "A f[r]eed aggregator with an intentionally reduced discovery mechanism.", + Long: `A f[r]eed aggregator with an intentionally reduced discovery mechanism. f[r]eed aims to handle all sort of different inputs that emit recurring content. This includes: RSS feeds, youtube channels, and more. If there is a type of input that you wish to be handled (or you find a bug), open an issue at https://github.com/dennisschoepf/freed/issues. @@ -46,7 +54,22 @@ Where f[r]eed is different to other feed aggregators or bookmarking services is The application also includes a set of recommended "Small Web" and topic-specific curated feeds. These are also available through the configuration. `, -} + PersistentPreRun: func(cmd *cobra.Command, args []string) { + db, err := database.Connect(appContext.Config.DB.Path) + + if err != nil { + fmt.Printf("Could not connect to the database: %s", err) + } + + appContext.DB = db + }, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + if appContext.DB != nil { + appContext.DB.Close() + } + }, + } +) func Execute() { err := rootCmd.Execute() @@ -58,11 +81,9 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - // rootCmd.SetHelpFunc(internal.HelpFunc) rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default: ~/.config/freed/config.toml)") } -// initConfig reads in config file and ENV variables if set. func initConfig() { if cfgFile != "" { viper.SetConfigFile(cfgFile) @@ -87,9 +108,9 @@ func initConfig() { os.Exit(1) } - var c Config + viper.SetDefault("database.path", "freed.sqlite3") - if err := viper.Unmarshal(&c); err != nil { + if err := viper.Unmarshal(&appContext.Config); err != nil { fmt.Printf("Could not read config file: %s", err) os.Exit(1) }