diff --git a/.golangci.yml b/.golangci.yml
index a947ef2..0338df0 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -12,6 +12,9 @@ linters:
- funlen
# Magic numbers everywhere and we can't get rid of them.
- gomnd
+ # This linter MIGHT BE good, but who decided that I want keepFor in
+ # JSON instead of keep_for for KeepFor field?
+ - tagliatelle
linters-settings:
lll:
line-length: 420
@@ -19,3 +22,10 @@ linters-settings:
min-complexity: 50
gocyclo:
min-complexity: 40
+
+issues:
+ exclude-rules:
+ # There will be some ToDos.
+ - linters:
+ - godox
+ text: "TODO"
diff --git a/cmd/fastpastebin/fastpastebin.go b/cmd/fastpastebin/fastpastebin.go
index a88a03a..2855948 100644
--- a/cmd/fastpastebin/fastpastebin.go
+++ b/cmd/fastpastebin/fastpastebin.go
@@ -25,12 +25,10 @@
package main
import (
- // stdlib
"os"
"os/signal"
"syscall"
- // local
"go.dev.pztrn.name/fastpastebin/domains/dbnotavailable"
"go.dev.pztrn.name/fastpastebin/domains/indexpage"
"go.dev.pztrn.name/fastpastebin/domains/pastes"
diff --git a/domains/dbnotavailable/dbnotavailable.go b/domains/dbnotavailable/dbnotavailable.go
index 02b43ba..9369094 100644
--- a/domains/dbnotavailable/dbnotavailable.go
+++ b/domains/dbnotavailable/dbnotavailable.go
@@ -25,17 +25,13 @@
package dbnotavailable
import (
- // stdlib
"net/http"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/templater"
-
- // other
"github.com/labstack/echo"
+ "go.dev.pztrn.name/fastpastebin/internal/templater"
)
-// Database not available error page
+// Database not available error page.
func dbNotAvailableGet(ec echo.Context) error {
htmlData := templater.GetTemplate(ec, "database_not_available.html", nil)
diff --git a/domains/dbnotavailable/exported.go b/domains/dbnotavailable/exported.go
index cd4c330..39defe8 100644
--- a/domains/dbnotavailable/exported.go
+++ b/domains/dbnotavailable/exported.go
@@ -25,13 +25,10 @@
package dbnotavailable
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
)
-var (
- c *context.Context
-)
+var c *context.Context
// New initializes pastes package and adds necessary HTTP and API
// endpoints.
diff --git a/domains/indexpage/exported.go b/domains/indexpage/exported.go
index f326f80..f842b58 100644
--- a/domains/indexpage/exported.go
+++ b/domains/indexpage/exported.go
@@ -25,13 +25,10 @@
package indexpage
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
)
-var (
- c *context.Context
-)
+var c *context.Context
// New initializes pastes package and adds necessary HTTP and API
// endpoints.
diff --git a/domains/indexpage/indexpage.go b/domains/indexpage/indexpage.go
index 293430f..a97c2c5 100644
--- a/domains/indexpage/indexpage.go
+++ b/domains/indexpage/indexpage.go
@@ -25,30 +25,27 @@
package indexpage
import (
- // stdlib
"net/http"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/captcha"
- "go.dev.pztrn.name/fastpastebin/internal/templater"
-
- // other
"github.com/alecthomas/chroma/lexers"
"github.com/labstack/echo"
+ "go.dev.pztrn.name/fastpastebin/internal/captcha"
+ "go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
+ "go.dev.pztrn.name/fastpastebin/internal/templater"
)
// Index of this site.
func indexGet(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
- if c.Config.Database.Type != "flatfiles" && dbConn == nil {
+ if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available")
}
// Generate list of available languages to highlight.
availableLexers := lexers.Names(false)
- var availableLexersSelectOpts = ""
+ availableLexersSelectOpts := ""
for i := range availableLexers {
availableLexersSelectOpts += ""
}
diff --git a/domains/pastes/exported.go b/domains/pastes/exported.go
index ef7d526..ba9e043 100644
--- a/domains/pastes/exported.go
+++ b/domains/pastes/exported.go
@@ -25,20 +25,14 @@
package pastes
import (
- // stdlib
"regexp"
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
)
-var (
- regexInts = regexp.MustCompile("[0-9]+")
-)
+var regexInts = regexp.MustCompile("[0-9]+")
-var (
- c *context.Context
-)
+var c *context.Context
// New initializes pastes package and adds necessary HTTP and API
// endpoints.
diff --git a/domains/pastes/paste_get.go b/domains/pastes/paste_get.go
index 060ef84..68c8f45 100644
--- a/domains/pastes/paste_get.go
+++ b/domains/pastes/paste_get.go
@@ -1,23 +1,20 @@
package pastes
import (
- // stdlib
"bytes"
"net/http"
"strconv"
"time"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/structs"
- "go.dev.pztrn.name/fastpastebin/internal/templater"
-
- // other
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters"
htmlfmt "github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
"github.com/labstack/echo"
+ "go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
+ "go.dev.pztrn.name/fastpastebin/internal/structs"
+ "go.dev.pztrn.name/fastpastebin/internal/templater"
)
const (
@@ -38,12 +35,14 @@ func pasteGetData(pasteID int, timestamp int64, cookieValue string) (*structs.Pa
paste, err1 := c.Database.GetPaste(pasteID)
if err1 != nil {
c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste")
+
return nil, pasteNotFound
}
// Check if paste is expired.
if paste.IsExpired() {
c.Logger.Error().Int("paste ID", pasteID).Msg("Paste is expired")
+
return nil, pasteExpired
}
@@ -52,6 +51,7 @@ func pasteGetData(pasteID int, timestamp int64, cookieValue string) (*structs.Pa
pasteTs := paste.CreatedAt.Unix()
if timestamp != pasteTs {
c.Logger.Error().Int("paste ID", pasteID).Int64("paste timestamp", pasteTs).Int64("provided timestamp", timestamp).Msg("Incorrect timestamp provided for private paste")
+
return nil, pasteTimestampInvalid
}
}
@@ -109,18 +109,20 @@ func pasteGETWebInterface(ec echo.Context) error {
cookieValue = cookie.Value
}
- paste, error := pasteGetData(pasteID, timestamp, cookieValue)
+ paste, err := pasteGetData(pasteID, timestamp, cookieValue)
// For these cases we should return 404 Not Found page.
- if error == pasteExpired || error == pasteNotFound || error == pasteTimestampInvalid {
+ if err == pasteExpired || err == pasteNotFound || err == pasteTimestampInvalid {
errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found")
+
return ec.HTML(http.StatusNotFound, errtpl)
}
// If passed cookie value was invalid - go to paste authorization
// page.
- if error == pasteCookieInvalid {
+ if err == pasteCookieInvalid {
c.Logger.Info().Int("paste ID", pasteID).Msg("Invalid cookie, redirecting to auth page")
+
return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDStr+"/"+ec.Param("timestamp")+"/verify")
}
@@ -212,6 +214,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
if cookieValue == cookie.Value {
c.Logger.Info().Msg("Valid cookie, redirecting to paste page...")
+
return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDRaw+"/"+ec.Param("timestamp"))
}
@@ -233,7 +236,7 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
- if c.Config.Database.Type != "flatfiles" && dbConn == nil {
+ if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available")
}
@@ -284,7 +287,7 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
func pasteRawGETWebInterface(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
- if c.Config.Database.Type != "flatfiles" && dbConn == nil {
+ if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available/raw")
}
@@ -298,11 +301,13 @@ func pasteRawGETWebInterface(ec echo.Context) error {
paste, err1 := c.Database.GetPaste(pasteID)
if err1 != nil {
c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste from database")
+
return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
}
if paste.IsExpired() {
c.Logger.Error().Int("paste ID", pasteID).Msg("Paste is expired")
+
return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
}
diff --git a/domains/pastes/paste_post.go b/domains/pastes/paste_post.go
index 8014805..5058bd4 100644
--- a/domains/pastes/paste_post.go
+++ b/domains/pastes/paste_post.go
@@ -1,30 +1,29 @@
package pastes
import (
- // stdlib
"net/http"
"regexp"
"strconv"
"strings"
"time"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/captcha"
- "go.dev.pztrn.name/fastpastebin/internal/structs"
- "go.dev.pztrn.name/fastpastebin/internal/templater"
-
- // other
"github.com/alecthomas/chroma/lexers"
"github.com/labstack/echo"
+ "go.dev.pztrn.name/fastpastebin/internal/captcha"
+ "go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
+ "go.dev.pztrn.name/fastpastebin/internal/structs"
+ "go.dev.pztrn.name/fastpastebin/internal/templater"
)
+const KeepPastesForever = "forever"
+
// POST for "/paste/" which will create new paste and redirect to
// "/pastes/CREATED_PASTE_ID". This handler will do all the job for
// requests comes from browsers via web interface.
func pastePOSTWebInterface(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
- if c.Config.Database.Type != "flatfiles" && dbConn == nil {
+ if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available")
}
@@ -48,7 +47,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
return ec.HTML(http.StatusBadRequest, errtpl)
}
- if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != "forever" {
+ if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != KeepPastesForever {
c.Logger.Debug().Str("field value", params["paste-keep-for"][0]).Msg("'Keep paste for' field have invalid value")
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
@@ -80,7 +79,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
keepFor := 0
keepForUnit := 0
- if params["paste-keep-for"][0] != "forever" {
+ if params["paste-keep-for"][0] != KeepPastesForever {
keepForUnitRegex := regexp.MustCompile("[Mmhd]")
keepForRaw := regexInts.FindAllString(params["paste-keep-for"][0], 1)[0]
@@ -89,7 +88,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
keepFor, err = strconv.Atoi(keepForRaw)
if err != nil {
- if params["paste-keep-for"][0] == "forever" {
+ if params["paste-keep-for"][0] == KeepPastesForever {
c.Logger.Debug().Msg("Keeping paste forever!")
keepFor = 0
diff --git a/domains/pastes/pastes_get.go b/domains/pastes/pastes_get.go
index 5516066..81f2508 100644
--- a/domains/pastes/pastes_get.go
+++ b/domains/pastes/pastes_get.go
@@ -25,17 +25,14 @@
package pastes
import (
- // stdlib
"net/http"
"strconv"
"strings"
- // local
+ "github.com/labstack/echo"
+ "go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
"go.dev.pztrn.name/fastpastebin/internal/pagination"
"go.dev.pztrn.name/fastpastebin/internal/templater"
-
- // other
- "github.com/labstack/echo"
)
// GET for "/pastes/", a list of publicly available pastes.
@@ -43,13 +40,13 @@ import (
func pastesGET(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
- if c.Config.Database.Type != "flatfiles" && dbConn == nil {
+ if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available")
}
pageFromParamRaw := ec.Param("page")
- var page = 1
+ page := 1
if pageFromParamRaw != "" {
pageRaw := regexInts.FindAllString(pageFromParamRaw, 1)[0]
@@ -62,7 +59,7 @@ func pastesGET(ec echo.Context) error {
pastes, err3 := c.Database.GetPagedPastes(page)
c.Logger.Debug().Int("count", len(pastes)).Msg("Got pastes")
- var pastesString = "No pastes to show."
+ pastesString := "No pastes to show."
// Show "No pastes to show" on any error for now.
if err3 != nil {
diff --git a/internal/captcha/exported.go b/internal/captcha/exported.go
index b36323d..8b89e5f 100644
--- a/internal/captcha/exported.go
+++ b/internal/captcha/exported.go
@@ -25,13 +25,10 @@
package captcha
import (
- // local
- "go.dev.pztrn.name/fastpastebin/internal/context"
-
- // other
"github.com/dchest/captcha"
"github.com/labstack/echo"
"github.com/rs/zerolog"
+ "go.dev.pztrn.name/fastpastebin/internal/context"
)
var (
diff --git a/internal/config/http.go b/internal/config/http.go
index 8601f77..a6fe77a 100644
--- a/internal/config/http.go
+++ b/internal/config/http.go
@@ -28,6 +28,6 @@ package config
type HTTP struct {
Address string `yaml:"address"`
Port string `yaml:"port"`
- AllowInsecure bool `yaml:"allow_insecure"`
MaxBodySizeMegabytes string `yaml:"max_body_size_megabytes"`
+ AllowInsecure bool `yaml:"allow_insecure"`
}
diff --git a/internal/config/logging.go b/internal/config/logging.go
index df6539f..8cb1e21 100644
--- a/internal/config/logging.go
+++ b/internal/config/logging.go
@@ -26,7 +26,7 @@ package config
// Logging describes logger configuration.
type Logging struct {
- LogToFile bool `yaml:"log_to_file"`
FileName string `yaml:"filename"`
LogLevel string `yaml:"loglevel"`
+ LogToFile bool `yaml:"log_to_file"`
}
diff --git a/internal/context/context.go b/internal/context/context.go
index 042564e..64987c3 100644
--- a/internal/context/context.go
+++ b/internal/context/context.go
@@ -25,18 +25,14 @@
package context
import (
- // stdlib
"io/ioutil"
"os"
"path/filepath"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/config"
- databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
-
- // other
"github.com/labstack/echo"
"github.com/rs/zerolog"
+ "go.dev.pztrn.name/fastpastebin/internal/config"
+ databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
"go.dev.pztrn.name/flagger"
"gopkg.in/yaml.v2"
)
diff --git a/internal/context/http_server.go b/internal/context/http_server.go
index 44f44d6..735e023 100644
--- a/internal/context/http_server.go
+++ b/internal/context/http_server.go
@@ -1,12 +1,9 @@
package context
import (
- // local
- "go.dev.pztrn.name/fastpastebin/assets/static"
-
- // other
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
+ "go.dev.pztrn.name/fastpastebin/assets/static"
)
func (c *Context) initializeHTTPServer() {
diff --git a/internal/context/logger.go b/internal/context/logger.go
index 718f750..b16c240 100644
--- a/internal/context/logger.go
+++ b/internal/context/logger.go
@@ -1,14 +1,12 @@
package context
import (
- // stdlib
"fmt"
"os"
"runtime"
"strings"
"time"
- // other
"github.com/rs/zerolog"
)
diff --git a/internal/database/database.go b/internal/database/database.go
index 4de4ef4..8684cf7 100644
--- a/internal/database/database.go
+++ b/internal/database/database.go
@@ -25,19 +25,15 @@
package database
import (
- // stdlib
"database/sql"
"time"
- // local
+ _ "github.com/go-sql-driver/mysql"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/mysql"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/postgresql"
"go.dev.pztrn.name/fastpastebin/internal/structs"
-
- // other
- _ "github.com/go-sql-driver/mysql"
)
// Database represents control structure for database connection.
@@ -111,7 +107,7 @@ func (db *Database) Initialize() {
if c.Config.Database.Type == "mysql" {
mysql.New(c)
- } else if c.Config.Database.Type == "flatfiles" {
+ } else if c.Config.Database.Type == flatfiles.FlatFileDialect {
flatfiles.New(c)
} else if c.Config.Database.Type == "postgresql" {
postgresql.New(c)
diff --git a/internal/database/dialects/flatfiles/exported.go b/internal/database/dialects/flatfiles/exported.go
index 3c384ce..6245a7e 100644
--- a/internal/database/dialects/flatfiles/exported.go
+++ b/internal/database/dialects/flatfiles/exported.go
@@ -25,11 +25,12 @@
package flatfiles
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
)
+const FlatFileDialect = "flatfiles"
+
var (
c *context.Context
f *FlatFiles
diff --git a/internal/database/dialects/flatfiles/flatfiles.go b/internal/database/dialects/flatfiles/flatfiles.go
index 9c03c19..93f809e 100644
--- a/internal/database/dialects/flatfiles/flatfiles.go
+++ b/internal/database/dialects/flatfiles/flatfiles.go
@@ -25,7 +25,6 @@
package flatfiles
import (
- // stdlib
"database/sql"
"encoding/json"
"io/ioutil"
@@ -36,14 +35,13 @@ import (
"strings"
"sync"
- // local
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
type FlatFiles struct {
+ writeMutex sync.Mutex
path string
pastesIndex []Index
- writeMutex sync.Mutex
}
// DeletePaste deletes paste from disk and index.
@@ -89,6 +87,7 @@ func (ff *FlatFiles) GetPaste(pasteID int) (*structs.Paste, error) {
pasteInBytes, err := ioutil.ReadFile(pastePath)
if err != nil {
c.Logger.Debug().Err(err).Msg("Failed to read paste from storage")
+
return nil, err
}
@@ -100,6 +99,7 @@ func (ff *FlatFiles) GetPaste(pasteID int) (*structs.Paste, error) {
err1 := json.Unmarshal(pasteInBytes, paste)
if err1 != nil {
c.Logger.Error().Err(err1).Msgf("Failed to parse paste")
+
return nil, err1
}
@@ -132,11 +132,13 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
if idx < startPagination {
c.Logger.Debug().Int("paste index", idx).Msg("Paste isn't in pagination query: too low index")
+
continue
}
if (idx-1 >= startPagination && page > 1 && idx > startPagination+((page-1)*c.Config.Pastes.Pagination)) || (idx-1 >= startPagination && page == 1 && idx > startPagination+(page*c.Config.Pastes.Pagination)) {
c.Logger.Debug().Int("paste index", idx).Msg("Paste isn't in pagination query: too high index")
+
break
}
@@ -148,12 +150,14 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
pasteRawData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
if err != nil {
c.Logger.Error().Err(err).Msg("Failed to read paste data")
+
continue
}
err1 := json.Unmarshal(pasteRawData, pasteData)
if err1 != nil {
c.Logger.Error().Err(err1).Msg("Failed to parse paste data")
+
continue
}
@@ -253,12 +257,14 @@ func (ff *FlatFiles) SavePaste(p *structs.Paste) (int64, error) {
data, err := json.Marshal(p)
if err != nil {
ff.writeMutex.Unlock()
+
return 0, err
}
err = ioutil.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0644)
if err != nil {
ff.writeMutex.Unlock()
+
return 0, err
}
@@ -278,12 +284,14 @@ func (ff *FlatFiles) Shutdown() {
indexData, err := json.Marshal(ff.pastesIndex)
if err != nil {
c.Logger.Error().Err(err).Msg("Failed to encode index data into JSON")
+
return
}
err1 := ioutil.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0644)
if err1 != nil {
c.Logger.Error().Err(err1).Msg("Failed to write index data to file. Pretty sure that you've lost your pastes.")
+
return
}
}
diff --git a/internal/database/dialects/flatfiles/handler.go b/internal/database/dialects/flatfiles/handler.go
index dcb26d3..190461f 100644
--- a/internal/database/dialects/flatfiles/handler.go
+++ b/internal/database/dialects/flatfiles/handler.go
@@ -25,10 +25,8 @@
package flatfiles
import (
- // stdlib
"database/sql"
- // local
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/database/dialects/interface/dialectinterface.go b/internal/database/dialects/interface/dialectinterface.go
index 711fa3f..c6d3bdd 100644
--- a/internal/database/dialects/interface/dialectinterface.go
+++ b/internal/database/dialects/interface/dialectinterface.go
@@ -25,10 +25,8 @@
package dialectinterface
import (
- // stdlib
"database/sql"
- // local
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/database/dialects/mysql/exported.go b/internal/database/dialects/mysql/exported.go
index 9e06184..df3a069 100644
--- a/internal/database/dialects/mysql/exported.go
+++ b/internal/database/dialects/mysql/exported.go
@@ -25,7 +25,6 @@
package mysql
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
)
diff --git a/internal/database/dialects/mysql/handler.go b/internal/database/dialects/mysql/handler.go
index c272b72..ff10edd 100644
--- a/internal/database/dialects/mysql/handler.go
+++ b/internal/database/dialects/mysql/handler.go
@@ -25,10 +25,8 @@
package mysql
import (
- // stdlib
"database/sql"
- // local
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/database/dialects/mysql/migrations/1_initial.go b/internal/database/dialects/mysql/migrations/1_initial.go
index d6a8a31..cf45a46 100644
--- a/internal/database/dialects/mysql/migrations/1_initial.go
+++ b/internal/database/dialects/mysql/migrations/1_initial.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/mysql/migrations/2_paste_lang.go b/internal/database/dialects/mysql/migrations/2_paste_lang.go
index e8988bd..3875bfa 100644
--- a/internal/database/dialects/mysql/migrations/2_paste_lang.go
+++ b/internal/database/dialects/mysql/migrations/2_paste_lang.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/mysql/migrations/3_private_pastes.go b/internal/database/dialects/mysql/migrations/3_private_pastes.go
index 9e70ee0..49838ce 100644
--- a/internal/database/dialects/mysql/migrations/3_private_pastes.go
+++ b/internal/database/dialects/mysql/migrations/3_private_pastes.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/mysql/migrations/4_passworded_pastes.go b/internal/database/dialects/mysql/migrations/4_passworded_pastes.go
index 224f439..5dd1f05 100644
--- a/internal/database/dialects/mysql/migrations/4_passworded_pastes.go
+++ b/internal/database/dialects/mysql/migrations/4_passworded_pastes.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/mysql/migrations/exported.go b/internal/database/dialects/mysql/migrations/exported.go
index fcb4c5a..67285f7 100644
--- a/internal/database/dialects/mysql/migrations/exported.go
+++ b/internal/database/dialects/mysql/migrations/exported.go
@@ -25,17 +25,11 @@
package migrations
import (
- // local
- "go.dev.pztrn.name/fastpastebin/internal/context"
-
- // other
- //"gitlab.com/jmoiron/sqlx"
"github.com/pressly/goose"
+ "go.dev.pztrn.name/fastpastebin/internal/context"
)
-var (
- c *context.Context
-)
+var c *context.Context
// New initializes migrations.
func New(cc *context.Context) {
diff --git a/internal/database/dialects/mysql/mysqldatabase.go b/internal/database/dialects/mysql/mysqldatabase.go
index 01a9dbb..80c32a9 100644
--- a/internal/database/dialects/mysql/mysqldatabase.go
+++ b/internal/database/dialects/mysql/mysqldatabase.go
@@ -25,17 +25,13 @@
package mysql
import (
- // stdlib
"database/sql"
"fmt"
- // local
- "go.dev.pztrn.name/fastpastebin/internal/database/dialects/mysql/migrations"
- "go.dev.pztrn.name/fastpastebin/internal/structs"
-
- // other
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
+ "go.dev.pztrn.name/fastpastebin/internal/database/dialects/mysql/migrations"
+ "go.dev.pztrn.name/fastpastebin/internal/structs"
)
// Database is a MySQL/MariaDB connection controlling structure.
@@ -169,6 +165,7 @@ func (db *Database) Initialize() {
dbConn, err := sqlx.Connect("mysql", dbConnString)
if err != nil {
c.Logger.Error().Err(err).Msg("Failed to connect to database")
+
return
}
diff --git a/internal/database/dialects/postgresql/exported.go b/internal/database/dialects/postgresql/exported.go
index 2fd991b..549fa33 100644
--- a/internal/database/dialects/postgresql/exported.go
+++ b/internal/database/dialects/postgresql/exported.go
@@ -25,7 +25,6 @@
package postgresql
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
)
diff --git a/internal/database/dialects/postgresql/handler.go b/internal/database/dialects/postgresql/handler.go
index 7ffac3c..df991d7 100644
--- a/internal/database/dialects/postgresql/handler.go
+++ b/internal/database/dialects/postgresql/handler.go
@@ -25,10 +25,8 @@
package postgresql
import (
- // stdlib
"database/sql"
- // local
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/database/dialects/postgresql/migrations/1_initial.go b/internal/database/dialects/postgresql/migrations/1_initial.go
index 51d2a2f..9284cf0 100644
--- a/internal/database/dialects/postgresql/migrations/1_initial.go
+++ b/internal/database/dialects/postgresql/migrations/1_initial.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/postgresql/migrations/2_paste_lang.go b/internal/database/dialects/postgresql/migrations/2_paste_lang.go
index e368317..688f6c1 100644
--- a/internal/database/dialects/postgresql/migrations/2_paste_lang.go
+++ b/internal/database/dialects/postgresql/migrations/2_paste_lang.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/postgresql/migrations/3_private_pastes.go b/internal/database/dialects/postgresql/migrations/3_private_pastes.go
index c9689b2..d9791ce 100644
--- a/internal/database/dialects/postgresql/migrations/3_private_pastes.go
+++ b/internal/database/dialects/postgresql/migrations/3_private_pastes.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/postgresql/migrations/4_passworded_pastes.go b/internal/database/dialects/postgresql/migrations/4_passworded_pastes.go
index 30ad80c..2e72d2c 100644
--- a/internal/database/dialects/postgresql/migrations/4_passworded_pastes.go
+++ b/internal/database/dialects/postgresql/migrations/4_passworded_pastes.go
@@ -25,7 +25,6 @@
package migrations
import (
- // stdlib
"database/sql"
)
diff --git a/internal/database/dialects/postgresql/migrations/exported.go b/internal/database/dialects/postgresql/migrations/exported.go
index 5f76c48..c7c9b53 100644
--- a/internal/database/dialects/postgresql/migrations/exported.go
+++ b/internal/database/dialects/postgresql/migrations/exported.go
@@ -25,17 +25,11 @@
package migrations
import (
- // local
- "go.dev.pztrn.name/fastpastebin/internal/context"
-
- // other
- //"gitlab.com/jmoiron/sqlx"
"github.com/pressly/goose"
+ "go.dev.pztrn.name/fastpastebin/internal/context"
)
-var (
- c *context.Context
-)
+var c *context.Context
// New initializes migrations.
func New(cc *context.Context) {
diff --git a/internal/database/dialects/postgresql/postgresqldatabase.go b/internal/database/dialects/postgresql/postgresqldatabase.go
index b61c709..170b192 100644
--- a/internal/database/dialects/postgresql/postgresqldatabase.go
+++ b/internal/database/dialects/postgresql/postgresqldatabase.go
@@ -25,19 +25,14 @@
package postgresql
import (
- // stdlib
"database/sql"
"fmt"
"time"
- // local
+ "github.com/jmoiron/sqlx"
+ _ "github.com/lib/pq"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/postgresql/migrations"
"go.dev.pztrn.name/fastpastebin/internal/structs"
-
- // other
- "github.com/jmoiron/sqlx"
- // postgresql adapter
- _ "github.com/lib/pq"
)
// Database is a PostgreSQL connection controlling structure.
@@ -182,6 +177,7 @@ func (db *Database) Initialize() {
dbConn, err := sqlx.Connect("postgres", dbConnString)
if err != nil {
c.Logger.Error().Err(err).Msg("Failed to connect to database")
+
return
}
diff --git a/internal/database/exported.go b/internal/database/exported.go
index 30678aa..419238a 100644
--- a/internal/database/exported.go
+++ b/internal/database/exported.go
@@ -25,7 +25,6 @@
package database
import (
- // local
"go.dev.pztrn.name/fastpastebin/internal/context"
databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
)
diff --git a/internal/database/handler.go b/internal/database/handler.go
index e2a3791..f424ac8 100644
--- a/internal/database/handler.go
+++ b/internal/database/handler.go
@@ -25,11 +25,8 @@
package database
import (
- // stdlib
"database/sql"
- // local
-
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/database/interface/databaseinterface.go b/internal/database/interface/databaseinterface.go
index a1afd7a..1f12e0f 100644
--- a/internal/database/interface/databaseinterface.go
+++ b/internal/database/interface/databaseinterface.go
@@ -25,10 +25,8 @@
package databaseinterface
import (
- // stdlib
"database/sql"
- // local
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
"go.dev.pztrn.name/fastpastebin/internal/structs"
)
diff --git a/internal/pagination/exported.go b/internal/pagination/exported.go
index 5f74754..a822d1b 100644
--- a/internal/pagination/exported.go
+++ b/internal/pagination/exported.go
@@ -1,11 +1,9 @@
package pagination
import (
- // stdlib
"strconv"
"strings"
- // local
"go.dev.pztrn.name/fastpastebin/assets/static"
)
@@ -48,9 +46,11 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
)
for i <= pages {
+ // ToDo: fix it!
+ // nolint:nestif
if pages > 5 {
if currentPage-3 < i && currentPage+3 > i || i == pages {
- var paginationItemRaw = string(paginationLinkRaw)
+ paginationItemRaw := string(paginationLinkRaw)
if i == currentPage {
paginationItemRaw = string(paginationLinkCurrentRaw)
}
@@ -68,7 +68,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
}
}
} else {
- var paginationItemRaw = string(paginationLinkRaw)
+ paginationItemRaw := string(paginationLinkRaw)
if i == currentPage {
paginationItemRaw = string(paginationLinkCurrentRaw)
}
diff --git a/internal/structs/paste.go b/internal/structs/paste.go
index 191f732..067911a 100644
--- a/internal/structs/paste.go
+++ b/internal/structs/paste.go
@@ -25,13 +25,11 @@
package structs
import (
- // stdlib
"crypto/sha256"
"fmt"
"math/rand"
"time"
- // other
"golang.org/x/crypto/scrypt"
)
@@ -95,6 +93,7 @@ func (p *Paste) CreatePassword(password string) error {
// GenerateCryptedCookieValue generates crypted cookie value for paste.
func (p *Paste) GenerateCryptedCookieValue() string {
cookieValueCrypted, _ := scrypt.Key([]byte(p.Password), []byte(p.PasswordSalt), 131072, 8, 1, 64)
+
return fmt.Sprintf("%x", sha256.Sum256(cookieValueCrypted))
}
diff --git a/internal/templater/exported.go b/internal/templater/exported.go
index 857a69e..fc7c4f4 100644
--- a/internal/templater/exported.go
+++ b/internal/templater/exported.go
@@ -25,17 +25,13 @@
package templater
import (
- // stdlib
"net/http"
"strings"
- // local
- "go.dev.pztrn.name/fastpastebin/assets/static"
- "go.dev.pztrn.name/fastpastebin/internal/context"
-
- // other
"github.com/labstack/echo"
"github.com/rs/zerolog"
+ "go.dev.pztrn.name/fastpastebin/assets/static"
+ "go.dev.pztrn.name/fastpastebin/internal/context"
)
var (
@@ -59,6 +55,7 @@ func GetRawTemplate(ec echo.Context, templateName string, data map[string]string
tplRaw, err := static.ReadFile(templateName)
if err != nil {
_ = ec.String(http.StatusBadRequest, templateName+" not found.")
+
return ""
}
@@ -79,6 +76,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
mainhtml, err := static.ReadFile("main.html")
if err != nil {
_ = ec.String(http.StatusBadRequest, "main.html not found.")
+
return ""
}
@@ -86,6 +84,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
navhtml, err1 := static.ReadFile("navigation.html")
if err1 != nil {
_ = ec.String(http.StatusBadRequest, "navigation.html not found.")
+
return ""
}
@@ -93,6 +92,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
footerhtml, err2 := static.ReadFile("footer.html")
if err2 != nil {
_ = ec.String(http.StatusBadRequest, "footer.html not found.")
+
return ""
}
@@ -106,6 +106,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
reqhtml, err3 := static.ReadFile(name)
if err3 != nil {
_ = ec.String(http.StatusBadRequest, name+" not found.")
+
return ""
}