Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

remove echo (#66)

Guilherme Oenning3e614ba8ae38
diff --git a/app/handlers/idea.go b/app/handlers/idea.go
index 91fa1605f..4e6049539 100644
--- a/app/handlers/idea.go
+++ b/app/handlers/idea.go
@@ -6,7 +6,6 @@ import (
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/web"
- "github.com/labstack/echo"
)
// Index is the default home page
@@ -17,7 +16,7 @@ func Index() web.HandlerFunc {
return c.Failure(err)
}
- return c.Page(echo.Map{
+ return c.Page(web.Map{
"ideas": ideas,
})
}
@@ -37,13 +36,13 @@ func PostIdea() web.HandlerFunc {
}
if strings.Trim(input.Title, " ") == "" {
- return c.JSON(400, echo.Map{
+ return c.JSON(400, web.Map{
"message": "Title is required.",
})
}
if len(input.Title) < 10 || len(strings.Split(input.Title, " ")) < 3 {
- return c.JSON(400, echo.Map{
+ return c.JSON(400, web.Map{
"message": "Title needs to be more descriptive.",
})
}
@@ -84,7 +83,7 @@ func IdeaDetails() web.HandlerFunc {
return c.Failure(err)
}
- return c.Page(echo.Map{
+ return c.Page(web.Map{
"comments": comments,
"idea": idea,
})
@@ -104,7 +103,7 @@ func PostComment() web.HandlerFunc {
}
if strings.Trim(input.Content, " ") == "" {
- return c.JSON(400, echo.Map{
+ return c.JSON(400, web.Map{
"message": "Comment is required.",
})
}
@@ -123,7 +122,7 @@ func PostComment() web.HandlerFunc {
return c.Failure(err)
}
- return c.JSON(200, echo.Map{})
+ return c.JSON(200, web.Map{})
}
}
@@ -141,13 +140,13 @@ func SetResponse() web.HandlerFunc {
}
if input.Status < models.IdeaNew || input.Status > models.IdeaDeclined {
- return c.JSON(400, echo.Map{
+ return c.JSON(400, web.Map{
"message": "Status is invalid.",
})
}
if strings.Trim(input.Text, " ") == "" {
- return c.JSON(400, echo.Map{
+ return c.JSON(400, web.Map{
"message": "Text is required.",
})
}
@@ -166,7 +165,7 @@ func SetResponse() web.HandlerFunc {
return c.Failure(err)
}
- return c.JSON(200, echo.Map{})
+ return c.JSON(200, web.Map{})
}
}
@@ -198,5 +197,5 @@ func addOrRemoveSupporter(c web.Context, addOrRemove func(number, userID int) er
return c.Failure(err)
}
- return c.JSON(200, echo.Map{})
+ return c.JSON(200, web.Map{})
}
diff --git a/app/handlers/signup.go b/app/handlers/signup.go
index 0745e9d9f..ee3fb61ef 100644
--- a/app/handlers/signup.go
+++ b/app/handlers/signup.go
@@ -11,7 +11,6 @@ import (
"github.com/getfider/fider/app/pkg/jwt"
"github.com/getfider/fider/app/pkg/web"
"github.com/getfider/fider/app/validate"
- "github.com/labstack/echo"
)
// CheckAvailability checks if given domain is available to be used
@@ -24,12 +23,12 @@ func CheckAvailability() web.HandlerFunc {
}
if !ok {
- return c.Ok(echo.Map{
+ return c.Ok(web.Map{
"message": strings.Join(messages, ","),
})
}
- return c.Ok(echo.Map{})
+ return c.Ok(web.Map{})
}
}
@@ -48,7 +47,7 @@ func CreateTenant() web.HandlerFunc {
}
if input.Token == "" {
- return c.BadRequest(echo.Map{
+ return c.BadRequest(web.Map{
"message": "Please identify yourself before proceeding",
})
}
@@ -63,7 +62,7 @@ func CreateTenant() web.HandlerFunc {
}
if input.Name == "" {
- return c.BadRequest(echo.Map{
+ return c.BadRequest(web.Map{
"message": "Name is required",
})
}
@@ -74,7 +73,7 @@ func CreateTenant() web.HandlerFunc {
}
if !ok {
- return c.BadRequest(echo.Map{
+ return c.BadRequest(web.Map{
"message": strings.Join(messages, ","),
})
}
@@ -97,7 +96,7 @@ func CreateTenant() web.HandlerFunc {
return c.Failure(err)
}
- return c.Ok(echo.Map{
+ return c.Ok(web.Map{
"id": tenant.ID,
})
}
@@ -116,6 +115,6 @@ func SignUp() web.HandlerFunc {
return c.Redirect(http.StatusTemporaryRedirect, "/")
}
}
- return c.Page(echo.Map{})
+ return c.Page(web.Map{})
}
}
diff --git a/app/handlers/status.go b/app/handlers/status.go
index c924ca183..66620012a 100644
--- a/app/handlers/status.go
+++ b/app/handlers/status.go
@@ -6,13 +6,12 @@ import (
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/web"
- "github.com/labstack/echo"
)
//Status returns some useful information
func Status(settings *models.AppSettings) web.HandlerFunc {
return func(c web.Context) error {
- return c.JSON(http.StatusOK, echo.Map{
+ return c.JSON(http.StatusOK, web.Map{
"build": settings.BuildTime,
"version": settings.Version,
"env": settings.Environment,
diff --git a/app/mock/server.go b/app/mock/server.go
index eb6ee47e0..40e7690f0 100644
--- a/app/mock/server.go
+++ b/app/mock/server.go
@@ -11,13 +11,11 @@ import (
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/web"
"github.com/jmoiron/jsonq"
- "github.com/labstack/echo"
)
// Server is a HTTP server wrapper for testing purpose
type Server struct {
engine *web.Engine
- handler echo.HandlerFunc
Context web.Context
recorder *httptest.ResponseRecorder
middleware web.MiddlewareFunc
@@ -36,7 +34,7 @@ func NewServer() *Server {
settings := &models.AppSettings{}
engine := web.New(settings)
- request, _ := http.NewRequest(echo.GET, "/", nil)
+ request, _ := http.NewRequest("GET", "/", nil)
recorder := httptest.NewRecorder()
context := engine.NewContext(request, recorder)
@@ -74,7 +72,7 @@ func (s *Server) ExecuteAsJSON(handler web.HandlerFunc) (int, *jsonq.JsonQuery)
// ExecutePost executes given handler as POST and return response
func (s *Server) ExecutePost(handler web.HandlerFunc, body string) (int, *httptest.ResponseRecorder) {
req, _ := http.NewRequest("POST", "/", strings.NewReader(body))
- req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationJSON)
+ req.Header.Add("Content-Type", "application/json; charset=UTF-8")
s.Context.SetRequest(req)
if err := s.middleware(handler)(s.Context); err != nil {
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index c5edcf0cf..3059accc8 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -13,6 +13,9 @@ import (
"github.com/labstack/echo"
)
+// Map defines a generic map of type `map[string]interface{}`.
+type Map map[string]interface{}
+
var (
preffixKey = "__CTX_"
tenantContextKey = preffixKey + "TENANT"
@@ -63,17 +66,17 @@ func (ctx *Context) Failure(err error) error {
}
//Ok returns 200 OK with JSON result
-func (ctx *Context) Ok(dict echo.Map) error {
+func (ctx *Context) Ok(dict Map) error {
return ctx.JSON(http.StatusOK, dict)
}
//BadRequest returns 400 BadRequest with JSON result
-func (ctx *Context) BadRequest(dict echo.Map) error {
+func (ctx *Context) BadRequest(dict Map) error {
return ctx.JSON(http.StatusBadRequest, dict)
}
//Page returns a page with given variables
-func (ctx *Context) Page(dict echo.Map) error {
+func (ctx *Context) Page(dict Map) error {
return ctx.Render(http.StatusOK, "index.html", dict)
}
@@ -145,10 +148,10 @@ func (ctx *Context) ParamAsInt(name string) (int, error) {
}
//RenderVars returns all registered RenderVar
-func (ctx *Context) RenderVars() echo.Map {
+func (ctx *Context) RenderVars() Map {
vars := ctx.Get("__renderVars")
if vars != nil {
- return vars.(echo.Map)
+ return vars.(Map)
}
return nil
}
@@ -157,10 +160,10 @@ func (ctx *Context) RenderVars() echo.Map {
func (ctx *Context) AddRenderVar(name string, value interface{}) {
var renderVars = ctx.Get("__renderVars")
if renderVars == nil {
- renderVars = make(echo.Map)
+ renderVars = make(Map)
ctx.Set("__renderVars", renderVars)
}
ctx.Logger().Debugf("storage.%v: %v", name, value)
- renderVars.(echo.Map)[name] = value
+ renderVars.(Map)[name] = value
}
diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.go
index 3d5174217..85ad868cc 100644
--- a/app/pkg/web/engine.go
+++ b/app/pkg/web/engine.go
@@ -109,10 +109,10 @@ func (g *Group) Post(path string, handler HandlerFunc) {
func errorHandler(e error, c echo.Context) {
if strings.Contains(e.Error(), "code=404") {
c.Logger().Debug(fmt.Sprintf("%s [%s] %s", e, c.Request().Method, c.Request().URL.String()))
- c.Render(http.StatusNotFound, "404.html", echo.Map{})
+ c.Render(http.StatusNotFound, "404.html", Map{})
} else {
c.Logger().Error(e)
- c.Render(http.StatusInternalServerError, "500.html", echo.Map{})
+ c.Render(http.StatusInternalServerError, "500.html", Map{})
}
}
diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.go
index c8081e53a..de2f9ef3d 100644
--- a/app/pkg/web/renderer.go
+++ b/app/pkg/web/renderer.go
@@ -58,11 +58,11 @@ func (r *HTMLRenderer) Render(w io.Writer, name string, data interface{}, c echo
tmpl = r.add(name)
}
- m := data.(echo.Map)
+ m := data.(Map)
m["tenant"] = ctx.Tenant()
- m["auth"] = echo.Map{
+ m["auth"] = Map{
"endpoint": ctx.AuthEndpoint(),
- "providers": echo.Map{
+ "providers": Map{
oauth.GoogleProvider: oauth.IsProviderEnabled(oauth.GoogleProvider),
oauth.FacebookProvider: oauth.IsProviderEnabled(oauth.FacebookProvider),
},
diff --git a/router.go b/router.go
index b6885557e..dd465cd79 100644
--- a/router.go
+++ b/router.go
@@ -8,7 +8,6 @@ import (
"github.com/getfider/fider/app/pkg/oauth"
"github.com/getfider/fider/app/pkg/web"
"github.com/getfider/fider/app/storage"
- "github.com/labstack/echo"
)
// AppServices holds reference to all Fider services
@@ -92,7 +91,7 @@ func GetMainEngine(settings *models.AppSettings) *web.Engine {
admin.Use(middlewares.IsAuthorized(models.RoleMember, models.RoleAdministrator))
admin.Get("", func(ctx web.Context) error {
- return ctx.Page(echo.Map{})
+ return ctx.Page(web.Map{})
})
}
}