-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
httprouter.go Need Type Assertion #292
Comments
Can you show us how you are using it? A bit of code might help to find the problem. |
Tried to dig into this blindly, but I can't reproduce any error:
works as expected. Maybe you are having an outdated version of httprouter or any other dependency.. possibly try updating them first and then we can search further :) |
Yeah, sorry for the lack of context.
Here are the related sections of
Was trying to figure out how to integrate into my existing code base that uses gorilla mux. I found this Example and tried to go down this route: https://github.com/manyminds/api2go-adapter/tree/master/gorillamux
Results in the error I initially reported. |
Related to manyminds/api2go-adapter#5 it seems. |
so it is fixed for you? |
No, when I have the above code snippet as provided in the gorillamux adapter example, I get the error in the initial report. |
ah sry I overlooked that one comment :) |
Ah I see now you are using an old version of api2go from november 2015..... puh it's hard to provide any help here, but I would guess that the adapter version would be too new... |
Is this the recommended way to connect api2go to gorilla mux, or would you recommend a different method? |
Currently that's the way to do it, I just tested it:
this will work with all versions on master. On version 0.6 somethings might be a lot different. But I understand the confusion, the Readme.md in the adapter package is outdated... We will improve and update all documentation. That should not happen - sorry :/ |
Here's a larger snippet of my code:
Then in my daemon, I'm calling:
This all still results in |
Yeah... well the fact that |
Updated to match your example. Still running the latest versions based on the
|
Ok, I think I understand now. It seems that since you used to tag releases, You might want to tag a more recent commit as a newer release. https://github.com/golang/dep With that in mind, I still had to change a portion of the code.
Do you want a PR to that effect? |
PR failed miserably in the tests you have setup, so I'm back to not understanding why I'm getting this error. Maybe there's a namespace conflict? |
The latest Tag is For proof I just tested a vanilla setup and it works fine:
where as gorilla.go will be one of the snippets above. |
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"github.com/manyminds/api2go"
"domain.com/user/mypkg"
)
var portFlag = flag.Int(snip)
var cassandraAppFlag = flag.String(snip)
var cassandraKeyspaceFlag = flag.String(snip)
// logPath returns a file hander or os.Stdout based on
// whether this is local dev or deployed in EC2
func logFile() io.Writer {
snip
}
// initDB initializes the database session
func initDB(app, keyspace string) error {
snip
}
func main() {
// parse flags and set port
flag.Parse()
port := fmt.Sprintf(":%v", strconv.Itoa(*portFlag))
app := *cassandraAppFlag
keyspace := *cassandraKeyspaceFlag
// init DB connection
err := initDB(app, keyspace)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
// new jsonapi spec
api := api2go.NewAPI("v2")
api.AddResource(Device{}, &Device{})
api.AddResource(Family{}, &Family{})
api.AddResource(Job{}, &Job{})
api.AddResource(Sequence{}, &Sequence{})
// Index, Healthcheck, initDatabase
r := api.Router()
r.Handle("GET", "/", mypkg.Index)
r.Handle("GET", "/healthcheck", mypkg.HealthCheck)
r.Handle("GET", "/InitDB", mypkg.InitDB)
// launch http service
log.Printf("Launching server on http://localhost%v\n", port)
log.Fatal(http.ListenAndServe(port, api.Handler()))
} Ripped out all the gorilla mux stuff to simplify things. Still getting the Not really sure where to go from here honestly. |
Just as a refresher, here are my current deps in the vendor directory:
and my go version
|
I just noticed the v1.1 tag on the httprouter package, and pinned to master instead. Problem is gone. |
As described in manyminds#292 (comment)
In order to use gin with api2go, a build tag is required. go-dep doesnt support setting build tags in so gin dependencies will be skipped. Therefore, gin needs to be explicitly listed as a dependency. This takes us up to [api2go issue #292](manyminds/api2go#292).
Hey guys,
Not sure why I'm getting this error when I attempt to build with
api2go
:Seems to be this line here: https://github.com/manyminds/api2go/blob/master/routing/httprouter.go#L51
If I comment this out everything seems to validate fine. Given the code in that section is from two years ago, I imagine there's just a small tweak that needs to be made?
The text was updated successfully, but these errors were encountered: