refactor: rename backend -> web

This commit is contained in:
2025-01-06 19:25:06 +03:00
parent 7d38326112
commit 521e140881
7 changed files with 0 additions and 0 deletions
+308
View File
@@ -0,0 +1,308 @@
package api
import (
"context"
"net/http"
"strconv"
"time"
"github.com/H1K0/SkazaNull/db"
"github.com/H1K0/SkazaNull/models"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
//#region User
func userAuth(c *gin.Context) {
var credentials struct {
Login string `form:"login" binding:"required"`
Password string `form:"password" binding:"required"`
}
err := c.ShouldBind(&credentials)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "И чё за шнягу ты мне кинул?"})
return
}
user, err := db.UserAuth(context.Background(), credentials.Login, credentials.Password)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
session := sessions.Default(c)
session.Set("user_id", user.ID)
session.Set("started", time.Now().Unix())
session.Save()
c.JSON(http.StatusOK, user)
}
func userGet(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
user, err := db.UserGet(context.Background(), user_id)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, user)
}
func userUpdate(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
var body map[string]string
err := c.BindJSON(&body)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "И чё за шнягу ты мне кинул?"})
return
}
var user models.User
ctx := context.Background()
newTelegramIDStr, ok := body["telegram_id"]
if ok && newTelegramIDStr != "" {
newTelegramID, err := strconv.ParseInt(newTelegramIDStr, 10, 0)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "telegram_id param must be int"})
return
}
user, err = db.UserUpdateTelegramID(ctx, user_id, newTelegramID)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
newName, ok := body["name"]
if ok && newName != "" {
user, err = db.UserUpdateName(ctx, user_id, newName)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
newLogin, ok := body["login"]
if ok && newLogin != "" {
user, err = db.UserUpdateLogin(ctx, user_id, newLogin)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
newPassword, ok := body["password"]
if ok && newPassword != "" {
user, err = db.UserUpdatePassword(ctx, user_id, newPassword)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
c.JSON(http.StatusOK, user)
}
func userLogout(c *gin.Context) {
session := sessions.Default(c)
_, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ну и как я тебя разлогиню, если ты даже не залогинился?"})
return
}
session.Clear()
session.Options(sessions.Options{MaxAge: -1})
session.Save()
c.Status(http.StatusNoContent)
}
//#endregion User
//#region Quotes
func quotesGet(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
filter, ok := c.GetQuery("filter")
if !ok {
filter = ""
}
sort, ok := c.GetQuery("sort")
if !ok {
sort = "-datetime"
}
var limit int64
limitStr, ok := c.GetQuery("limit")
if ok {
var err error
limit, err = strconv.ParseInt(limitStr, 10, 0)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "limit param must be int"})
return
}
} else {
limit = 10
}
var offset int64
offsetStr, ok := c.GetQuery("offset")
if ok {
var err error
offset, err = strconv.ParseInt(offsetStr, 10, 0)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "offset param must be int"})
return
}
} else {
offset = 0
}
quotes, err := db.QuotesGet(c, user_id, filter, sort, int(limit), int(offset))
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, quotes)
}
func quoteGet(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
quote_id := c.Param("id")
quote, err := db.QuoteGet(context.Background(), user_id, quote_id)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, quote)
}
func quoteAdd(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
var body map[string]string
err := c.BindJSON(&body)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "И чё за шнягу ты мне кинул?"})
return
}
text, ok := body["text"]
if !ok || text == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Э, а где цитата?"})
return
}
author, ok := body["author"]
if !ok || author == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Цитата может быть сказана только тем, кто её сказанул! А кто сказанул эту цитату?"})
return
}
var datetime time.Time
datetimeStr, ok := body["datetime"]
if ok {
datetime, err = time.Parse(time.RFC3339, datetimeStr)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Чёт дата и время у тебя какие-то кривые..."})
return
}
} else {
datetime = time.Now()
}
quote, err := db.QuoteAdd(context.Background(), user_id, text, author, datetime)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusCreated, quote)
}
func quoteUpdate(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
quote_id := c.Param("id")
var body map[string]string
err := c.BindJSON(&body)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "И чё за шнягу ты мне кинул?"})
return
}
var quote models.Quote
ctx := context.Background()
newText, ok := body["text"]
if ok && newText != "" {
quote, err = db.QuoteUpdateText(ctx, user_id, quote_id, newText)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
newAuthor, ok := body["author"]
if ok && newAuthor != "" {
quote, err = db.QuoteUpdateAuthor(ctx, user_id, quote_id, newAuthor)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
datetimeStr, ok := body["datetime"]
if ok && datetimeStr != "" {
newDatetime, err := time.Parse(time.RFC3339, datetimeStr)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Чёт дата и время у тебя какие-то кривые..."})
return
}
quote, err = db.QuoteUpdateDatetime(context.Background(), user_id, quote_id, newDatetime)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
}
c.JSON(http.StatusOK, quote)
}
func quoteDelete(c *gin.Context) {
session := sessions.Default(c)
user_id, ok := session.Get("user_id").(string)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Ты это, залогинься сначала что ли, а то чё как крыса"})
return
}
quote_id := c.Param("id")
err := db.QuoteDelete(context.Background(), user_id, quote_id)
if err != nil {
status, message := HandleDBError(err)
c.JSON(status, gin.H{"error": message})
return
}
c.JSON(http.StatusNoContent, nil)
}
//#endregion Quotes
+34
View File
@@ -0,0 +1,34 @@
package api
import (
"github.com/gin-gonic/gin"
)
// @title SkazaNull API
// @description RESTful API для пацанского цитатника SkazaNull
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host skazanull.hakoniwa.ru
// @BasePath /api
func RegisterRoutes(r *gin.Engine) {
api := r.Group("/api")
{
api.POST("/auth", userAuth)
api.GET("/auth", userGet)
api.PATCH("/auth", userUpdate)
api.DELETE("/auth", userLogout)
api.GET("/quotes", quotesGet)
api.POST("/quotes", quoteAdd)
api.GET("/quotes/:id", quoteGet)
api.PATCH("/quotes/:id", quoteUpdate)
api.DELETE("/quotes/:id", quoteDelete)
}
}
+22
View File
@@ -0,0 +1,22 @@
package api
import (
"strconv"
"github.com/jackc/pgx/v5/pgconn"
)
func HandleDBError(err error) (int, string) {
pgErr, ok := err.(*pgconn.PgError)
if !ok {
return 500, err.Error()
}
statusStr := pgErr.Message[:3]
message := pgErr.Message[4:]
status, err := strconv.ParseInt(statusStr, 10, 0)
if err == nil {
return int(status), message
} else {
return 400, pgErr.Message
}
}
+172
View File
@@ -0,0 +1,172 @@
package db
import (
"context"
"fmt"
"strings"
"time"
"github.com/H1K0/SkazaNull/models"
"github.com/jackc/pgx/v5/pgxpool"
)
var ConnPool *pgxpool.Pool
func InitDB(connString string) error {
poolConfig, err := pgxpool.ParseConfig(connString)
if err != nil {
return fmt.Errorf("error while parsing connection string: %w", err)
}
poolConfig.MaxConns = 10
poolConfig.MinConns = 0
poolConfig.MaxConnLifetime = time.Hour
poolConfig.HealthCheckPeriod = 30 * time.Second
ConnPool, err = pgxpool.NewWithConfig(context.Background(), poolConfig)
if err != nil {
return fmt.Errorf("error while initializing DB connections pool: %w", err)
}
return nil
}
//#region User
func UserAuth(ctx context.Context, login string, password string) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_auth($1, $2)", login, password)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
func UserGet(ctx context.Context, user_id string) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_get($1)", user_id)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
func UserUpdateName(ctx context.Context, user_id string, new_name string) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_update($1, $2)", user_id, new_name)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
func UserUpdateLogin(ctx context.Context, user_id string, new_login string) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_update($1, NULL, $2)", user_id, new_login)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
func UserUpdateTelegramID(ctx context.Context, user_id string, new_telegram_id int64) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_update($1, NULL, NULL, $2)", user_id, new_telegram_id)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
func UserUpdatePassword(ctx context.Context, user_id string, new_password string) (user models.User, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM user_update($1, NULL, NULL, NULL, $2)", user_id, new_password)
err = row.Scan(&user.ID, &user.Name, &user.Login, &user.Role, &user.TelegramID)
return
}
//#endregion User
//#region Quotes
func QuotesGet(ctx context.Context, user_id string, filter string, sort string, limit int, offset int) (quotes []models.Quote, err error) {
query := "SELECT * FROM quotes_get($1) WHERE position($2 in text)>0 OR position($2 in author)>0"
if sort == "random" {
query += " ORDER BY random()"
} else if sort != "" {
sort_options := strings.Split(sort, ",")
query += " ORDER BY "
for i, sort_option := range sort_options {
sort_order := sort_option[:1]
sort_field := sort_option[1:]
switch sort_order {
case "+":
sort_order = "ASC"
case "-":
sort_order = "DESC"
default:
err = fmt.Errorf("invalid sorting parameter: %q", sort)
return
}
switch sort_field {
case "text":
fallthrough
case "author":
fallthrough
case "datetime":
fallthrough
case "creator.name":
sort_field = strings.ReplaceAll(sort_field, ".", "_")
default:
err = fmt.Errorf("unknown sorting field: %q", sort_field)
return
}
if i > 0 {
query += ", "
}
query += fmt.Sprintf("%s %s", sort_field, sort_order)
}
}
if limit >= 0 {
query += fmt.Sprintf(" LIMIT %d", limit)
}
if offset > 0 {
query += fmt.Sprintf(" OFFSET %d", offset)
}
rows, err := ConnPool.Query(ctx, query, user_id, filter)
if err != nil {
err = fmt.Errorf("error while getting quotes: %w", err)
return
}
for rows.Next() {
var quote models.Quote
err = rows.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
if err != nil {
err = fmt.Errorf("error while fetching quotes: %w", err)
return
}
quotes = append(quotes, quote)
}
err = rows.Err()
return
}
func QuoteGet(ctx context.Context, user_id string, quote_id string) (quote models.Quote, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_get($1, $2)", user_id, quote_id)
err = row.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
return
}
func QuoteAdd(ctx context.Context, user_id string, text string, author string, datetime time.Time) (quote models.Quote, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_add($1, $2, $3, $4)", user_id, text, author, datetime)
err = row.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
return
}
func QuoteUpdateText(ctx context.Context, user_id string, quote_id string, new_text string) (quote models.Quote, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_update($1, $2, $3)", user_id, quote_id, new_text)
err = row.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
return
}
func QuoteUpdateAuthor(ctx context.Context, user_id string, quote_id string, new_author string) (quote models.Quote, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_update($1, $2, NULL, $3)", user_id, quote_id, new_author)
err = row.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
return
}
func QuoteUpdateDatetime(ctx context.Context, user_id string, quote_id string, new_datetime time.Time) (quote models.Quote, err error) {
row := ConnPool.QueryRow(ctx, "SELECT * FROM quote_update($1, $2, NULL, NULL, $3)", user_id, quote_id, new_datetime)
err = row.Scan(&quote.ID, &quote.Text, &quote.Author, &quote.Datetime, &quote.Creator.ID, &quote.Creator.Name, &quote.Creator.Login, &quote.Creator.Role, &quote.Creator.TelegramID)
return
}
func QuoteDelete(ctx context.Context, user_id string, quote_id string) (err error) {
_, err = ConnPool.Exec(ctx, "CALL quote_delete($1, $2)", user_id, quote_id)
return
}
//#endregion Quotes
+50
View File
@@ -0,0 +1,50 @@
module github.com/H1K0/SkazaNull
go 1.22
toolchain go1.22.10
require (
github.com/gin-contrib/sessions v1.0.2
github.com/gin-gonic/gin v1.10.0
github.com/jackc/pgx/v5 v5.7.2
)
require (
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/sessions v1.2.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+115
View File
@@ -0,0 +1,115 @@
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/sessions v1.0.2 h1:UaIjUvTH1cMeOdj3in6dl+Xb6It8RiKRF9Z1anbUyCA=
github.com/gin-contrib/sessions v1.0.2/go.mod h1:KxKxWqWP5LJVDCInulOl4WbLzK2KSPlLesfZ66wRvMs=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o=
github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
+29
View File
@@ -0,0 +1,29 @@
package models
import (
"time"
)
type Role string
const (
Admin Role = "admin"
Editor Role = "editor"
Viewer Role = "viewer"
)
type User struct {
ID string `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Role Role `json:"role"`
TelegramID int64 `json:"telegram_id"`
}
type Quote struct {
ID string `json:"id"`
Text string `json:"text"`
Author string `json:"author"`
Datetime time.Time `json:"datetime"`
Creator User `json:"creator"`
}