v1.0.3 добавил описания функций

main
parent 9f117ac4d6
commit 78a463650e

@ -0,0 +1,3 @@
{
"docwriter.style": "GoDoc"
}

14
.vscode/tasks.json vendored

@ -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"
}
]
}

@ -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()

@ -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")

@ -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)

Loading…
Cancel
Save