Last active
April 8, 2018 02:35
-
-
Save SerkanSipahi/0708da19bc3971c0d6689edccd57c4be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ######################################### | |
// rest/get.go | |
// ######################################### | |
// This is working but its not what i want. | |
func GET(c echo.Context) error { | |
// do something | |
} | |
// This is not working. | |
// Getting following error: cannot use GET (type func(interface {})) as type echo.HandlerFunc in argument to e.GET | |
// I thought i can pass GET function everything when it has a empty interface, what im doing wrong? | |
func GET(c interface{}){ | |
// do something | |
} | |
// maybe im doing everything wrong? | |
// ######################################### | |
// index.go | |
// ######################################### | |
package main | |
import ( | |
"github.com/labstack/echo" | |
"github.com/serkansipahi/bitcollage/rest" | |
) | |
func main() { | |
e := echo.New() | |
e.GET("/*", rest.GET) | |
e.Logger.Fatal(e.Start(":1323")) | |
} |
you have to install echo: go get -u github.com/labstack/echo
I've got it to a point where I just need to pass the correct object type, but I can't seem to get it to pass an echo.HandlerFunc.
It doesn't solve the problem, but it gets you much closer to resolving it.
/workspace/rest/rest.go
package rest
import (
"github.com/labstack/echo"
)
// This is not working.
// Getting following error: cannot use GET (type func(interface {})) as type echo.HandlerFunc in argument to e.GET
// I thought i can pass GET function everything when it has a empty interface, what im doing wrong?
func GET(c echo.HandlerFunc){
return
}
/workspace/main.go
package main
import (
"./github.com/labstack/echo"
rest "./rest"
)
func main() {
e := echo.New()
e.GET("/*", rest.GET)
e.Logger.Fatal(e.Start(":1323"))
}
e.GET
expects a HandlerFunc
which is declared as HandlerFunc func(Context) error
.
The Context type is an interface, so if you create a content as an interface you should meet the interface requirements.
All that's left is refer to documentation on usage, and usage does seem to work as recommended.
@fubarhouse thank you. Now its clearer to me. I think what i want is not possible as you had described.
func GET(c interface{}){
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, I'm looking further at the echo documentation, it just doesn't seem right...
I've got missing packages, but the package addresses are just wrong.