-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_server.go
69 lines (60 loc) · 1.76 KB
/
start_server.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
package main
import (
"github.com/go-playground/validator/v10"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
log "github.com/sirupsen/logrus"
"net/http"
"telno/config"
"telno/database"
m "telno/middleware"
"telno/models"
routes "telno/route"
"telno/service"
"telno/service/latest_bar"
"telno/service/sitemap"
"time"
)
func initServer(e *echo.Echo) {
config.LoadEnv(".env")
config.LoadConfig()
e.HideBanner = true
e.Use(middleware.Recover())
e.Use(m.LogrusMiddleware)
e.Use(m.AfterResponseMiddleware)
e.Use(m.AdminCheck)
e.Use(middleware.Secure())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace},
}))
e.Any("*", func(c echo.Context) error {
return c.JSON(http.StatusNotFound, models.Response{
Code: http.StatusNotFound,
Message: "Not Found",
Data: nil,
})
})
e.Validator = &config.CustomValidator{Validator: validator.New()}
// LOGGER
log.SetFormatter(&log.TextFormatter{
EnvironmentOverrideColors: true,
ForceColors: true,
FullTimestamp: true,
TimestampFormat: time.RFC3339,
})
log.SetLevel(log.DebugLevel)
routes.UseRoute(e)
database.Database.Connect()
go initSitemapGenerator()
sitemap.SetCronForSitemap()
latest_bar.SetLatestCron()
service.SetCronForIndexMap()
latest_bar.InitLatestComments()
latest_bar.InitLatestSearches()
}
func initSitemapGenerator() {
config.ApiConfig.Sitemaps = sitemap.GenerateNumbersSitemap()
config.ApiConfig.Sitemap = sitemap.GenerateBaseSitemap()
config.ApiConfig.SitemapMain = sitemap.GenerateMainSitemap()
}