-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
52 lines (46 loc) · 1.74 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
package main
import (
IndexAction "crawl/controller"
"crawl/database"
"crawl/util"
"fmt"
"github.com/gin-gonic/gin"
"os"
"path"
)
func main() {
config, err := util.LoadConfig(".")
if err != nil {
fmt.Println("not load config", err)
panic(err)
}
db, err := database.DBConn(config)
if err != nil {
panic(err)
}
r := gin.Default()
gin.SetMode(gin.ReleaseMode)
cwd, _ := os.Getwd()
r.LoadHTMLGlob(path.Join(cwd, "templates/*.tmpl"))
controller := IndexAction.Controller{}
r.StaticFile("/favicon.ico", "./templates/favicon.ico")
r.StaticFile("/css/styles.css", "./templates/css/styles.css")
r.StaticFile("/robots.txt", "./templates/robots.txt")
r.StaticFile("/images/image.webp", "./templates/images/image.webp")
r.StaticFile("/images/icon/dev-to.png", "./templates/images/icon/dev-to.png")
r.StaticFile("/images/icon/hashnode.jpeg", "./templates/images/icon/hashnode.jpeg")
r.StaticFile("/images/icon/freecodecam.jpeg", "./templates/images/icon/freecodecam.jpeg")
r.StaticFile("/images/icon/logrocket.png", "./templates/images/icon/logrocket.png")
r.StaticFile("/images/icon/infoq.png", "./templates/images/icon/infoq.png")
r.StaticFile("/google18bb3160694ad28a.html", "./templates/google18bb3160694ad28a.html")
r.GET("/", controller.GetAllArticles(db))
r.GET("/search", controller.Search(config, db))
r.GET("/top", controller.GetAllArticlesByTop(db))
r.GET("/tags", controller.GetAllTags(db))
r.GET("/articles.xml", controller.Sitemap(db))
r.GET("/tags.xml", controller.SitemapTags(db))
r.GET("/sources/:website_slug", controller.GetArticleBySource(db))
r.GET("/t/:tag", controller.GetArticleByTag(db))
r.GET("/:slug", controller.GetArticleBySlug(db))
r.Run(":9000") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}