More Greater Linting.

This commit is contained in:
Stanislav Nikitin 2021-06-15 00:11:58 +05:00
parent 6ea6e2e144
commit 968d945205
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
28 changed files with 143 additions and 15 deletions

View File

@ -22,6 +22,8 @@ linters-settings:
min-complexity: 50 min-complexity: 50
gocyclo: gocyclo:
min-complexity: 40 min-complexity: 40
cyclop:
max-complexity: 40
issues: issues:
exclude-rules: exclude-rules:

View File

@ -35,9 +35,11 @@ import (
func dbNotAvailableGet(ec echo.Context) error { func dbNotAvailableGet(ec echo.Context) error {
htmlData := templater.GetTemplate(ec, "database_not_available.html", nil) htmlData := templater.GetTemplate(ec, "database_not_available.html", nil)
// nolint:wrapcheck
return ec.HTML(http.StatusInternalServerError, htmlData) return ec.HTML(http.StatusInternalServerError, htmlData)
} }
func dbNotAvailableRawGet(ec echo.Context) error { func dbNotAvailableRawGet(ec echo.Context) error {
// nolint:wrapcheck
return ec.String(http.StatusInternalServerError, "Database not available\nSomething went wrong while trying to connect to database. Check logs for details.") return ec.String(http.StatusInternalServerError, "Database not available\nSomething went wrong while trying to connect to database. Check logs for details.")
} }

View File

@ -39,6 +39,7 @@ func indexGet(ec echo.Context) error {
// We should check if database connection available. // We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil { if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/database_not_available") return ec.Redirect(http.StatusFound, "/database_not_available")
} }
@ -55,5 +56,6 @@ func indexGet(ec echo.Context) error {
htmlData := templater.GetTemplate(ec, "index.html", map[string]string{"lexers": availableLexersSelectOpts, "captchaString": captchaString}) htmlData := templater.GetTemplate(ec, "index.html", map[string]string{"lexers": availableLexersSelectOpts, "captchaString": captchaString})
// nolint:wrapcheck
return ec.HTML(http.StatusOK, htmlData) return ec.HTML(http.StatusOK, htmlData)
} }

View File

@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/alecthomas/chroma" "github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters"
htmlfmt "github.com/alecthomas/chroma/formatters/html" htmlfmt "github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/lexers" "github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles" "github.com/alecthomas/chroma/styles"
@ -48,9 +47,9 @@ func pasteGetData(pasteID int, timestamp int64, cookieValue string) (*structs.Pa
// Check if we have a private paste and it's parameters are correct. // Check if we have a private paste and it's parameters are correct.
if paste.Private { if paste.Private {
pasteTs := paste.CreatedAt.Unix() pasteTS := paste.CreatedAt.Unix()
if timestamp != pasteTs { 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") 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 return nil, pasteTimestampInvalid
} }
@ -94,6 +93,7 @@ func pasteGETWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDStr+" not found") errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDStr+" not found")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -115,6 +115,7 @@ func pasteGETWebInterface(ec echo.Context) error {
if err == pasteExpired || err == pasteNotFound || err == pasteTimestampInvalid { if err == pasteExpired || err == pasteNotFound || err == pasteTimestampInvalid {
errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found") errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found")
// nolint:wrapcheck
return ec.HTML(http.StatusNotFound, errtpl) return ec.HTML(http.StatusNotFound, errtpl)
} }
@ -123,6 +124,7 @@ func pasteGETWebInterface(ec echo.Context) error {
if err == pasteCookieInvalid { if err == pasteCookieInvalid {
c.Logger.Info().Int("paste ID", pasteID).Msg("Invalid cookie, redirecting to auth page") c.Logger.Info().Int("paste ID", pasteID).Msg("Invalid cookie, redirecting to auth page")
// nolint:wrapcheck
return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDStr+"/"+ec.Param("timestamp")+"/verify") return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDStr+"/"+ec.Param("timestamp")+"/verify")
} }
@ -166,9 +168,7 @@ func pasteGETWebInterface(ec echo.Context) error {
} }
// Get HTML formatter. // Get HTML formatter.
formatter := chroma.Formatter(htmlfmt.New(htmlfmt.WithLineNumbers(true), htmlfmt.LineNumbersInTable(true), htmlfmt.LinkableLineNumbers(true, "L"))) formatter := chroma.Formatter(htmlfmt.New(htmlfmt.WithLineNumbers(true), htmlfmt.LineNumbersInTable(true), htmlfmt.LinkableLineNumbers(true, "L")))
if formatter == nil {
formatter = formatters.Fallback
}
// Create buffer and format into it. // Create buffer and format into it.
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
@ -182,6 +182,7 @@ func pasteGETWebInterface(ec echo.Context) error {
// Get template and format it. // Get template and format it.
pasteHTML := templater.GetTemplate(ec, "paste.html", pasteData) pasteHTML := templater.GetTemplate(ec, "paste.html", pasteData)
// nolint:wrapcheck
return ec.HTML(http.StatusOK, pasteHTML) return ec.HTML(http.StatusOK, pasteHTML)
} }
@ -200,6 +201,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found") errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -215,6 +217,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
if cookieValue == cookie.Value { if cookieValue == cookie.Value {
c.Logger.Info().Msg("Valid cookie, redirecting to paste page...") c.Logger.Info().Msg("Valid cookie, redirecting to paste page...")
// nolint:wrapcheck
return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDRaw+"/"+ec.Param("timestamp")) return ec.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDRaw+"/"+ec.Param("timestamp"))
} }
@ -228,6 +231,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
verifyHTML := templater.GetTemplate(ec, "passworded_paste_verify.html", htmlData) verifyHTML := templater.GetTemplate(ec, "passworded_paste_verify.html", htmlData)
// nolint:wrapcheck
return ec.HTML(http.StatusOK, verifyHTML) return ec.HTML(http.StatusOK, verifyHTML)
} }
@ -237,6 +241,7 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil { if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/database_not_available") return ec.Redirect(http.StatusFound, "/database_not_available")
} }
@ -253,6 +258,7 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste") c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste")
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found") errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -262,6 +268,7 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found") errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -274,11 +281,13 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
cookie.Expires = time.Now().Add(24 * time.Hour) cookie.Expires = time.Now().Add(24 * time.Hour)
ec.SetCookie(cookie) ec.SetCookie(cookie)
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/paste/"+strconv.Itoa(pasteID)+"/"+timestampRaw) return ec.Redirect(http.StatusFound, "/paste/"+strconv.Itoa(pasteID)+"/"+timestampRaw)
} }
errtpl := templater.GetErrorTemplate(ec, "Invalid password. Please, try again.") errtpl := templater.GetErrorTemplate(ec, "Invalid password. Please, try again.")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -288,6 +297,7 @@ func pasteRawGETWebInterface(ec echo.Context) error {
// We should check if database connection available. // We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil { if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/database_not_available/raw") return ec.Redirect(http.StatusFound, "/database_not_available/raw")
} }
@ -302,12 +312,14 @@ func pasteRawGETWebInterface(ec echo.Context) error {
if err1 != nil { if err1 != nil {
c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste from database") c.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste from database")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.") return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
} }
if paste.IsExpired() { if paste.IsExpired() {
c.Logger.Error().Int("paste ID", pasteID).Msg("Paste is expired") c.Logger.Error().Int("paste ID", pasteID).Msg("Paste is expired")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.") return ec.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
} }
@ -319,13 +331,15 @@ func pasteRawGETWebInterface(ec echo.Context) error {
if err2 != nil { if err2 != nil {
c.Logger.Error().Err(err2).Int("paste ID", pasteID).Str("provided timestamp", tsProvidedStr).Msg("Invalid timestamp provided for getting private paste") c.Logger.Error().Err(err2).Int("paste ID", pasteID).Str("provided timestamp", tsProvidedStr).Msg("Invalid timestamp provided for getting private paste")
// nolint:wrapcheck
return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found") return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
} }
pasteTs := paste.CreatedAt.Unix() pasteTS := paste.CreatedAt.Unix()
if tsProvided != pasteTs { if tsProvided != pasteTS {
c.Logger.Error().Int("paste ID", pasteID).Int64("provided timestamp", tsProvided).Int64("paste timestamp", pasteTs).Msg("Incorrect timestamp provided for private paste") c.Logger.Error().Int("paste ID", pasteID).Int64("provided timestamp", tsProvided).Int64("paste timestamp", pasteTS).Msg("Incorrect timestamp provided for private paste")
// nolint:wrapcheck
return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found") return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
} }
} }
@ -338,5 +352,6 @@ func pasteRawGETWebInterface(ec echo.Context) error {
return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found") return ec.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
} }
// nolint:wrapcheck
return ec.String(http.StatusOK, paste.Data) return ec.String(http.StatusOK, paste.Data)
} }

View File

@ -24,6 +24,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
// We should check if database connection available. // We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil { if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/database_not_available") return ec.Redirect(http.StatusFound, "/database_not_available")
} }
@ -33,6 +34,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Cannot create empty paste") errtpl := templater.GetErrorTemplate(ec, "Cannot create empty paste")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -44,6 +46,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Empty pastes aren't allowed.") errtpl := templater.GetErrorTemplate(ec, "Empty pastes aren't allowed.")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -52,6 +55,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).") errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -61,9 +65,11 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Invalid captcha solution.") errtpl := templater.GetErrorTemplate(ec, "Invalid captcha solution.")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
// nolint:exhaustivestruct
paste := &structs.Paste{ paste := &structs.Paste{
Title: params["paste-title"][0], Title: params["paste-title"][0],
Data: params["paste-contents"][0], Data: params["paste-contents"][0],
@ -97,6 +103,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).") errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
} }
@ -137,6 +144,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
errtpl := templater.GetErrorTemplate(ec, "Failed to save paste. Please, try again later.") errtpl := templater.GetErrorTemplate(ec, "Failed to save paste. Please, try again later.")
// nolint:wrapcheck
return ec.HTML(http.StatusBadRequest, errtpl) return ec.HTML(http.StatusBadRequest, errtpl)
} }
@ -145,8 +153,10 @@ func pastePOSTWebInterface(ec echo.Context) error {
// Private pastes have it's timestamp in URL. // Private pastes have it's timestamp in URL.
if paste.Private { if paste.Private {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString+"/"+strconv.FormatInt(paste.CreatedAt.Unix(), 10)) return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString+"/"+strconv.FormatInt(paste.CreatedAt.Unix(), 10))
} }
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString) return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString)
} }

View File

@ -41,6 +41,7 @@ func pastesGET(ec echo.Context) error {
// We should check if database connection available. // We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil { if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
return ec.Redirect(http.StatusFound, "/database_not_available") return ec.Redirect(http.StatusFound, "/database_not_available")
} }
@ -67,6 +68,7 @@ func pastesGET(ec echo.Context) error {
noPastesToShowTpl := templater.GetErrorTemplate(ec, "No pastes to show.") noPastesToShowTpl := templater.GetErrorTemplate(ec, "No pastes to show.")
// nolint:wrapcheck
return ec.HTML(http.StatusOK, noPastesToShowTpl) return ec.HTML(http.StatusOK, noPastesToShowTpl)
} }
@ -104,5 +106,6 @@ func pastesGET(ec echo.Context) error {
pasteListTpl := templater.GetTemplate(ec, "pastelist_list.html", map[string]string{"pastes": pastesString, "pagination": paginationHTML}) pasteListTpl := templater.GetTemplate(ec, "pastelist_list.html", map[string]string{"pastes": pastesString, "pagination": paginationHTML})
// nolint:wrapcheck
return ec.HTML(http.StatusOK, pasteListTpl) return ec.HTML(http.StatusOK, pasteListTpl)
} }

1
go.mod
View File

@ -18,4 +18,5 @@ require (
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20201224014010-6772e930b67b golang.org/x/net v0.0.0-20201224014010-6772e930b67b
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
mvdan.cc/gofumpt v0.1.1 // indirect
) )

27
go.sum
View File

@ -24,8 +24,13 @@ github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= 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/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
@ -52,6 +57,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k= github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k=
github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8= github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs= github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs=
github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo=
@ -69,24 +75,34 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.dev.pztrn.name/flagger v0.0.0-20200617193309-89bc9818b76c h1:+GgFefaTLsYDS0lXc8LNzTo6tcsA9qO3EkTAKduPAsI= go.dev.pztrn.name/flagger v0.0.0-20200617193309-89bc9818b76c h1:+GgFefaTLsYDS0lXc8LNzTo6tcsA9qO3EkTAKduPAsI=
go.dev.pztrn.name/flagger v0.0.0-20200617193309-89bc9818b76c/go.mod h1:ttPExQNCubgqqO5Y19LfIBKqmWtBocY7P9MXQEECuZo= go.dev.pztrn.name/flagger v0.0.0-20200617193309-89bc9818b76c/go.mod h1:ttPExQNCubgqqO5Y19LfIBKqmWtBocY7P9MXQEECuZo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/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-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/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-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
@ -97,11 +113,22 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c h1:dS09fXwOFF9cXBnIzZexIuUBj95U1NyQjkEhkgidDow=
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
mvdan.cc/gofumpt v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=

View File

@ -100,6 +100,7 @@ func (c *Context) LoadConfiguration() {
c.Logger.Debug().Str("path", configPath).Msg("Configuration file path") c.Logger.Debug().Str("path", configPath).Msg("Configuration file path")
// nolint:exhaustivestruct
c.Config = &config.Struct{} c.Config = &config.Struct{}
// Read configuration file. // Read configuration file.

View File

@ -31,5 +31,6 @@ const (
// New creates new context. // New creates new context.
func New() *Context { func New() *Context {
// nolint:exhaustivestruct
return &Context{} return &Context{}
} }

View File

@ -24,6 +24,7 @@ func (c *Context) getMemoryUsage(e *zerolog.Event, level zerolog.Level, message
// Initializes logger. // Initializes logger.
func (c *Context) initializeLogger() { func (c *Context) initializeLogger() {
// Устанавливаем форматирование логгера. // Устанавливаем форматирование логгера.
// nolint:exhaustivestruct
output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339} output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: false, TimeFormat: time.RFC3339}
output.FormatLevel = func(i interface{}) string { output.FormatLevel = func(i interface{}) string {
var v string var v string

View File

@ -28,6 +28,7 @@ import (
"database/sql" "database/sql"
"time" "time"
// MySQL driver.
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles" "go.dev.pztrn.name/fastpastebin/internal/database/dialects/flatfiles"
dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface" dialectinterface "go.dev.pztrn.name/fastpastebin/internal/database/dialects/interface"
@ -78,6 +79,7 @@ func (db *Database) cleanup() {
} }
func (db *Database) DeletePaste(pasteID int) error { func (db *Database) DeletePaste(pasteID int) error {
// nolint:wrapcheck
return db.db.DeletePaste(pasteID) return db.db.DeletePaste(pasteID)
} }
@ -90,10 +92,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
} }
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) { func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
// nolint:wrapcheck
return db.db.GetPaste(pasteID) return db.db.GetPaste(pasteID)
} }
func (db *Database) GetPagedPastes(page int) ([]structs.Paste, error) { func (db *Database) GetPagedPastes(page int) ([]structs.Paste, error) {
// nolint:wrapcheck
return db.db.GetPagedPastes(page) return db.db.GetPagedPastes(page)
} }
@ -124,6 +128,7 @@ func (db *Database) RegisterDialect(di dialectinterface.Interface) {
} }
func (db *Database) SavePaste(p *structs.Paste) (int64, error) { func (db *Database) SavePaste(p *structs.Paste) (int64, error) {
// nolint:wrapcheck
return db.db.SavePaste(p) return db.db.SavePaste(p)
} }

View File

@ -38,6 +38,7 @@ var (
func New(cc *context.Context) { func New(cc *context.Context) {
c = cc c = cc
// nolint:exhaustivestruct
f = &FlatFiles{} f = &FlatFiles{}
c.Database.RegisterDialect(dialectinterface.Interface(Handler{})) c.Database.RegisterDialect(dialectinterface.Interface(Handler{}))

View File

@ -51,6 +51,7 @@ func (ff *FlatFiles) DeletePaste(pasteID int) error {
if err != nil { if err != nil {
c.Logger.Error().Err(err).Msg("Failed to delete paste!") c.Logger.Error().Err(err).Msg("Failed to delete paste!")
// nolint:wrapcheck
return err return err
} }
@ -88,18 +89,21 @@ func (ff *FlatFiles) GetPaste(pasteID int) (*structs.Paste, error) {
if err != nil { if err != nil {
c.Logger.Debug().Err(err).Msg("Failed to read paste from storage") c.Logger.Debug().Err(err).Msg("Failed to read paste from storage")
// nolint:wrapcheck
return nil, err return nil, err
} }
c.Logger.Debug().Int("paste bytes", len(pasteInBytes)).Msg("Loaded paste") c.Logger.Debug().Int("paste bytes", len(pasteInBytes)).Msg("Loaded paste")
ff.writeMutex.Unlock() ff.writeMutex.Unlock()
// nolint:exhaustivestruct
paste := &structs.Paste{} paste := &structs.Paste{}
err1 := json.Unmarshal(pasteInBytes, paste) err1 := json.Unmarshal(pasteInBytes, paste)
if err1 != nil { if err1 != nil {
c.Logger.Error().Err(err1).Msgf("Failed to parse paste") c.Logger.Error().Err(err1).Msgf("Failed to parse paste")
// nolint:wrapcheck
return nil, err1 return nil, err1
} }
@ -145,6 +149,7 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
c.Logger.Debug().Int("ID", paste.ID).Int("index", idx).Msg("Getting paste data") c.Logger.Debug().Int("ID", paste.ID).Int("index", idx).Msg("Getting paste data")
// Get paste data. // Get paste data.
// nolint:exhaustivestruct
pasteData := &structs.Paste{} pasteData := &structs.Paste{}
pasteRawData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json")) pasteRawData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
@ -258,17 +263,21 @@ func (ff *FlatFiles) SavePaste(p *structs.Paste) (int64, error) {
if err != nil { if err != nil {
ff.writeMutex.Unlock() ff.writeMutex.Unlock()
// nolint:wrapcheck
return 0, err return 0, err
} }
// nolint:gosec
err = ioutil.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0644) err = ioutil.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0644)
if err != nil { if err != nil {
ff.writeMutex.Unlock() ff.writeMutex.Unlock()
// nolint:wrapcheck
return 0, err return 0, err
} }
// Add it to cache. // Add it to cache.
// nolint:exhaustivestruct
indexData := Index{} indexData := Index{}
indexData.ID = pasteID indexData.ID = pasteID
indexData.Private = p.Private indexData.Private = p.Private
@ -288,6 +297,7 @@ func (ff *FlatFiles) Shutdown() {
return return
} }
// nolint:gosec
err1 := ioutil.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0644) err1 := ioutil.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0644)
if err1 != nil { if err1 != nil {
c.Logger.Error().Err(err1).Msg("Failed to write index data to file. Pretty sure that you've lost your pastes.") c.Logger.Error().Err(err1).Msg("Failed to write index data to file. Pretty sure that you've lost your pastes.")

View File

@ -36,6 +36,7 @@ var (
func New(cc *context.Context) { func New(cc *context.Context) {
c = cc c = cc
// nolint:exhaustivestruct
d = &Database{} d = &Database{}
c.Database.RegisterDialect(dialectinterface.Interface(Handler{})) c.Database.RegisterDialect(dialectinterface.Interface(Handler{}))

View File

@ -38,6 +38,7 @@ func InitialUp(tx *sql.Tx) error {
keep_for_unit_type int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.', keep_for_unit_type int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.',
PRIMARY KEY (id), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';`) PRIMARY KEY (id), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';`)
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,6 +31,7 @@ import (
func PasteLangUp(tx *sql.Tx) error { func PasteLangUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` ADD `language` VARCHAR(191) NOT NULL DEFAULT 'text' COMMENT 'Paste language'") _, err := tx.Exec("ALTER TABLE `pastes` ADD `language` VARCHAR(191) NOT NULL DEFAULT 'text' COMMENT 'Paste language'")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -40,6 +41,7 @@ func PasteLangUp(tx *sql.Tx) error {
func PasteLangDown(tx *sql.Tx) error { func PasteLangDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `language`") _, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `language`")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,6 +31,7 @@ import (
func PrivatePastesUp(tx *sql.Tx) error { func PrivatePastesUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` ADD `private` BOOL NOT NULL DEFAULT false COMMENT 'Private paste? If true - additional URL parameter (UNIX TIMESTAMP) of paste will be required to access.'") _, err := tx.Exec("ALTER TABLE `pastes` ADD `private` BOOL NOT NULL DEFAULT false COMMENT 'Private paste? If true - additional URL parameter (UNIX TIMESTAMP) of paste will be required to access.'")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -40,6 +41,7 @@ func PrivatePastesUp(tx *sql.Tx) error {
func PrivatePastesDown(tx *sql.Tx) error { func PrivatePastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `private`") _, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `private`")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,11 +31,13 @@ import (
func PasswordedPastesUp(tx *sql.Tx) error { func PasswordedPastesUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` ADD `password` varchar(64) NOT NULL DEFAULT '' COMMENT 'Password for paste (scrypted and sha256ed).'") _, err := tx.Exec("ALTER TABLE `pastes` ADD `password` varchar(64) NOT NULL DEFAULT '' COMMENT 'Password for paste (scrypted and sha256ed).'")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
_, err1 := tx.Exec("ALTER TABLE `pastes` ADD `password_salt` varchar(64) NOT NULL DEFAULT '' COMMENT 'Password salt (sha256ed).'") _, err1 := tx.Exec("ALTER TABLE `pastes` ADD `password_salt` varchar(64) NOT NULL DEFAULT '' COMMENT 'Password salt (sha256ed).'")
if err1 != nil { if err1 != nil {
// nolint:wrapcheck
return err1 return err1
} }
@ -45,11 +47,13 @@ func PasswordedPastesUp(tx *sql.Tx) error {
func PasswordedPastesDown(tx *sql.Tx) error { func PasswordedPastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `password`") _, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `password`")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
_, err1 := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `password_salt`") _, err1 := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `password_salt`")
if err1 != nil { if err1 != nil {
// nolint:wrapcheck
return err1 return err1
} }

View File

@ -28,6 +28,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
// MySQL driver.
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/mysql/migrations" "go.dev.pztrn.name/fastpastebin/internal/database/dialects/mysql/migrations"
@ -58,6 +59,7 @@ func (db *Database) DeletePaste(pasteID int) error {
_, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID) _, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID)
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -78,10 +80,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) { func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
db.check() db.check()
// nolint:exhaustivestruct
p := &structs.Paste{} p := &structs.Paste{}
err := db.db.Get(p, db.db.Rebind("SELECT * FROM `pastes` WHERE id=?"), pasteID) err := db.db.Get(p, db.db.Rebind("SELECT * FROM `pastes` WHERE id=?"), pasteID)
if err != nil { if err != nil {
// nolint:wrapcheck
return nil, err return nil, err
} }
@ -104,6 +108,7 @@ func (db *Database) GetPagedPastes(page int) ([]structs.Paste, error) {
err := db.db.Select(&pastesRaw, db.db.Rebind("SELECT * FROM `pastes` WHERE private != true ORDER BY id DESC LIMIT ? OFFSET ?"), c.Config.Pastes.Pagination, startPagination) err := db.db.Select(&pastesRaw, db.db.Rebind("SELECT * FROM `pastes` WHERE private != true ORDER BY id DESC LIMIT ? OFFSET ?"), c.Config.Pastes.Pagination, startPagination)
if err != nil { if err != nil {
// nolint:wrapcheck
return nil, err return nil, err
} }
@ -186,11 +191,13 @@ func (db *Database) SavePaste(p *structs.Paste) (int64, error) {
result, err := db.db.NamedExec("INSERT INTO `pastes` (title, data, created_at, keep_for, keep_for_unit_type, language, private, password, password_salt) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language, :private, :password, :password_salt)", p) result, err := db.db.NamedExec("INSERT INTO `pastes` (title, data, created_at, keep_for, keep_for_unit_type, language, private, password, password_salt) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language, :private, :password, :password_salt)", p)
if err != nil { if err != nil {
// nolint:wrapcheck
return 0, err return 0, err
} }
ID, err1 := result.LastInsertId() ID, err1 := result.LastInsertId()
if err1 != nil { if err1 != nil {
// nolint:wrapcheck
return 0, err return 0, err
} }

View File

@ -36,6 +36,7 @@ var (
func New(cc *context.Context) { func New(cc *context.Context) {
c = cc c = cc
// nolint:exhaustivestruct
d = &Database{} d = &Database{}
c.Database.RegisterDialect(dialectinterface.Interface(Handler{})) c.Database.RegisterDialect(dialectinterface.Interface(Handler{}))

View File

@ -48,6 +48,7 @@ func InitialUp(tx *sql.Tx) error {
COMMENT ON COLUMN pastes.keep_for_unit_type IS 'Keep for unit type. 0 - forever, 1 - minutes, 2 - hours, 3 - days, 4 - months.'; COMMENT ON COLUMN pastes.keep_for_unit_type IS 'Keep for unit type. 0 - forever, 1 - minutes, 2 - hours, 3 - days, 4 - months.';
`) `)
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,6 +31,7 @@ import (
func PasteLangUp(tx *sql.Tx) error { func PasteLangUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes ADD COLUMN language VARCHAR(191) NOT NULL DEFAULT 'text'; COMMENT ON COLUMN pastes.language IS 'Paste language';") _, err := tx.Exec("ALTER TABLE pastes ADD COLUMN language VARCHAR(191) NOT NULL DEFAULT 'text'; COMMENT ON COLUMN pastes.language IS 'Paste language';")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -40,6 +41,7 @@ func PasteLangUp(tx *sql.Tx) error {
func PasteLangDown(tx *sql.Tx) error { func PasteLangDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes DROP COLUMN language") _, err := tx.Exec("ALTER TABLE pastes DROP COLUMN language")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,6 +31,7 @@ import (
func PrivatePastesUp(tx *sql.Tx) error { func PrivatePastesUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes ADD COLUMN private BOOLEAN NOT NULL DEFAULT false; COMMENT ON COLUMN pastes.private IS 'Private paste? If true - additional URL parameter (UNIX TIMESTAMP) of paste will be required to access.';") _, err := tx.Exec("ALTER TABLE pastes ADD COLUMN private BOOLEAN NOT NULL DEFAULT false; COMMENT ON COLUMN pastes.private IS 'Private paste? If true - additional URL parameter (UNIX TIMESTAMP) of paste will be required to access.';")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -40,6 +41,7 @@ func PrivatePastesUp(tx *sql.Tx) error {
func PrivatePastesDown(tx *sql.Tx) error { func PrivatePastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes DROP COLUMN private") _, err := tx.Exec("ALTER TABLE pastes DROP COLUMN private")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }

View File

@ -31,11 +31,13 @@ import (
func PasswordedPastesUp(tx *sql.Tx) error { func PasswordedPastesUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes ADD COLUMN password VARCHAR(64) NOT NULL DEFAULT ''; COMMENT ON COLUMN pastes.password IS 'Password for paste (scrypted and sha256ed).';") _, err := tx.Exec("ALTER TABLE pastes ADD COLUMN password VARCHAR(64) NOT NULL DEFAULT ''; COMMENT ON COLUMN pastes.password IS 'Password for paste (scrypted and sha256ed).';")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
_, err1 := tx.Exec("ALTER TABLE pastes ADD COLUMN password_salt VARCHAR(64) NOT NULL DEFAULT ''; COMMENT ON COLUMN pastes.password_salt IS 'Password salt (sha256ed).';") _, err1 := tx.Exec("ALTER TABLE pastes ADD COLUMN password_salt VARCHAR(64) NOT NULL DEFAULT ''; COMMENT ON COLUMN pastes.password_salt IS 'Password salt (sha256ed).';")
if err1 != nil { if err1 != nil {
// nolint:wrapcheck
return err1 return err1
} }
@ -45,11 +47,13 @@ func PasswordedPastesUp(tx *sql.Tx) error {
func PasswordedPastesDown(tx *sql.Tx) error { func PasswordedPastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes DROP COLUMN password") _, err := tx.Exec("ALTER TABLE pastes DROP COLUMN password")
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
_, err1 := tx.Exec("ALTER TABLE pastes DROP COLUMN password_salt") _, err1 := tx.Exec("ALTER TABLE pastes DROP COLUMN password_salt")
if err1 != nil { if err1 != nil {
// nolint:wrapcheck
return err1 return err1
} }

View File

@ -24,13 +24,16 @@
package postgresql package postgresql
// nolint:gci
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"time" "time"
"github.com/jmoiron/sqlx" // PostgreSQL driver.
_ "github.com/lib/pq" _ "github.com/lib/pq"
"github.com/jmoiron/sqlx"
"go.dev.pztrn.name/fastpastebin/internal/database/dialects/postgresql/migrations" "go.dev.pztrn.name/fastpastebin/internal/database/dialects/postgresql/migrations"
"go.dev.pztrn.name/fastpastebin/internal/structs" "go.dev.pztrn.name/fastpastebin/internal/structs"
) )
@ -59,6 +62,7 @@ func (db *Database) DeletePaste(pasteID int) error {
_, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID) _, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID)
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }
@ -79,10 +83,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) { func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
db.check() db.check()
// nolint:exhaustivestruct
p := &structs.Paste{} p := &structs.Paste{}
err := db.db.Get(p, db.db.Rebind("SELECT * FROM pastes WHERE id=$1"), pasteID) err := db.db.Get(p, db.db.Rebind("SELECT * FROM pastes WHERE id=$1"), pasteID)
if err != nil { if err != nil {
// nolint:wrapcheck
return nil, err return nil, err
} }
@ -112,6 +118,7 @@ func (db *Database) GetPagedPastes(page int) ([]structs.Paste, error) {
err := db.db.Select(&pastesRaw, db.db.Rebind("SELECT * FROM pastes WHERE private != true ORDER BY id DESC LIMIT $1 OFFSET $2"), c.Config.Pastes.Pagination, startPagination) err := db.db.Select(&pastesRaw, db.db.Rebind("SELECT * FROM pastes WHERE private != true ORDER BY id DESC LIMIT $1 OFFSET $2"), c.Config.Pastes.Pagination, startPagination)
if err != nil { if err != nil {
// nolint:wrapcheck
return nil, err return nil, err
} }
@ -195,6 +202,7 @@ func (db *Database) SavePaste(p *structs.Paste) (int64, error) {
stmt, err := db.db.PrepareNamed("INSERT INTO pastes (title, data, created_at, keep_for, keep_for_unit_type, language, private, password, password_salt) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language, :private, :password, :password_salt) RETURNING id") stmt, err := db.db.PrepareNamed("INSERT INTO pastes (title, data, created_at, keep_for, keep_for_unit_type, language, private, password, password_salt) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language, :private, :password, :password_salt) RETURNING id")
if err != nil { if err != nil {
// nolint:wrapcheck
return 0, err return 0, err
} }
@ -202,6 +210,7 @@ func (db *Database) SavePaste(p *structs.Paste) (int64, error) {
err = stmt.Get(&id, p) err = stmt.Get(&id, p)
if err != nil { if err != nil {
// nolint:wrapcheck
return 0, err return 0, err
} }

View File

@ -37,6 +37,7 @@ var (
// New initializes database structure. // New initializes database structure.
func New(cc *context.Context) { func New(cc *context.Context) {
c = cc c = cc
// nolint:exhaustivestruct
d = &Database{} d = &Database{}
c.RegisterDatabaseInterface(databaseinterface.Interface(Handler{})) c.RegisterDatabaseInterface(databaseinterface.Interface(Handler{}))

View File

@ -34,15 +34,22 @@ import (
) )
const ( const (
// PasteKeepForever indicates that paste should be kept forever.
PasteKeepForever = 0 PasteKeepForever = 0
// PasteKeepForMinutes indicates that saved timeout is in minutes.
PasteKeepForMinutes = 1 PasteKeepForMinutes = 1
// PasteKeepForHours indicates that saved timeout is in hours.
PasteKeepForHours = 2 PasteKeepForHours = 2
// PasteKeepForDays indicates that saved timeout is in days.
PasteKeepForDays = 3 PasteKeepForDays = 3
// PasteKeepForMonths indicates that saved timeout is in months.
PasteKeepForMonths = 4 PasteKeepForMonths = 4
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
) )
// PasteKeepsCorrelation is a correlation map between database representation
// and passed data representation.
var PasteKeepsCorrelation = map[string]int{ var PasteKeepsCorrelation = map[string]int{
"M": PasteKeepForMinutes, "M": PasteKeepForMinutes,
"h": PasteKeepForHours, "h": PasteKeepForHours,
@ -68,6 +75,8 @@ type Paste struct {
// CreatePassword creates password for current paste. // CreatePassword creates password for current paste.
func (p *Paste) CreatePassword(password string) error { func (p *Paste) CreatePassword(password string) error {
// Create salt - random string. // Create salt - random string.
// Yes, it is insecure. Should be refactored!
// nolint:gosec
seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
saltBytes := make([]byte, 64) saltBytes := make([]byte, 64)
@ -81,6 +90,7 @@ func (p *Paste) CreatePassword(password string) error {
// Create crypted password and hash it. // Create crypted password and hash it.
passwordCrypted, err := scrypt.Key([]byte(password), []byte(p.PasswordSalt), 131072, 8, 1, 64) passwordCrypted, err := scrypt.Key([]byte(password), []byte(p.PasswordSalt), 131072, 8, 1, 64)
if err != nil { if err != nil {
// nolint:wrapcheck
return err return err
} }