realize/server/main.go

30 lines
630 B
Go
Raw Normal View History

2016-09-01 22:35:31 +00:00
package server
import (
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
2016-09-06 00:31:44 +00:00
"github.com/labstack/echo/middleware"
2016-09-01 22:35:31 +00:00
"net/http"
)
2016-09-06 00:31:44 +00:00
func render(c echo.Context, path string) error{
data, err := Asset(path)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound)
}
rs := c.Response()
rs.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
rs.WriteHeader(http.StatusOK)
rs.Write(data)
return nil
}
2016-09-01 22:35:31 +00:00
func init() {
e := echo.New()
2016-09-06 00:31:44 +00:00
e.Use(middleware.Gzip())
2016-09-01 22:35:31 +00:00
e.GET("/", func(c echo.Context) error {
2016-09-06 00:31:44 +00:00
return render(c, "server/assets/index.html")
2016-09-01 22:35:31 +00:00
})
go e.Run(standard.New(":5000"))
}