-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
85 lines (66 loc) · 2.36 KB
/
main.go
File metadata and controls
85 lines (66 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/XanderMoroz/goBlog/database"
"github.com/XanderMoroz/goBlog/internal/controllers"
"github.com/gofiber/swagger"
_ "github.com/XanderMoroz/goBlog/docs"
)
// @title Good News on Go
// @version 1.0
// @description Сервис с новостными статьями и блогами.
// @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 127.0.0.1:8080
func main() {
log.Println("Подключаюсь к базе данных")
database.Connect()
// Start a new fiber app
log.Println("Инициализируем приложение Fiber")
app := fiber.New(fiber.Config{
ServerHeader: "Good News on Go",
AppName: "Good News on Go v0.0.1",
CaseSensitive: true,
StrictRouting: false,
})
// Middleware
app.Use(recover.New())
app.Use(cors.New())
app.Get("/swagger/*", swagger.HandlerDefault) // default
app.Get("/", func(c *fiber.Ctx) error {
err := c.Status(200).JSON(fiber.Map{
"message": "API APP is UP!",
"docs": "http://127.0.0.1:8080/swagger/index.html",
})
return err
})
// Auth routes
app.Post("/api/v1/register", controllers.Register)
app.Post("/api/v1/login", controllers.Login)
app.Get("/api/v1/current_user", controllers.GetCurrentUser)
app.Get("/api/v1/logout", controllers.Logout)
// Category routes
app.Post("/categories", controllers.CreateNewCategory)
app.Get("/categories", controllers.GetAllCategories)
app.Post("/categories/add_article", controllers.AddArticleToCategory)
app.Post("/categories/remove_article", controllers.DeleteArticleFromCategory)
// Article routes
app.Get("/articles", controllers.GetAllArticles)
app.Post("/articles", controllers.CreateMyArticle)
app.Get("/articles/:id", controllers.GetArticleById)
app.Put("/articles/:id", controllers.UpdateMyArticleById)
app.Delete("/articles/:id", controllers.DeleteMyArticleById)
// Comment routes
app.Post("/article/{id}/add_comment", controllers.AddNewCommentToArticle)
// Start Server and Listen on PORT 8080
if err := app.Listen(":8080"); err != nil {
log.Fatal(err)
}
}