Make linter happy and move to os from io/ioutil for reading/writing.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Stanislav Nikitin 2022-08-14 15:49:05 +05:00
parent df5671586e
commit 2ec0e28243
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
28 changed files with 99 additions and 99 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Updated bulma to v 0.7.5.
* Moved from `io/ioutil` to `os` package for reading/writing files and directories.
### Fixed

View File

@ -1,3 +1,4 @@
//nolint:gofmt,gofumpt,goimports
package assets
import "embed"

View File

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

View File

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

View File

@ -92,7 +92,7 @@ func pasteGETWebInterface(ectx echo.Context) error {
errtpl := templater.GetErrorTemplate(ectx, "Paste #"+pasteIDStr+" not found")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, errtpl)
}
@ -114,7 +114,7 @@ func pasteGETWebInterface(ectx echo.Context) error {
if err == pasteExpired || err == pasteNotFound || err == pasteTimestampInvalid {
errtpl := templater.GetErrorTemplate(ectx, "Paste #"+pasteIDRaw+" not found")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusNotFound, errtpl)
}
@ -123,7 +123,7 @@ func pasteGETWebInterface(ectx echo.Context) error {
if err == pasteCookieInvalid {
ctx.Logger.Info().Int("paste ID", pasteID).Msg("Invalid cookie, redirecting to auth page")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDStr+"/"+ectx.Param("timestamp")+"/verify")
}
@ -181,7 +181,7 @@ func pasteGETWebInterface(ectx echo.Context) error {
// Get template and format it.
pasteHTML := templater.GetTemplate(ectx, "paste.html", pasteData)
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusOK, pasteHTML)
}
@ -200,7 +200,7 @@ func pastePasswordedVerifyGet(ectx echo.Context) error {
errtpl := templater.GetErrorTemplate(ectx, "Paste #"+pasteIDRaw+" not found")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, errtpl)
}
@ -216,7 +216,7 @@ func pastePasswordedVerifyGet(ectx echo.Context) error {
if cookieValue == cookie.Value {
ctx.Logger.Info().Msg("Valid cookie, redirecting to paste page...")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.Redirect(http.StatusMovedPermanently, "/paste/"+pasteIDRaw+"/"+ectx.Param("timestamp"))
}
@ -230,7 +230,7 @@ func pastePasswordedVerifyGet(ectx echo.Context) error {
verifyHTML := templater.GetTemplate(ectx, "passworded_paste_verify.html", htmlData)
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusOK, verifyHTML)
}
@ -240,7 +240,7 @@ func pastePasswordedVerifyPost(ectx echo.Context) error {
dbConn := ctx.Database.GetDatabaseConnection()
if ctx.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.Redirect(http.StatusFound, "/database_not_available")
}
@ -257,7 +257,7 @@ func pastePasswordedVerifyPost(ectx echo.Context) error {
ctx.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste")
errtpl := templater.GetErrorTemplate(ectx, "Paste #"+strconv.Itoa(pasteID)+" not found")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, errtpl)
}
@ -267,7 +267,7 @@ func pastePasswordedVerifyPost(ectx echo.Context) error {
errtpl := templater.GetErrorTemplate(ectx, "Paste #"+strconv.Itoa(pasteID)+" not found")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, errtpl)
}
@ -280,13 +280,13 @@ func pastePasswordedVerifyPost(ectx echo.Context) error {
cookie.Expires = time.Now().Add(24 * time.Hour)
ectx.SetCookie(cookie)
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.Redirect(http.StatusFound, "/paste/"+strconv.Itoa(pasteID)+"/"+timestampRaw)
}
errtpl := templater.GetErrorTemplate(ectx, "Invalid password. Please, try again.")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, errtpl)
}
@ -296,7 +296,7 @@ func pasteRawGETWebInterface(ectx echo.Context) error {
// We should check if database connection available.
dbConn := ctx.Database.GetDatabaseConnection()
if ctx.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.Redirect(http.StatusFound, "/database_not_available/raw")
}
@ -311,14 +311,14 @@ func pasteRawGETWebInterface(ectx echo.Context) error {
if err1 != nil {
ctx.Logger.Error().Err(err1).Int("paste ID", pasteID).Msg("Failed to get paste from database")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
}
if paste.IsExpired() {
ctx.Logger.Error().Int("paste ID", pasteID).Msg("Paste is expired")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.HTML(http.StatusBadRequest, "Paste #"+pasteIDRaw+" does not exist.")
}
@ -330,7 +330,7 @@ func pasteRawGETWebInterface(ectx echo.Context) error {
if err2 != nil {
ctx.Logger.Error().Err(err2).Int("paste ID", pasteID).Str("provided timestamp", tsProvidedStr).Msg("Invalid timestamp provided for getting private paste")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
}
@ -338,12 +338,12 @@ func pasteRawGETWebInterface(ectx echo.Context) error {
if tsProvided != pasteTS {
ctx.Logger.Error().Int("paste ID", pasteID).Int64("provided timestamp", tsProvided).Int64("paste timestamp", pasteTS).Msg("Incorrect timestamp provided for private paste")
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
}
}
// nolint
//nolint
// ToDo: figure out how to handle passworded pastes here.
// Return error for now.
if paste.Password != "" {
@ -351,6 +351,6 @@ func pasteRawGETWebInterface(ectx echo.Context) error {
return ectx.String(http.StatusBadRequest, "Paste #"+pasteIDRaw+" not found")
}
// nolint:wrapcheck
//nolint:wrapcheck
return ectx.String(http.StatusOK, paste.Data)
}

View File

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

View File

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

View File

@ -25,7 +25,6 @@
package context
import (
"io/ioutil"
"os"
"path/filepath"
@ -100,11 +99,11 @@ func (c *Context) LoadConfiguration() {
c.Logger.Debug().Str("path", configPath).Msg("Configuration file path")
// nolint:exhaustruct
//nolint:exhaustruct
c.Config = &config.Struct{}
// Read configuration file.
fileData, err2 := ioutil.ReadFile(normalizedConfigPath)
fileData, err2 := os.ReadFile(normalizedConfigPath)
if err2 != nil {
c.Logger.Panic().Err(err2).Msg("Failed to read configuration file")
}

View File

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

View File

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

View File

@ -79,7 +79,7 @@ func (db *Database) cleanup() {
}
func (db *Database) DeletePaste(pasteID int) error {
// nolint:wrapcheck
//nolint:wrapcheck
return db.db.DeletePaste(pasteID)
}
@ -92,12 +92,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
}
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
// nolint:wrapcheck
//nolint:wrapcheck
return db.db.GetPaste(pasteID)
}
func (db *Database) GetPagedPastes(page int) ([]structs.Paste, error) {
// nolint:wrapcheck
//nolint:wrapcheck
return db.db.GetPagedPastes(page)
}
@ -128,7 +128,7 @@ func (db *Database) RegisterDialect(di dialectinterface.Interface) {
}
func (db *Database) SavePaste(p *structs.Paste) (int64, error) {
// nolint:wrapcheck
//nolint:wrapcheck
return db.db.SavePaste(p)
}

View File

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

View File

@ -27,7 +27,6 @@ package flatfiles
import (
"database/sql"
"encoding/json"
"io/ioutil"
"os"
"os/user"
"path/filepath"
@ -51,7 +50,7 @@ func (ff *FlatFiles) DeletePaste(pasteID int) error {
if err != nil {
ctx.Logger.Error().Err(err).Msg("Failed to delete paste!")
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -85,25 +84,25 @@ func (ff *FlatFiles) GetPaste(pasteID int) (*structs.Paste, error) {
pastePath := filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json")
ctx.Logger.Debug().Str("path", pastePath).Msg("Trying to load paste data")
pasteInBytes, err := ioutil.ReadFile(pastePath)
pasteInBytes, err := os.ReadFile(pastePath)
if err != nil {
ctx.Logger.Debug().Err(err).Msg("Failed to read paste from storage")
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err
}
ctx.Logger.Debug().Int("paste bytes", len(pasteInBytes)).Msg("Loaded paste")
ff.writeMutex.Unlock()
// nolint:exhaustruct
//nolint:exhaustruct
paste := &structs.Paste{}
err1 := json.Unmarshal(pasteInBytes, paste)
if err1 != nil {
ctx.Logger.Error().Err(err1).Msgf("Failed to parse paste")
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err1
}
@ -149,10 +148,10 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
ctx.Logger.Debug().Int("ID", paste.ID).Int("index", idx).Msg("Getting paste data")
// Get paste data.
// nolint:exhaustruct
//nolint:exhaustruct
pasteData := &structs.Paste{}
pasteRawData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
pasteRawData, err := os.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
if err != nil {
ctx.Logger.Error().Err(err).Msg("Failed to read paste data")
@ -236,7 +235,7 @@ func (ff *FlatFiles) Initialize() {
if _, err := os.Stat(filepath.Join(ff.path, "pastes", "index.json")); err != nil {
ctx.Logger.Warn().Msg("Pastes index file does not exist, will create new one")
} else {
indexData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", "index.json"))
indexData, err := os.ReadFile(filepath.Join(ff.path, "pastes", "index.json"))
if err != nil {
ctx.Logger.Fatal().Msg("Failed to read contents of index file!")
}
@ -253,7 +252,7 @@ func (ff *FlatFiles) Initialize() {
func (ff *FlatFiles) SavePaste(paste *structs.Paste) (int64, error) {
ff.writeMutex.Lock()
// Write paste data on disk.
filesOnDisk, _ := ioutil.ReadDir(filepath.Join(ff.path, "pastes"))
filesOnDisk, _ := os.ReadDir(filepath.Join(ff.path, "pastes"))
pasteID := len(filesOnDisk) + 1
paste.ID = pasteID
@ -263,20 +262,20 @@ func (ff *FlatFiles) SavePaste(paste *structs.Paste) (int64, error) {
if err != nil {
ff.writeMutex.Unlock()
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}
err = ioutil.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0o600)
err = os.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0o600)
if err != nil {
ff.writeMutex.Unlock()
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}
// Add it to cache.
// nolint:exhaustruct
//nolint:exhaustruct
indexData := Index{}
indexData.ID = pasteID
indexData.Private = paste.Private
@ -296,7 +295,7 @@ func (ff *FlatFiles) Shutdown() {
return
}
err1 := ioutil.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0o600)
err1 := os.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0o600)
if err1 != nil {
ctx.Logger.Error().Err(err1).Msg("Failed to write index data to file. Pretty sure that you've lost your pastes.")

View File

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

View File

@ -38,7 +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.',
PRIMARY KEY (id), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';`)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}

View File

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

View File

@ -31,7 +31,7 @@ import (
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.'")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -41,7 +41,7 @@ func PrivatePastesUp(tx *sql.Tx) error {
func PrivatePastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `private`")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}

View File

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

View File

@ -59,7 +59,7 @@ func (db *Database) DeletePaste(pasteID int) error {
_, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -80,12 +80,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
db.check()
// nolint:exhaustruct
//nolint:exhaustruct
paste := &structs.Paste{}
err := db.db.Get(paste, db.db.Rebind("SELECT * FROM `pastes` WHERE id=?"), pasteID)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err
}
@ -108,7 +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 ?"), ctx.Config.Pastes.Pagination, startPagination)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err
}
@ -191,13 +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)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}
lastInsertID, err1 := result.LastInsertId()
if err1 != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}

View File

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

View File

@ -48,7 +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.';
`)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}

View File

@ -31,7 +31,7 @@ import (
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';")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -41,7 +41,7 @@ func PasteLangUp(tx *sql.Tx) error {
func PasteLangDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes DROP COLUMN language")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}

View File

@ -31,7 +31,7 @@ import (
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.';")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -41,7 +41,7 @@ func PrivatePastesUp(tx *sql.Tx) error {
func PrivatePastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE pastes DROP COLUMN private")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}

View File

@ -31,13 +31,13 @@ import (
func PasswordedPastesUp(txn *sql.Tx) error {
_, err := txn.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 {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
_, err1 := txn.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 {
// nolint:wrapcheck
//nolint:wrapcheck
return err1
}
@ -47,13 +47,13 @@ func PasswordedPastesUp(txn *sql.Tx) error {
func PasswordedPastesDown(txn *sql.Tx) error {
_, err := txn.Exec("ALTER TABLE pastes DROP COLUMN password")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
_, err1 := txn.Exec("ALTER TABLE pastes DROP COLUMN password_salt")
if err1 != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err1
}

View File

@ -24,7 +24,7 @@
package postgresql
// nolint:gci
//nolint:gci
import (
"database/sql"
"fmt"
@ -63,7 +63,7 @@ func (db *Database) DeletePaste(pasteID int) error {
_, err := db.db.Exec(db.db.Rebind("DELETE FROM pastes WHERE id=?"), pasteID)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}
@ -84,12 +84,12 @@ func (db *Database) GetDatabaseConnection() *sql.DB {
func (db *Database) GetPaste(pasteID int) (*structs.Paste, error) {
db.check()
// nolint:exhaustruct
//nolint:exhaustruct
paste := &structs.Paste{}
err := db.db.Get(paste, db.db.Rebind("SELECT * FROM pastes WHERE id=$1"), pasteID)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err
}
@ -119,7 +119,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"), ctx.Config.Pastes.Pagination, startPagination)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return nil, err
}
@ -203,7 +203,7 @@ func (db *Database) SavePaste(paste *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")
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}
@ -211,7 +211,7 @@ func (db *Database) SavePaste(paste *structs.Paste) (int64, error) {
err = stmt.Get(&newPasteID, paste)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return 0, err
}

View File

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

View File

@ -42,13 +42,13 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
var (
ellipsisStartAdded = false
ellipsisEndAdded = false
// nolint:varnamelen
//nolint:varnamelen
i = 2
)
for i <= pages {
// ToDo: fix it!
// nolint:nestif
//nolint:nestif
if pages > 5 {
if currentPage-3 < i && currentPage+3 > i || i == pages {
paginationItemRaw := string(paginationLinkRaw)

View File

@ -76,7 +76,7 @@ type Paste struct {
func (p *Paste) CreatePassword(password string) error {
// Create salt - random string.
// Yes, it is insecure. Should be refactored!
// nolint:gosec
//nolint:gosec
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
saltBytes := make([]byte, 64)
@ -90,7 +90,7 @@ func (p *Paste) CreatePassword(password string) error {
// Create crypted password and hash it.
passwordCrypted, err := scrypt.Key([]byte(password), []byte(p.PasswordSalt), 131072, 8, 1, 64)
if err != nil {
// nolint:wrapcheck
//nolint:wrapcheck
return err
}