/
imagereductor.go
45 lines (39 loc) · 1.46 KB
/
imagereductor.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
package main
import (
"fmt"
"os"
"github.com/golang-jwt/jwt/v5"
"github.com/howood/imagereductor/application/actor"
"github.com/howood/imagereductor/domain/entity"
"github.com/howood/imagereductor/infrastructure/custommiddleware"
"github.com/howood/imagereductor/interfaces/handler"
"github.com/howood/imagereductor/library/utils"
echojwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// DefaultPort is default port of server
var DefaultPort = utils.GetOsEnv("SERVER_PORT", "8080")
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORS())
if os.Getenv("ADMIN_MODE") == "enable" {
e.GET("/token", handler.TokenHandler{}.Request, custommiddleware.IPRestriction())
}
jwtconfig := echojwt.Config{
Skipper: custommiddleware.OptionsMethodSkipper,
NewClaimsFunc: func(c echo.Context) jwt.Claims {
return new(entity.JwtClaims)
},
SigningKey: []byte(actor.TokenSecret),
}
e.GET("/", handler.ImageReductionHandler{}.Request)
e.POST("/", handler.ImageReductionHandler{}.Upload, echojwt.WithConfig(jwtconfig))
e.GET("/files", handler.ImageReductionHandler{}.RequestFile)
e.POST("/files", handler.ImageReductionHandler{}.UploadFile, echojwt.WithConfig(jwtconfig))
e.GET("/streaming", handler.ImageReductionHandler{}.RequestStreaming)
e.GET("/info", handler.ImageReductionHandler{}.RequestInfo)
e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", DefaultPort)))
}