generated from UCLALibrary/service-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (35 loc) · 801 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
44
45
package main
import (
"net/http"
"strconv"
"github.com/labstack/echo/v4"
)
const Port = 8888
// App represents your application.
type App struct {
Router *echo.Echo
}
func main() {
app := NewApp()
app.Routes()
err := app.Router.Start(":" + strconv.Itoa(Port))
if err != nil {
panic(err)
}
}
// NewApp initializes a new instance of your application.
func NewApp() *App {
e := echo.New()
return &App{Router: e}
}
// Routes configure the server's endpoints.
func (app *App) Routes() {
app.Router.GET("/", helloWorld)
app.Router.RouteNotFound("/*", NotFoundHandler)
}
func helloWorld(c echo.Context) error {
return c.String(http.StatusOK, "hello world")
}
func NotFoundHandler(c echo.Context) error {
return echo.NewHTTPError(http.StatusNotFound, "This is not yet supported")
}