-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (64 loc) · 2 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
package main
import (
"fmt"
"html/template"
"io"
"net/http"
"github.com/JinHyukParkk/CapstoneProject/controllers"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
// TemplateRenderer is a custom html/template renderer for Echo framework
type TemplateRenderer struct {
templates *template.Template
}
// Render renders a template document
func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
// Add global methods if data is a map
if viewContext, isMap := data.(map[string]interface{}); isMap {
viewContext["reverse"] = c.Echo().Reverse
}
return t.templates.ExecuteTemplate(w, name, data)
}
func customHTTPErrorHandler(err error, c echo.Context) {
code := http.StatusInternalServerError
if he, ok := err.(*echo.HTTPError); ok {
code = he.Code
}
errorPage := fmt.Sprintf("errorHtml/%d.html", code)
if err := c.File(errorPage); err != nil {
c.Logger().Error(err)
}
// c.Logger().Error(err)
}
func main() {
e := echo.New()
//HTTP Error Handler
e.HTTPErrorHandler = customHTTPErrorHandler
//middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
//CORS
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.PUT, echo.POST, echo.DELETE},
}))
// 둘 중 아무거나 써도 됨. js, css 파일 root directory 설정
// e.Use(middleware.Static("/static"))
e.Static("/", "static")
//처음 시작하는 파일 설정.
e.File("/", "template/index.html")
//middleware로 static 관리
// e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
// Root: "static",
// Index: "../template/index.html",
// Browse: true,
// }))
// route
e.GET("/videoList", controllers.VideoList)
e.POST("/videoUpload", controllers.VideoUpload)
e.GET("/keyword/:keyword", controllers.SearchKeyword)
e.GET("/oneKeyword/:filename/:keyword", controllers.OneSearchKeyword)
e.DELETE("/deleteVideo/:file", controllers.DeleteVideo)
e.Logger.Fatal(e.Start(":8080"))
}