gomplate

repository·main·Indexed 25 days ago

https://github.com/hairyhenderson/gomplate

A powerful template renderer that uses Go's templating syntax to inject data from various sources, including JSON, YAML, AWS EC2 metadata, Hashicorp Consul, and Hashicorp Vault. It supports a wide range of datasources via URLs, files, environment variables, and standard input, and allows for custom function extension through a plugin system.

Tokens
41.2K
Snippets
224
Records
327
Agent score
75%

What's inside gomplate

  1. Overview of gomplate

    main
    gomplate is a template renderer that supports a wide variety of datasources. It allows you to inject data from sources like JSON (including encrypted EJSON), YAML, AWS EC2 metadata, Hashicorp Consul, and Hashicorp Vault into your templates. It uses Go's templating syntax for logic and transformations.
  2. Use the filepath namespace for local filesystem paths

    main
    gomplate provides two path namespaces: path for slash-based (/) paths (like URLs) and filepath for local filesystem paths. Use the filepath namespace when dealing with paths that may involve platform-specific separators, such as Windows backslashes (\). All filepath functions are wrappers for Go's path/filepath package.
  3. Manage Template Context

    main

    The context is referenced using the . (period) character.

    • Use the with action to change the current context for a block.
    • The initial (root) context is always accessible via the $ variable, even if shadowed by range or with blocks.
    • You can populate the default context from data sources using the --context or -c flag.
  4. Use S3 as a datasource

    main

    Retrieve objects from Amazon S3 or S3-compatible storage using the s3:// scheme.

    URL Structure: s3://<bucket>/<path>?<query>

    Query Parameters:

    • region: AWS region (defaults to AWS_REGION, AWS_DEFAULT_REGION, or EC2 region).
    • endpoint: The endpoint hostname/URI (useful for Minio or local testing). Can also be set via AWS_S3_ENDPOINT.
    • s3ForcePathStyle: Set to true to force path-style access (required for some S3-compatible servers).
    • disableSSL: Set to true to disable SSL (use for testing only).
    • type: Overrides the MIME type for parsing.

    Output: The object contents, parsed based on the discovered MIME type or the type query parameter.

  5. Use `git` datasources

    main

    The git datasource provides access to files in local or remote git repositories. Remote repositories can be accessed via git, git+file, git+http, git+https, and git+ssh schemes.

    URL Structure: scheme://[userinfo@]authority//path/to/repo//path/to/file#fragment

    • The // sequence separates the repository path from the file/directory path. If // is missing, the datasource points to the repository root.
    • The #fragment specifies the branch or tag (e.g., #main or #refs/tags/v1).

    Note: For local repositories, only committed files are visible; 'dirty' or uncommitted files are ignored.

  6. Process directories with --input-dir and --output-dir

    main

    To process multiple templates in a directory recursively, use --input-dir and --output-dir. All files in the input directory are treated as templates, and the resulting files are stored in the output directory while preserving the original directory structure. The output directory is created automatically if it does not exist.

    You can filter files using --exclude and --include or a .gomplateignore file.

    # Process all files in directory "templates" with the datasource given
    # and store the files with the same directory structure in "config"
    gomplate --input-dir=templates --output-dir=config --datasource config=config.yaml