From 276942ab91ae2f27e4c62e15e134b0a20941b188 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sat, 7 Mar 2020 20:37:48 +0530 Subject: [PATCH] Replace outdated UUID lib --- campaigns.go | 10 ++++++++-- go.mod | 4 +--- go.sum | 23 ++--------------------- install.go | 12 ++++++------ lists.go | 10 ++++++++-- manager_db.go | 13 +++++++++---- media.go | 12 ++++++++++-- subimporter/importer.go | 14 ++++++++++---- subscribers.go | 11 ++++++++--- 9 files changed, 62 insertions(+), 47 deletions(-) diff --git a/campaigns.go b/campaigns.go index 46c09e2..04a5d6c 100644 --- a/campaigns.go +++ b/campaigns.go @@ -14,10 +14,10 @@ import ( "time" "github.com/asaskevich/govalidator" + "github.com/gofrs/uuid" "github.com/knadh/listmonk/models" "github.com/labstack/echo" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" null "gopkg.in/volatiletech/null.v6" ) @@ -217,10 +217,16 @@ func handleCreateCampaign(c echo.Context) error { fmt.Sprintf("Unknown messenger %s", o.MessengerID)) } + uu, err := uuid.NewV4() + if err != nil { + app.Logger.Println("error generating UUID: %v", err) + return echo.NewHTTPError(http.StatusInternalServerError, "Error generating UUID") + } + // Insert and read ID. var newID int if err := app.Queries.CreateCampaign.Get(&newID, - uuid.NewV4(), + uu, o.Type, o.Name, o.Subject, diff --git a/go.mod b/go.mod index aa594c9..64162fd 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,8 @@ module github.com/knadh/listmonk require ( github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf - github.com/aws/aws-sdk-go v1.25.12 github.com/disintegration/imaging v1.5.0 + github.com/gofrs/uuid v3.2.0+incompatible github.com/jinzhu/gorm v1.9.1 github.com/jmoiron/sqlx v1.2.0 github.com/jordan-wright/email v0.0.0-20181027021455-480bedc4908b @@ -17,9 +17,7 @@ require ( github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.4 // indirect github.com/rhnvrm/simples3 v0.2.4-0.20191018074503-3d5b071ef727 - github.com/satori/go.uuid v1.2.0 github.com/spf13/pflag v1.0.3 - github.com/stretchr/objx v0.2.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 // indirect golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd // indirect diff --git a/go.sum b/go.sum index 65e59ac..fcbf307 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/aws/aws-sdk-go v1.25.12 h1:a4h2FxoUJq9h+hajSE/dsRiqoOniIh6BkzhxMjkepzY= -github.com/aws/aws-sdk-go v1.25.12/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= 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= @@ -13,33 +11,21 @@ github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= +github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 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/jinzhu/gorm v1.9.1 h1:lDSDtsCt5AGGSKTs8AHlSDbbgif4G4+CKJ8ETBDVHTA= github.com/jinzhu/gorm v1.9.1/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= -github.com/jordan-wright/email v0.0.0-20181027021455-480bedc4908b h1:veTPVnbkOijplSJVywDYKDRPoZEN39kfuMDzzRKP0FA= -github.com/jordan-wright/email v0.0.0-20181027021455-480bedc4908b/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A= -github.com/knadh/email v0.0.0-20181027021455-480bedc4908b h1:EJPKWXCv9G08Gs5KWjUP8PKj8trrRsLO8B90KZycApE= -github.com/knadh/email v0.0.0-20181027021455-480bedc4908b/go.mod h1:xqJp94kA9qz2ffXuDJueBN+K6MP5BfEGmbIHR8MDJOo= github.com/knadh/email v0.0.0-20200206100304-6d2c7064c2e8 h1:HVq7nA5uWjpo93WsWjva1YIBuQrr8UkWQEUbzg1DX+E= github.com/knadh/email v0.0.0-20200206100304-6d2c7064c2e8/go.mod h1:Fy2gCFfZhay8jplf/Csj6cyH/oshQTkLQYZbKkcV+SY= -github.com/knadh/goyesql v1.1.1 h1:iQLgsjYI/zC417DhmZYxmJgWmCHhtV4fho5QazWL/1g= -github.com/knadh/goyesql v1.1.1/go.mod h1:W0tSzU8l7lYH1Fihj+bdQzkzOwvirrsMNHwkuY22qoY= github.com/knadh/goyesql v2.0.0+incompatible h1:hJFJrU8kaiLmvYt9I/1k1AB7q+qRhHs/afzTfQ3eGqk= github.com/knadh/goyesql v2.0.0+incompatible/go.mod h1:W0tSzU8l7lYH1Fihj+bdQzkzOwvirrsMNHwkuY22qoY= -github.com/knadh/koanf v0.4.2 h1:A/bb9+eRoHHHQ57O6y66vzRCYui915CK3FdDYzNs56Q= -github.com/knadh/koanf v0.4.2/go.mod h1:Qd5yvXN39ZzjoRJdXMKN2QqHzQKhSx/K8fU5gyn4LPs= -github.com/knadh/koanf v0.4.3 h1:aeCEnL10SVOIxnhhS3FeFtfvzC3RBphdhhrESE9qfCI= -github.com/knadh/koanf v0.4.3/go.mod h1:Qd5yvXN39ZzjoRJdXMKN2QqHzQKhSx/K8fU5gyn4LPs= github.com/knadh/koanf v0.4.4 h1:Pg+eR7wuJtCGHLeip31K20eJojjZ3lXE8ILQQGj2PTM= github.com/knadh/koanf v0.4.4/go.mod h1:Qd5yvXN39ZzjoRJdXMKN2QqHzQKhSx/K8fU5gyn4LPs= -github.com/knadh/stuffbin v0.0.0-20190103171338-6379e949be48 h1:lRb28d0+iiVwqF7Li25IJXjNRaVCQPH6n/fHwk9Qo+E= -github.com/knadh/stuffbin v0.0.0-20190103171338-6379e949be48/go.mod h1:afUOPBWr6bZ09aS3wbSOqXVGaO6rKcyvXYTcuG9LYpI= github.com/knadh/stuffbin v1.0.0 h1:NQon6PTpLXies4bRFhS3VpLCf6y+jn6YVXU3i2wPQ+M= github.com/knadh/stuffbin v1.0.0/go.mod h1:yVCFaWaKPubSNibBsTAJ939q2ABHudJQxRWZWV5yh+4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -65,16 +51,11 @@ github.com/pelletier/go-toml v1.4.0 h1:u3Z1r+oOXJIkxqw34zVhyPgjBsm6X2wn21NWs/HfS github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= 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/rhnvrm/simples3 v0.2.3 h1:qNXPynabu8M3F4+69fspA5aWZR8jqVV1RQtv2xc1OVk= -github.com/rhnvrm/simples3 v0.2.3/go.mod h1:iphavgjkW1uvoIiqLUX6D42XuuI9Cr+B/63xw3gb9qA= github.com/rhnvrm/simples3 v0.2.4-0.20191018074503-3d5b071ef727 h1:2josYcx2gm3CT0WMqi0jBagvg50V3UMWlYN/CnBEbSI= github.com/rhnvrm/simples3 v0.2.4-0.20191018074503-3d5b071ef727/go.mod h1:iphavgjkW1uvoIiqLUX6D42XuuI9Cr+B/63xw3gb9qA= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= diff --git a/install.go b/install.go index 98eb6cd..22b3bf7 100644 --- a/install.go +++ b/install.go @@ -8,11 +8,11 @@ import ( "strings" "time" + "github.com/gofrs/uuid" "github.com/jmoiron/sqlx" "github.com/knadh/goyesql" "github.com/knadh/listmonk/models" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" ) // install runs the first time setup of creating and @@ -54,7 +54,7 @@ func install(app *App, qMap goyesql.Queries, prompt bool) { optinList int ) if err := q.CreateList.Get(&defList, - uuid.NewV4().String(), + uuid.Must(uuid.NewV4()), "Default list", models.ListTypePrivate, models.ListOptinSingle, @@ -63,7 +63,7 @@ func install(app *App, qMap goyesql.Queries, prompt bool) { logger.Fatalf("Error creating list: %v", err) } - if err := q.CreateList.Get(&optinList, uuid.NewV4().String(), + if err := q.CreateList.Get(&optinList, uuid.Must(uuid.NewV4()), "Opt-in list", models.ListTypePublic, models.ListOptinDouble, @@ -74,7 +74,7 @@ func install(app *App, qMap goyesql.Queries, prompt bool) { // Sample subscriber. if _, err := q.UpsertSubscriber.Exec( - uuid.NewV4(), + uuid.Must(uuid.NewV4()), "john@example.com", "John Doe", `{"type": "known", "good": true, "city": "Bengaluru"}`, @@ -83,7 +83,7 @@ func install(app *App, qMap goyesql.Queries, prompt bool) { logger.Fatalf("Error creating subscriber: %v", err) } if _, err := q.UpsertSubscriber.Exec( - uuid.NewV4(), + uuid.Must(uuid.NewV4()), "anon@example.com", "Anon Doe", `{"type": "unknown", "good": true, "city": "Bengaluru"}`, @@ -112,7 +112,7 @@ func install(app *App, qMap goyesql.Queries, prompt bool) { // Sample campaign. sendAt := time.Now() sendAt.Add(time.Minute * 43200) - if _, err := q.CreateCampaign.Exec(uuid.NewV4(), + if _, err := q.CreateCampaign.Exec(uuid.Must(uuid.NewV4()), models.CampaignTypeRegular, "Test campaign", "Welcome to listmonk", diff --git a/lists.go b/lists.go index 0dcba56..344bc97 100644 --- a/lists.go +++ b/lists.go @@ -5,9 +5,9 @@ import ( "net/http" "strconv" + "github.com/gofrs/uuid" "github.com/knadh/listmonk/models" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" "github.com/asaskevich/govalidator" "github.com/labstack/echo" @@ -85,9 +85,15 @@ func handleCreateList(c echo.Context) error { "Invalid length for the name field.") } + uu, err := uuid.NewV4() + if err != nil { + app.Logger.Println("error generating UUID: %v", err) + return echo.NewHTTPError(http.StatusInternalServerError, "Error generating UUID") + } + // Insert and read ID. var newID int - o.UUID = uuid.NewV4().String() + o.UUID = uu.String() if err := app.Queries.CreateList.Get(&newID, o.UUID, o.Name, diff --git a/manager_db.go b/manager_db.go index 96a6c57..49aba36 100644 --- a/manager_db.go +++ b/manager_db.go @@ -1,9 +1,9 @@ package main import ( + "github.com/gofrs/uuid" "github.com/knadh/listmonk/models" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" ) // runnerDB implements runner.DataSource over the primary @@ -52,10 +52,15 @@ func (r *runnerDB) UpdateCampaignStatus(campID int, status string) error { func (r *runnerDB) CreateLink(url string) (string, error) { // Create a new UUID for the URL. If the URL already exists in the DB // the UUID in the database is returned. - var uu string - if err := r.queries.CreateLink.Get(&uu, uuid.NewV4(), url); err != nil { + uu, err := uuid.NewV4() + if err != nil { return "", err } - return uu, nil + var out string + if err := r.queries.CreateLink.Get(&out, uu, url); err != nil { + return "", err + } + + return out, nil } diff --git a/media.go b/media.go index 1f3fb9f..cbabbb7 100644 --- a/media.go +++ b/media.go @@ -5,9 +5,9 @@ import ( "net/http" "strconv" + "github.com/gofrs/uuid" "github.com/knadh/listmonk/media" "github.com/labstack/echo" - uuid "github.com/satori/go.uuid" ) var imageMimes = []string{"image/jpg", "image/jpeg", "image/png", "image/svg", "image/gif"} @@ -68,6 +68,7 @@ func handleUploadMedia(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Error opening image for resizing: %s", err)) } + // Upload thumbnail. thumbfName, err := app.Media.Put(thumbPrefix+fName, typ, thumbFile) if err != nil { @@ -75,8 +76,15 @@ func handleUploadMedia(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Error saving thumbnail: %s", err)) } + + uu, err := uuid.NewV4() + if err != nil { + app.Logger.Println("error generating UUID: %v", err) + return echo.NewHTTPError(http.StatusInternalServerError, "Error generating UUID") + } + // Write to the DB. - if _, err := app.Queries.InsertMedia.Exec(uuid.NewV4(), fName, thumbfName, 0, 0); err != nil { + if _, err := app.Queries.InsertMedia.Exec(uu, fName, thumbfName, 0, 0); err != nil { cleanUp = true return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Error saving uploaded file to db: %s", pqErrMsg(err))) diff --git a/subimporter/importer.go b/subimporter/importer.go index 2aeee21..8b87de9 100644 --- a/subimporter/importer.go +++ b/subimporter/importer.go @@ -21,8 +21,8 @@ import ( "strings" "sync" + "github.com/gofrs/uuid" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" "github.com/asaskevich/govalidator" "github.com/knadh/listmonk/models" @@ -253,11 +253,17 @@ func (s *Session) Start() { } } - var err error + uu, err := uuid.NewV4() + if err != nil { + s.log.Printf("error generating UUID: %v", err) + tx.Rollback() + break + } + if s.mode == ModeSubscribe { - _, err = stmt.Exec(uuid.NewV4(), sub.Email, sub.Name, sub.Attribs, listIDs) + _, err = stmt.Exec(uu, sub.Email, sub.Name, sub.Attribs, listIDs) } else if s.mode == ModeBlacklist { - _, err = stmt.Exec(uuid.NewV4(), sub.Email, sub.Name, sub.Attribs) + _, err = stmt.Exec(uu, sub.Email, sub.Name, sub.Attribs) } if err != nil { s.log.Printf("error executing insert: %v", err) diff --git a/subscribers.go b/subscribers.go index c62daa6..1e0020b 100644 --- a/subscribers.go +++ b/subscribers.go @@ -11,11 +11,11 @@ import ( "strings" "github.com/asaskevich/govalidator" + "github.com/gofrs/uuid" "github.com/knadh/listmonk/models" "github.com/knadh/listmonk/subimporter" "github.com/labstack/echo" "github.com/lib/pq" - uuid "github.com/satori/go.uuid" ) // subQueryReq is a "catch all" struct for reading various @@ -496,8 +496,13 @@ func handleExportSubscriberData(c echo.Context) error { // insertSubscriber inserts a subscriber and returns the ID. func insertSubscriber(req subimporter.SubReq, app *App) (int, error) { - req.UUID = uuid.NewV4().String() - err := app.Queries.InsertSubscriber.Get(&req.ID, + uu, err := uuid.NewV4() + if err != nil { + return 0, err + } + req.UUID = uu.String() + + err = app.Queries.InsertSubscriber.Get(&req.ID, req.UUID, req.Email, strings.TrimSpace(req.Name),