labstack / echox Goto Github PK
View Code? Open in Web Editor NEWEcho cookbook and website
Home Page: https://echo.labstack.com
License: MIT License
Echo cookbook and website
Home Page: https://echo.labstack.com
License: MIT License
Hello @vishr @matcornic ,
I am not able to run the JWT cookbook code. On line 56 I get the following error:
cannot use middleware.Logger() (value with invalid type) as echo.MiddlewareFunc value in argument to e.Use
Any help would be much appreciated.
Hi Guys
Please help check below issue. thanks!
https://echo.labstack.com/guide/request
example is Validate Data
package main
import (
"gopkg.in/go-playground/validator.v8"
"github.com/labstack/echo"
"net/http"
)
type (
User struct {
Name string json:"name" validate:"required"
Email string json:"email" validate:"required,email"
}
CustomValidator struct {
validator *validator.Validate
}
)
func (cv *CustomValidator) Validate(i interface{}) error {
return cv.validator.Struct(i)
}
func main() {
e := echo.New()
e.Validator = &CustomValidator{validator: validator.New()}
e.POST("/users", func(c echo.Context) (err error) {
u := new(User)
if err = c.Bind(u); err != nil {
return
}
if err = c.Validate(u); err != nil {
return
}
return c.JSON(http.StatusOK, u)
})
e.Logger.Fatal(e.Start(":1323"))
}
./server3.go:26:57: not enough arguments in call to validator.New
have ()
want (*validator.Config)
Update auto tls recipe
Site appears to be down.
Workaround: was able to clone this project, brew install hugo
and then serve the site with Hugo locally. Pretty cool.
Migrated from labstack/echo#277
Some pages on site have a broken syntax highlighting.
For example:
URL: https://echo.labstack.com/guide
Screenshot: https://i.imgur.com/cC05Ev8.jpg
I follow this documentation -> https://echo.labstack.com/guide/request
My code is:
main.go
package main
import (
"github.com/labstack/echo"
"gopkg.in/go-playground/validator.v9"
)
type CustomValidator struct {
validator *validator.Validate
}
func (cv *CustomValidator) Validate(i interface{}) error {
return cv.validator.Struct(i)
}
func main() {
e := echo.New()
e.Validator = &CustomValidator{validator: validator.New()}
// TODOS
e.GET("/todos", getTodos)
e.POST("/todos", createTodo)
e.Logger.Fatal(e.Start(":1323"))
}
todo.go
package main
import (
"github.com/labstack/echo"
)
type Todo struct {
Title string `json:"title" validate:"required"`
}
var todos = []Todo {
{
Title: "Saugen",
},
}
func getTodos(c echo.Context) error {
return c.JSONPretty(200, map[string][]Todo {
"todos": todos,
}, " ")
}
func createTodo(c echo.Context) (err error) {
todo := new(Todo)
if err = c.Bind(todo); err != nil {
return
}
if err = c.Validate(todo); err != nil {
return
}
todos = append(todos, *todo)
return c.JSONPretty(200, *todo, " ")
}
My payload is:
{
"title": ""
}
My result is:
{
"message": "Internal Server Error"
}
which should not be!
Console output:
{"time":"2018-03-08T20:51:49.3489642+01:00","level":"ERROR","prefix":"echo","file":"echo.go","line":"286","message":"Key: 'Todo.Title' Error:Field validation for 'Title' failed on the 'required' tag"}
Migrated from labstack/echo#317
Copied from Echo: labstack/echo#1309
Could you please add an explicit LICENSE
file to the repo so that it's clear under what terms the content is provided, and under what terms user contributions are licensed?
[...] without a license, the default copyright laws apply, meaning that you retain all rights to your source code and no one may reproduce, distribute, or create derivative works from your work. If you're creating an open source project, we strongly encourage you to include an open source license.
Thanks!
https://github.com/labstack/echox/blob/master/website/layouts/partials/topnav.html#L15
Only occurs when in the middlwware section
Migrated from labstack/echo#269
Please mention you recipe request in the area.
Can you tell me a way to create a http2 server without tls connection?
github.com/dgrijalva/jwt-go
please don't del it.# command-line-arguments
.\main.go:25: req.MultipartForm.File undefined (type func() (*multipart.Form, error) has no field or method File)
I've try echo example and found an error on CRUD
the first one is
./server.go:72: e.DELETE undefined (type *echo.Echo has no field or method DELETE, but does have Delete)
then I just comment that line and
found another one when send POST request to localhost:1323/users
it return response
Unsupported Media Type
Pre middleware
Hi,
I just ran your JWT example code and I wonder why the middleware throws no 401 after the token expired?
I changed the time.Hour
to time.Second
, waited 10 seconds and I could still access the /restricted
route where it prints Welcome Jon Snow.
Did I miss something?
claims["exp"] = time.Now().Add(time.Second * 10).Unix()
OS
Proxy
Example / Cookbook with App Engine on Go 1.11 won't work as build tags are deprecated now.
Just use echo on port 8080 or define custom with env "Port".
my env: win10/amd64/go-1.6
when use
# Valid token
$ curl localhost:1323/restricted -H "Authorization: Bearer <token>"
it gets not "Access granted with JWT" but nothing.
it seems func restricted(){...}
not executed.
Migrated from labstack/echo#516
In https://echo.labstack.com/cookbook/jwt , ==
results in a timing attack (even if you are comparing hashes like this: hash(webPassword) == savedHashedPassword
).
The example code should probably have at least a comment // example only; string comparisons are vulnerable to timing attacks
and perhaps another comment that even just hashed passwords should use the timing-attack-resistant comparison functions within the hash library, rather than a regular ==
string comparison.
Greetings,
I have just started playing around with the echo & echox frameworks and was able to compile and run the jsonp recipe, but had some problems when it came to testing the streaming-response recipe:
lonnie@spartan:~/work/streaming-response$ go build server.go
./server.go:34: undefined: echo.ContentType
./server.go:34: undefined: echo.ApplicationJSON
Can you please advice what may be happening as I am running on Ubuntu 15.04 and have installed:
go version go1.6 linux/amd64
cheers,
Lonnie
Managed VMs has been renamed to App Engine flexible environment.
Written as:
e.Use(middleware.KeyAuth(func(key string) (bool, error) {
return key == "valid-key", nil
}))
Should be:
e.Use(middleware.KeyAuth(func(key string, c echo.Context) (error, bool) {
return nil, key == "valid-key"
}))
https://echo.labstack.com/middleware/proxy
AND
https://github.com/labstack/echox/blob/master/website/content/middleware/proxy.md
middleware.RoundRobinBalancer
change
middleware.NewRoundRobinBalancer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.