Template path issue
Documentation for the iris project can be found at https://github.com/kataras/iris#-learn.
go version go1.8.3 windows/amd64
File structure GOPATH |-src |---|-myProj |---|----|-projBase |---|----|-----|-views |---|----|-----|----|-index.html |---|----|-----|-main.go
When run go
go run GOPATH/src/myProj/projBase/main.go
It run properly but it cant get the views html
So i change directory into projBase, then the html is render properly
I found a solution which is not so practical to do so.
_, goDir, _, ok := runtime.Caller(0)
if !ok {
panic("No caller information")
}
appDir := path.Dir(goDir)
app.RegisterView(iris.HTML(appDir+"/views", ".html").Reload(true))
With the code in main.go and below command, im able to get the views html
go run GOPATH/src/myProj/projBase/main.go
There is no problem with the template path, it works on examples and on every website we have built with Iris. Templates are loaded based on the root path you pass at the iris.HTML(...) function.
Actually your code is not the solution you're looking for, if you want to have the templates within your go application you have to "bundle" them using the go-bindata library + .Binary(Asset, AssetNames), this way your app will render the templates even faster and you will never have any problem with your assets, with Iris you can do it by using a single function. An example of this can be found there: https://github.com/kataras/iris/tree/master/_examples/view/embedding-templates-into-app
What if you have a website where users can upload photos? can you still use the bind method for resources?
You mean dynamic files, no I suggest you use the binary method for templates, favicon and any other static assets, for the rest of the files use the Context's methods for serving files that are being saved to the disk by the user.
I understand, but which context methods are you referring to? I only used the static file server until now.