From 78a463650e4fc8a56b0f68b69c0c03954665fc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sat, 6 Jan 2024 15:55:50 +0500 Subject: [PATCH] =?UTF-8?q?v1.0.3=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 +++ .vscode/tasks.json | 14 ++++++++++++++ main.go | 4 +++- router.go | 4 ++++ stemdb/start.go | 16 ++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..27b9163 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "docwriter.style": "GoDoc" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..013cd13 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "path": "app", + "group": "build", + "problemMatcher": [], + "label": "npm: build - app", + "detail": "vite build" + } + ] +} \ No newline at end of file diff --git a/main.go b/main.go index da36885..7356624 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,10 @@ import ( "github.com/gofiber/fiber/v2/middleware/logger" ) +// The main function initializes a Fiber web server, sets up middleware, initializes the router, and +// listens for incoming requests on port 4321. func main() { - fmt.Printf("stem v1.0.2\n") + fmt.Printf("stem v1.0.3\n") // инициализация fiber app := fiber.New() diff --git a/router.go b/router.go index b6852f9..a2c62a2 100644 --- a/router.go +++ b/router.go @@ -6,6 +6,8 @@ import ( "github.com/jmoiron/sqlx" ) +// The function `initRouter` initializes the router for a Fiber app, sets up static file serving, and +// defines routes for a test page and a list of books. func initRouter(app *fiber.App) { db := stemdb.Connect() @@ -25,6 +27,8 @@ func testPage(c *fiber.Ctx) error { return c.SendString("простая проверка") } +// The function `list_books` returns a Fiber handler that lists all books based on the provided query +// parameters. func list_books(db *sqlx.DB) fiber.Handler { return func(c *fiber.Ctx) error { deleted := c.Query("deleted") diff --git a/stemdb/start.go b/stemdb/start.go index 4c03b59..8b41bff 100644 --- a/stemdb/start.go +++ b/stemdb/start.go @@ -8,6 +8,19 @@ import ( "github.com/jmoiron/sqlx" ) +// The above type represents a book with properties such as ID, author, series, title, and flags for +// deletion and selection. +// @property {int} ID - The ID property is an integer that represents the unique identifier of a book. +// @property {string} Author - The author of the book. +// @property {string} Seria - The "Seria" property in the Book struct represents the series to which +// the book belongs. It is a string that holds the name or identifier of the series. +// @property {string} Title - The title of the book. +// @property {bool} Deleted - The "Deleted" property is a boolean value that indicates whether the book +// has been marked as deleted or not. If the value is true, it means the book has been deleted. If the +// value is false, it means the book is not deleted. +// @property {bool} Selected - The "Selected" property is a boolean value that indicates whether the +// book is currently selected or not. It can be used to keep track of which books are currently being +// interacted with or displayed in a user interface. type Book struct { ID int Author string @@ -19,6 +32,7 @@ type Book struct { var dbx *sqlx.DB +// The Connect function opens a connection to a MySQL database and returns the connection object. func Connect() *sqlx.DB { db, err := sqlx.Open("mysql", "itman:X753951x@(xigmanas:3306)/stem") checkError("open db", err) @@ -28,6 +42,7 @@ func Connect() *sqlx.DB { // возвращает список всех книг // возможно использование фильтров в query, типа: ?deleted=deleted&selected=not selected +// The function `ListAllBooks` retrieves a list of books from a database based on optional conditions. func ListAllBooks(options ...string) ([]Book, error) { cmd := ` SELECT @@ -58,6 +73,7 @@ func ListAllBooks(options ...string) ([]Book, error) { // ============================ разные утилиты ========================== // Проверяет наличие ошибки +// The function "checkError" is used to print and exit the program if an error occurs. func checkError(src string, err error) { if err != nil { fmt.Printf("[db] (%s): %s\n", src, err)