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

StaticEmbeddedHandler Question #784

Closed
jkuri opened this Issue Oct 12, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@jkuri

jkuri commented Oct 12, 2017

Hi.
First, @kataras thank you for this nice framework, I think its amazing. Coming from Node.JS and having pretty much same syntax as Express is helping me alot of learning go itself and I already making some apps in two days :)

I have question about this line:

app.RegisterView(iris.HTML("../../dist", ".html").Binary(Asset, AssetNames))

it worked yesterday already on some other project of mine, but today I am getting

src/api/main.go:45:59: undefined: Asset
src/api/main.go:45:66: undefined: AssetNames

and having underlined this line with red in VSCode.
sorry if this is a question thats to obvious, but cannot get it working right now.
Thank you.

@jkuri

This comment has been minimized.

Show comment
Hide comment
@jkuri

jkuri Oct 12, 2017

I noticed if I move main.go to the root and change path to

app.RegisterView(iris.HTML("./dist", ".html").Binary(Asset, AssetNames))

then it works. Is this a bug?

jkuri commented Oct 12, 2017

I noticed if I move main.go to the root and change path to

app.RegisterView(iris.HTML("./dist", ".html").Binary(Asset, AssetNames))

then it works. Is this a bug?

@kataras

This comment has been minimized.

Show comment
Hide comment
@kataras

kataras Oct 12, 2017

Owner

Hello @jkuri

Thanks for your nice words about the framework, I really appreciate it, I've worked thousands of hours over the last 2 years for this result.

The title is not correct, StaticEmbeddedHandler is for serving static files like .css, .js .zip and so on, your question is about embedded views (this is a different feature).

About your issue, it's very easy to solve:

  1. run go build and execute ./yourapp instead of go run main.go when having more than one files in package main, as the examples says: https://github.com/kataras/iris/blob/master/_examples/view/embedding-templates-into-app/main.go#L18. This fixes the compile error: src/api/main.go:45:59: undefined: Asset this is a general Go thing:)

  2. You don't have to move the main.go, go to your parent folder that your dist is and run go-bindata ./dist/... , copy the bindata.go file near to your main.go and use the iris.HTML("./dist", ...) as you did in your second comment, that's the correct and simpler way, it's not a bug, this is how Go works, it can't link other files if you ran only main.go

I made it to recognize the "../../" paths inside the HTML engine but it is not really necessary so I will comment that on the commit I'll push soon but in order that to worked you had to run go-bindata ../../dist/... from your main.go file but in your example you didn't run that, see the above 2. answer.

The problems were two 1) you didn't compile the bindata.go file so the main.go file couldn't find its Asset and AssetNames functions, this is a Go thing, at general not iris-specific. and 2) that you tried to act the embedded files as normal files, and lookup them via ../../dist in the same time you ran the go-bindata targeted to ./dist.

Thanks!!

Owner

kataras commented Oct 12, 2017

Hello @jkuri

Thanks for your nice words about the framework, I really appreciate it, I've worked thousands of hours over the last 2 years for this result.

The title is not correct, StaticEmbeddedHandler is for serving static files like .css, .js .zip and so on, your question is about embedded views (this is a different feature).

About your issue, it's very easy to solve:

  1. run go build and execute ./yourapp instead of go run main.go when having more than one files in package main, as the examples says: https://github.com/kataras/iris/blob/master/_examples/view/embedding-templates-into-app/main.go#L18. This fixes the compile error: src/api/main.go:45:59: undefined: Asset this is a general Go thing:)

  2. You don't have to move the main.go, go to your parent folder that your dist is and run go-bindata ./dist/... , copy the bindata.go file near to your main.go and use the iris.HTML("./dist", ...) as you did in your second comment, that's the correct and simpler way, it's not a bug, this is how Go works, it can't link other files if you ran only main.go

I made it to recognize the "../../" paths inside the HTML engine but it is not really necessary so I will comment that on the commit I'll push soon but in order that to worked you had to run go-bindata ../../dist/... from your main.go file but in your example you didn't run that, see the above 2. answer.

The problems were two 1) you didn't compile the bindata.go file so the main.go file couldn't find its Asset and AssetNames functions, this is a Go thing, at general not iris-specific. and 2) that you tried to act the embedded files as normal files, and lookup them via ../../dist in the same time you ran the go-bindata targeted to ./dist.

Thanks!!

@jkuri

This comment has been minimized.

Show comment
Hide comment
@jkuri

jkuri Oct 13, 2017

@kataras,

thanks for your extensive answer. I have frontend SPA application that is compiled into ./dist and includes index.html and other assets as well. Your answer really helped me understand where Asset and AssetNames come from (bindata.go). I made bash script which after bindata.go is generated copies that file where I have main.go, then building the app worked right away.
In short, what I needed to do is just copy the bindata.go into ./src/api and it worked 👍

About the framework, I really appreciate your work on this framework, I think is the best one from all go web frameworks, at least for what I could find. Hope you will continoue with the good work.

Closing this issue as resolved. 👍

Cheers, Jan

jkuri commented Oct 13, 2017

@kataras,

thanks for your extensive answer. I have frontend SPA application that is compiled into ./dist and includes index.html and other assets as well. Your answer really helped me understand where Asset and AssetNames come from (bindata.go). I made bash script which after bindata.go is generated copies that file where I have main.go, then building the app worked right away.
In short, what I needed to do is just copy the bindata.go into ./src/api and it worked 👍

About the framework, I really appreciate your work on this framework, I think is the best one from all go web frameworks, at least for what I could find. Hope you will continoue with the good work.

Closing this issue as resolved. 👍

Cheers, Jan

@jkuri jkuri closed this Oct 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment