The Great Sources Linting.
This commit is contained in:
@@ -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 (
|
||||
|
@@ -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"`
|
||||
}
|
||||
|
@@ -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"`
|
||||
}
|
||||
|
@@ -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"
|
||||
)
|
||||
|
@@ -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() {
|
||||
|
@@ -1,14 +1,12 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// other
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -25,10 +25,8 @@
|
||||
package flatfiles
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/fastpastebin/internal/structs"
|
||||
)
|
||||
|
||||
|
@@ -25,10 +25,8 @@
|
||||
package dialectinterface
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/fastpastebin/internal/structs"
|
||||
)
|
||||
|
||||
|
@@ -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"
|
||||
)
|
||||
|
@@ -25,10 +25,8 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/fastpastebin/internal/structs"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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"
|
||||
)
|
||||
|
@@ -25,10 +25,8 @@
|
||||
package postgresql
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
|
||||
// local
|
||||
"go.dev.pztrn.name/fastpastebin/internal/structs"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
// local
|
||||
"go.dev.pztrn.name/fastpastebin/internal/context"
|
||||
databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
|
||||
)
|
||||
|
@@ -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"
|
||||
)
|
||||
|
@@ -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"
|
||||
)
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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))
|
||||
}
|
||||
|
||||
|
@@ -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 ""
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user