-
-
Save SerkanSipahi/0708da19bc3971c0d6689edccd57c4be to your computer and use it in GitHub Desktop.
// ######################################### | |
// 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")) | |
} |
rest/get.go is a package. I forgot it in gist to write !
package rest
func GET(c interface{}){
// do something
}
1.) and you have to set the package path to: github.com/serkansipahi/bitcollage under "Edit Configuration" (above-right)
2.) now it will show the error when you try to compile: cannot use GET (type func(interface {})) as type echo.HandlerFunc in argument to e.GET
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.
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{}){
}
So immediately some things jump out: