-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (72 loc) · 2.84 KB
/
main.go
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
86
87
88
89
90
91
92
93
package main
import (
"github.com/sylba2050/RedSpear/handler/article"
"github.com/sylba2050/RedSpear/handler/markdown"
"github.com/sylba2050/RedSpear/handler/user"
"github.com/sylba2050/RedSpear/struct/DB"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
func main() {
e := echo.New()
e.Use(middleware.Recover())
e.Use(middleware.Logger())
e.Use(middleware.CORS())
db, err := gorm.Open("sqlite3", "DB/main.sqlite3")
if err != nil {
panic("failed to connect database")
}
defer db.Close()
db.AutoMigrate(&DB.User{})
db.AutoMigrate(&DB.Article{})
db.AutoMigrate(&DB.ArticleLike{})
db.AutoMigrate(&DB.ArticleStock{})
db.AutoMigrate(&DB.ArticleComment{})
db.AutoMigrate(&DB.CommentLike{})
db.AutoMigrate(&DB.User{})
db.AutoMigrate(&DB.FollowTag{})
db.AutoMigrate(&DB.FF{})
e.Static("/img", "img")
e.Static("/js", "js")
e.Static("/css", "css")
e.File("/", "html/index.html")
e.File("/write", "html/write.html")
e.File("/items/:articleid", "html/article.html")
e.GET("/article/:articleid", article.GetById(db))
e.POST("/article", article.Post(db))
e.PUT("/article", article.Update(db))
e.DELETE("/article/:articleid", article.Delete(db))
e.GET("/article/stock/:articleid", article.GetStocksByArticleId(db))
e.POST("/article/stock/:articleid", article.Stock(db))
e.DELETE("/article/stock/:articleid", article.UnStock(db))
e.GET("/article/like/:articleid", article.GetLikesByArticleId(db))
e.POST("/article/like/:articleid", article.Like(db))
e.DELETE("/article/like/:articleid", article.UnLike(db))
e.GET("/article/comments/:articleid", article.GetCommentsByArticleId(db))
e.POST("/article/comment/:articleid", article.Comment(db))
e.PUT("/article/comment/update/:commentid", article.UpdateComment(db))
e.DELETE("/article/comment/delete/:commentid", article.DeleteComment(db))
e.GET("/articles", article.Get(db))
e.GET("/articles/newer", article.GetNewer(db))
e.GET("/articles/visited", article.GetVisited(db))
e.GET("/articles/populer/day", article.GetPopulerPerDay(db))
e.GET("/articles/populer/week", article.GetPopulerPerWeek(db))
e.GET("/articles/populer/month", article.GetPopulerPerMonth(db))
e.GET("/articles/:userid", article.GetByUser(db))
e.GET("/article/cp/:articleid", article.Cp(db))
e.POST("/user", user.Create(db))
e.PUT("/user", user.Update(db))
e.DELETE("/user", user.Delete(db))
e.POST("/user/follow/:userid", user.Follow(db))
e.DELETE("/user/follow/:userid", user.UnFollow(db))
e.POST("/user/tab/follow", user.TabFollow(db))
e.DELETE("/user/tab/follow", user.TabUnFollow(db))
e.GET("/user/cp/:userid", user.Cp(db))
e.GET("/user/stock/:userid", user.GetStockByUserId(db))
e.GET("/user/like/:userid", user.GetLikeByUserId(db))
e.GET("/user/comment/:userid", user.GetCommentByUserId(db))
e.POST("/md", markdown.Default)
e.Start(":8080")
}