-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (35 loc) · 965 Bytes
/
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
package main
import (
"errors"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"gopkg.in/go-playground/validator.v9"
"os"
_textHttpDelivery "github.com/afzalabbasi/demo-code-invozone/textapiroute/delivery/http"
)
type CustomValidator struct {
validator *validator.Validate
}
func (cv *CustomValidator) Validate(i interface{}) error {
return cv.validator.Struct(i)
}
func main() {
// check if required env variables are provided
hasValidEnvVariables()
//server setup
e := echo.New()
e.Validator = &CustomValidator{validator: validator.New()}
pub := e.Group("/v1")
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.POST},
}))
_textHttpDelivery.NewTextHandler(pub)
e.Logger.Fatal(e.Start(":" + os.Getenv("PORT")))
}
func hasValidEnvVariables() {
if os.Getenv("PORT") == "" {
panic(errors.New("Please Provide Valid PORT"))
}
}