Skip to content
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

[BUG] jet.View - urlpath error (also maybe update dep) #1438

Closed
Dexus opened this issue Jan 31, 2020 · 1 comment
Closed

[BUG] jet.View - urlpath error (also maybe update dep) #1438

Dexus opened this issue Jan 31, 2020 · 1 comment

Comments

@Dexus
Copy link

Dexus commented Jan 31, 2020

Describe the bug

[HTTP Server] http: panic serving [::1]:35074: interface conversion: interface {} is func(jet.Arguments) reflect.Value, not jet.Func

To Reproduce

Steps to reproduce the behavior:
iris: v12.1.5
make jet.View and use "urlpath" like {{urlpath("pathname")}} Example (https://github.com/kataras/iris/blob/master/_examples/routing/reverse/main.go)

if i use something like


	rv := router.NewRoutePathReverser(app)

	tmpl.AddFunc("urlpath2", func(a view.JetArguments) reflect.Value {
		a.RequireNumOfArguments("urlpath2", 1, -1)
		var mapper []interface{}
		var i int
		for i = 1; i < a.NumOfArguments(); i++ {
			mapper = append(mapper, a.Get(i).String())
		}

		myrouteRequestPath := rv.Path(a.Get(0).String(), mapper...)
		return reflect.ValueOf(myrouteRequestPath)
	})

it works more or less with {{ urlpath2("countriesDelete","1","2345") }} but it don't work with uint/int etc currently.

Expected behavior

return the correct urlpath for the route

additional:
maybe an example with routes with placeholders like /path/to/:id to set the named placeholders

also a new v3 of jet is available.

@kataras
Copy link
Owner

kataras commented Feb 5, 2020

Hello @Dexus,

You don't need to add your own url path function, the issue was just a wrapper around jet.Func.

Note that the /path/to/{id:int} -> ctx.Params().GetIntDefault("id", 0) works but you have to pass it as string argument in the {{urlpath("my-route", "42")}}

I also updated jet to the latest v3.0.0 which fixes some issues it had in the past (although, Iris had fixes about those by its side, those JetRanger "hacks" are removed from our code base as well).

Update to v12.1.6: go get -u github.com/kataras/iris/[email protected]

Thanks for the report!

@kataras kataras closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants