iris
iris copied to clipboard
Load templates from S3
Is your feature request related to a problem? Please describe. As far as I understand there are two ways of getting templates works:
- put templates at the same location near executable as they were near main.go
- pack all templates into an executable with go-bindata
Describe the solution you'd like I would like to use S3 storage for templates
Describe alternatives you've considered
It seems that locales are able to load from function, e.g. LoadAssets
, but not a templates
Additional context I don't think it's a good idea to have a big executable with all of my HTML templates (email templates - there are a lot) Also, don't like the idea to carry along the HTML directory.
So, I've been able to make HTMLEngine
work with S3
Actually the issue with view.HTMLEngine
, Load()
method, that is able to load templates only from the filesystem (virtual or actual)
I've passed my own FileGetter
interface:
type FileGetter interface {
GetFileContent(path string) ([]byte, error)
ListFiles() ([]string, error)
}
embedded HTMLEngine
and change Load()
method.
Also, I've implemented LocalFs and S3 structs of the FileGetter
interface
Now it can get templates whatever you want.
I could make these changes to get the ability to load templates from anywhere, but it will have BC breaks.
The FileGetter
should be added to the HTMLEngine
constructor, or to Load()
function of interface.
Maybe that change is applicable to the Iris contrib repo. @kataras let me know what do you think.
P.S.: another way - is to make a new function, same as LoadAssets
, let's call it LoadTemplates
- in such a way we can take care of BC
something like this would be useful for my use case where our users would like to dynamically provide templates which can change sporadically
I will wait comment from @kataras Will be happy to make that changes to iris
Hello @spolischook and @gf3,
If the addition requires the amazon s3 go dependency, then it's better to live as its own repository that will work as an "extension" of the HTMLEngine. I have invited you to the https://github.com/iris-contrib/s3, that repository will contain everything amazon s3-related and Iris. You can initialize the root project and then create a sub-package of 'view/html' and put your work there. Please let me know your thoughts.
@kataras sorry for late response. I'm ukrainian and I have a lot of issues to resolve right now, so this one is not in a priority. I'll look at it a bit later.
Actually, what I remember, we can have LoadTemplates
method, same as LoadAssets
and the get templates from S3 (actualy from any storega, e.g. database) will be few lines of user code
Yes @spolischook but Aws S3 is a heavy dependency we really don't need in the main repository, that's why we must put it on iris-contrib/s3. And about Ukraine I am really sorry for what happens there - stay strong! I have a lot of ukrainian friends!
Zero dependency. It just gave me ability to inject my own AwsS3 io.Reader
Hello @spolischook, how are you?
You can customize how directories are loaded to view engine by: iris.Patches().Context().ResolveFS
method. Currently we support: string
, fs.FS
, http.FileSystem
and embed.FS
(code here). The fs.FS
type is useful on your case, because you can use s3-to-fs package to convert your amazon s3 objects to go fs.FS
value.
If you found other solution, could you please share the code on PR or here or the repository we've created for S3?