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

Directory datasource #215

Closed
zealic opened this issue Oct 22, 2017 · 4 comments
Closed

Directory datasource #215

zealic opened this issue Oct 22, 2017 · 4 comments

Comments

@zealic
Copy link
Contributor

zealic commented Oct 22, 2017

A new feature data.Directory:

Datasource will recursive scan directory files, include:

  • *.json
  • *.yaml or *.yml
  • *.toml

Example

Datasource directory

file: config/message.json

{
  "welcome": "Hello World"
}

file: config/person.yml

name: "Gomplate"

Shell code:

# Datasource need endwith slash
gomplate -d config=./config/ ...

Template:

{{ $config := (datasource "config") -}}
{{ $config.message.welcome }}, {{ $config.person.name }}!

OUTPUT:

Hello World, Gomplate!
@hairyhenderson
Copy link
Owner

@zealic Thanks for the feature request! This is indeed something I'd like to do.

A similar idea was put forward in #124, though in that one the datasource aliases were inferred based on filename, whereas I think I slightly prefer this proposed syntax.

I can start working on this soon, unless you were hoping to implement it?

@zealic
Copy link
Contributor Author

zealic commented Oct 23, 2017

I'm no plan to implement it for this time.

Thank you for your work.

I love gomplate ❤️ , it help me resolve many problems.

@hairyhenderson hairyhenderson self-assigned this Oct 23, 2017
@hairyhenderson
Copy link
Owner

@zealic you're welcome! 😀

I'll see if I can find time to work on it soon. Thanks again for the request!

@hairyhenderson
Copy link
Owner

Fleshing out this idea in my head a bit more, I think the approach of using a trailing / is probably the correct one, and I think it turns out this can apply to more than just file-based datasources.

Here's how it could work with the various supported datasources:

  • aws+smp - could use GetParameters to list parameters with a given prefix
  • boltdb - could list all keys in a given bucket
  • consul - could use get-tree
  • file - would return a directory listing (much like file.ReadDir)
  • http - n/a
  • stdin - n/a
  • vault - could use the LIST operation

It'd take some time to get here, though, and I think the natural place to start is with file. I think the big trick will be to come to a UX that's not too cumbersome to use.

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