Skip to content

Instantly share code, notes, and snippets.

@SerkanSipahi
Last active April 8, 2018 02:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SerkanSipahi/0708da19bc3971c0d6689edccd57c4be to your computer and use it in GitHub Desktop.
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"))
}
@fubarhouse
Copy link

So immediately some things jump out:

  • package "github.com/serkansipahi/bitcollage/rest" is actually located at "./rest"
  • package "./rest" is not a package, but an application - I'm not entirely sure how you made this non-importable but I'd add a package name to it to try to get around that.
  • package "github.com/serkansipahi/bitcollage/rest" actually has two dependencies missing entirely from github!
github.com/labstack/echo/echo.go:54:2: cannot find package "github.com/labstack/gommon/color" in any of:
	/usr/local/go/src/github.com/labstack/gommon/color (from $GOROOT)
	/usr/local/go/bin/src/github.com/labstack/gommon/color (from $GOPATH)
github.com/labstack/echo/echo.go:55:2: cannot find package "github.com/labstack/gommon/log" in any of:
	/usr/local/go/src/github.com/labstack/gommon/log (from $GOROOT)
	/usr/local/go/bin/src/github.com/labstack/gommon/log (from $GOPATH)

@SerkanSipahi
Copy link
Author

SerkanSipahi commented Jan 15, 2017

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

@fubarhouse
Copy link

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.

@SerkanSipahi
Copy link
Author

you have to install echo: go get -u github.com/labstack/echo

@fubarhouse
Copy link

fubarhouse commented Jan 15, 2017

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.

@fubarhouse
Copy link

All that's left is refer to documentation on usage, and usage does seem to work as recommended.

@SerkanSipahi
Copy link
Author

SerkanSipahi commented Jan 16, 2017

@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