Linting things.

This commit is contained in:
Stanislav Nikitin 2019-10-13 16:26:52 +05:00
parent cdc8ecf49b
commit 6a787e7e23
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
13 changed files with 19 additions and 25 deletions

View File

@ -42,7 +42,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" && dbConn == nil { if c.Config.Database.Type != "flatfiles" && dbConn == nil {
ec.Redirect(http.StatusFound, "/database_not_available") return ec.Redirect(http.StatusFound, "/database_not_available")
} }
// Generate list of available languages to highlight. // Generate list of available languages to highlight.

View File

@ -77,11 +77,6 @@ func pasteGetData(pasteID int, timestamp int64, cookieValue string) (*structs.Pa
return paste, "" return paste, ""
} }
// GET for "/api/paste/PASTE_ID" and "/api/paste/PASTE_ID/TIMESTAMP".
func pasteGETApi(ec echo.Context) error {
return nil
}
// GET for "/paste/PASTE_ID" and "/paste/PASTE_ID/TIMESTAMP" (private pastes). // GET for "/paste/PASTE_ID" and "/paste/PASTE_ID/TIMESTAMP" (private pastes).
// Web interface version. // Web interface version.
func pasteGETWebInterface(ec echo.Context) error { func pasteGETWebInterface(ec echo.Context) error {

View File

@ -112,7 +112,7 @@ func pastePOSTWebInterface(ec echo.Context) error {
} }
if pastePassword[0] != "" { if pastePassword[0] != "" {
paste.CreatePassword(pastePassword[0]) _ = paste.CreatePassword(pastePassword[0])
} }
id, err2 := c.Database.SavePaste(paste) id, err2 := c.Database.SavePaste(paste)

View File

@ -79,7 +79,7 @@ func pastesGET(ec echo.Context) error {
// Get max 4 lines of each paste. // Get max 4 lines of each paste.
pasteDataSplitted := strings.Split(pastes[i].Data, "\n") pasteDataSplitted := strings.Split(pastes[i].Data, "\n")
var pasteData = "" var pasteData string
if len(pasteDataSplitted) < 4 { if len(pasteDataSplitted) < 4 {
pasteData = pastes[i].Data pasteData = pastes[i].Data
} else { } else {

View File

@ -32,7 +32,7 @@ import (
// local // local
"go.dev.pztrn.name/fastpastebin/internal/config" "go.dev.pztrn.name/fastpastebin/internal/config"
"go.dev.pztrn.name/fastpastebin/internal/database/interface" databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
// other // other
"github.com/labstack/echo" "github.com/labstack/echo"
@ -60,7 +60,7 @@ func (c *Context) Initialize() {
c.Flagger = flagger.New("fastpastebin", nil) c.Flagger = flagger.New("fastpastebin", nil)
c.Flagger.Initialize() c.Flagger.Initialize()
c.Flagger.AddFlag(&flagger.Flag{ _ = c.Flagger.AddFlag(&flagger.Flag{
Name: "config", Name: "config",
Description: "Configuration file path. Can be overridded with FASTPASTEBIN_CONFIG environment variable (this is what used in tests).", Description: "Configuration file path. Can be overridded with FASTPASTEBIN_CONFIG environment variable (this is what used in tests).",
Type: "string", Type: "string",

View File

@ -40,8 +40,7 @@ func (c *Context) echoReqLogger() echo.MiddlewareFunc {
Str("UA", ec.Request().UserAgent()). Str("UA", ec.Request().UserAgent()).
Msg("HTTP request") Msg("HTTP request")
next(ec) return next(ec)
return nil
} }
} }
} }

View File

@ -169,10 +169,10 @@ func (ff *FlatFiles) Initialize() {
ff.path = path ff.path = path
c.Logger.Debug().Msgf("Storage path is now: %s", ff.path) c.Logger.Debug().Msgf("Storage path is now: %s", ff.path)
// Create directory if neccessary. // Create directory if necessary.
if _, err := os.Stat(ff.path); err != nil { if _, err := os.Stat(ff.path); err != nil {
c.Logger.Debug().Msgf("Directory '%s' does not exist, creating...", ff.path) c.Logger.Debug().Msgf("Directory '%s' does not exist, creating...", ff.path)
os.MkdirAll(ff.path, os.ModePerm) _ = os.MkdirAll(ff.path, os.ModePerm)
} else { } else {
c.Logger.Debug().Msgf("Directory '%s' already exists", ff.path) c.Logger.Debug().Msgf("Directory '%s' already exists", ff.path)
} }
@ -180,7 +180,7 @@ func (ff *FlatFiles) Initialize() {
// Create directory for pastes. // Create directory for pastes.
if _, err := os.Stat(filepath.Join(ff.path, "pastes")); err != nil { if _, err := os.Stat(filepath.Join(ff.path, "pastes")); err != nil {
c.Logger.Debug().Msgf("Directory '%s' does not exist, creating...", filepath.Join(ff.path, "pastes")) c.Logger.Debug().Msgf("Directory '%s' does not exist, creating...", filepath.Join(ff.path, "pastes"))
os.MkdirAll(filepath.Join(ff.path, "pastes"), os.ModePerm) _ = os.MkdirAll(filepath.Join(ff.path, "pastes"), os.ModePerm)
} else { } else {
c.Logger.Debug().Msgf("Directory '%s' already exists", filepath.Join(ff.path, "pastes")) c.Logger.Debug().Msgf("Directory '%s' already exists", filepath.Join(ff.path, "pastes"))
} }

View File

@ -46,7 +46,7 @@ func New(cc *context.Context) {
func Migrate() { func Migrate() {
c.Logger.Info().Msg("Migrating database...") c.Logger.Info().Msg("Migrating database...")
goose.SetDialect("mysql") _ = goose.SetDialect("mysql")
goose.AddNamedMigration("1_initial.go", InitialUp, nil) goose.AddNamedMigration("1_initial.go", InitialUp, nil)
goose.AddNamedMigration("2_paste_lang.go", PasteLangUp, PasteLangDown) goose.AddNamedMigration("2_paste_lang.go", PasteLangUp, PasteLangDown)
goose.AddNamedMigration("3_private_pastes.go", PrivatePastesUp, PrivatePastesDown) goose.AddNamedMigration("3_private_pastes.go", PrivatePastesUp, PrivatePastesDown)

View File

@ -135,7 +135,7 @@ func (db *Database) Initialize() {
// There might be only user, without password. MySQL/MariaDB driver // There might be only user, without password. MySQL/MariaDB driver
// in DSN wants "user" or "user:password", "user:" is invalid. // in DSN wants "user" or "user:password", "user:" is invalid.
var userpass = "" var userpass string
if c.Config.Database.Password == "" { if c.Config.Database.Password == "" {
userpass = c.Config.Database.Username userpass = c.Config.Database.Username
} else { } else {

View File

@ -46,7 +46,7 @@ func New(cc *context.Context) {
func Migrate() { func Migrate() {
c.Logger.Info().Msg("Migrating database...") c.Logger.Info().Msg("Migrating database...")
goose.SetDialect("postgres") _ = goose.SetDialect("postgres")
goose.AddNamedMigration("1_initial.go", InitialUp, nil) goose.AddNamedMigration("1_initial.go", InitialUp, nil)
goose.AddNamedMigration("2_paste_lang.go", PasteLangUp, PasteLangDown) goose.AddNamedMigration("2_paste_lang.go", PasteLangUp, PasteLangDown)
goose.AddNamedMigration("3_private_pastes.go", PrivatePastesUp, PrivatePastesDown) goose.AddNamedMigration("3_private_pastes.go", PrivatePastesUp, PrivatePastesDown)

View File

@ -147,7 +147,7 @@ func (db *Database) GetPastesPages() int {
func (db *Database) Initialize() { func (db *Database) Initialize() {
c.Logger.Info().Msg("Initializing database connection...") c.Logger.Info().Msg("Initializing database connection...")
var userpass = "" var userpass string
if c.Config.Database.Password == "" { if c.Config.Database.Password == "" {
userpass = c.Config.Database.Username userpass = c.Config.Database.Username
} else { } else {

View File

@ -33,7 +33,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
} }
// First page should always be visible. // First page should always be visible.
var paginationString = "" var paginationString string
if currentPage == 1 { if currentPage == 1 {
paginationString = strings.Replace(string(paginationLinkCurrentRaw), "{pageNum}", strconv.Itoa(currentPage), -1) paginationString = strings.Replace(string(paginationLinkCurrentRaw), "{pageNum}", strconv.Itoa(currentPage), -1)
} else { } else {

View File

@ -58,7 +58,7 @@ func GetRawTemplate(ec echo.Context, templateName string, data map[string]string
// Getting main template. // Getting main template.
tplRaw, err := static.ReadFile(templateName) tplRaw, err := static.ReadFile(templateName)
if err != nil { if err != nil {
ec.String(http.StatusBadRequest, templateName+" not found.") _ = ec.String(http.StatusBadRequest, templateName+" not found.")
return "" return ""
} }
@ -78,21 +78,21 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
// Getting main template. // Getting main template.
mainhtml, err := static.ReadFile("main.html") mainhtml, err := static.ReadFile("main.html")
if err != nil { if err != nil {
ec.String(http.StatusBadRequest, "main.html not found.") _ = ec.String(http.StatusBadRequest, "main.html not found.")
return "" return ""
} }
// Getting navigation. // Getting navigation.
navhtml, err1 := static.ReadFile("navigation.html") navhtml, err1 := static.ReadFile("navigation.html")
if err1 != nil { if err1 != nil {
ec.String(http.StatusBadRequest, "navigation.html not found.") _ = ec.String(http.StatusBadRequest, "navigation.html not found.")
return "" return ""
} }
// Getting footer. // Getting footer.
footerhtml, err2 := static.ReadFile("footer.html") footerhtml, err2 := static.ReadFile("footer.html")
if err2 != nil { if err2 != nil {
ec.String(http.StatusBadRequest, "footer.html not found.") _ = ec.String(http.StatusBadRequest, "footer.html not found.")
return "" return ""
} }
@ -105,7 +105,7 @@ func GetTemplate(ec echo.Context, name string, data map[string]string) string {
// Get requested template. // Get requested template.
reqhtml, err3 := static.ReadFile(name) reqhtml, err3 := static.ReadFile(name)
if err3 != nil { if err3 != nil {
ec.String(http.StatusBadRequest, name+" not found.") _ = ec.String(http.StatusBadRequest, name+" not found.")
return "" return ""
} }