revel/cmd

Arg types in generated routes.go and run.go

Closed this issue · 4 comments

One issue is about the controller arg type.
eg: controller method

func (c Base) Debug(id bson.ObjectId) revel.Result {
}

before 1.0, generated routes.go using interface{}

func (_ tBase) Debug(
		id interface{},
		) string {
	args := make(map[string]string)
	
	revel.Unbind(args, "id", id)
	return revel.MainRouter.Reverse("Base.Debug", args).URL
}

But for 1.0, generated routes using bson.ObjectId, before generate routes.go, app will terminate at line 224, "source_info_processor.go"

# line 222 ###
if importPath, ok = s.sourceProcessor.importMap[typeExpr.PkgName]; !ok {
utils.Logger.Fatalf("Failed to find import for arg of type: %s , %s", typeExpr.PkgName, typeExpr.TypeName(""))
# line 225 ###

If ignore the Logger.Fatalf, generate routes.go is using bson.ObjectId as type instead of interface{} in old version

func (_ tBase) Debug(
		id bson.ObjectId,
		) string {
	args := make(map[string]string)
	
	revel.Unbind(args, "id", id)
	return revel.MainRouter.Reverse("Base.Debug", args).URL
}

Check generated run.go file, no import for new binded arg type, but in old version, run.go has several import lines.
the line below in run.go not exist in 1.0.0

import bson "github.com/globalsign/mgo/bson"

Thanks for the example, Ill look and see if I can resolve this issue quickly

@lujiacn See PR #192 I think this will resolve your issue, if the test suite works Ill make a new release in 12 hours

Its merged on master (tag v1.0.2)

Thank you @notzippy, no issue for my project now :)