gomplate

一个灵活的模板渲染命令行工具。支持大量的本地和远程数据源。「A flexible commandline tool for template rendering. Supports lots of local and remote datasources.」

Github stars Tracking Chart

gomplate logo

阅读 docs.gomplate.ca 上的文档,在 Gophers Slack 上的 #gomplate 频道 与开发者和社区聊天。

gomplate 是一个模板渲染器,它支持越来越多的数据源,如:JSON(包括 EJSON -- 加密的 JSON)、YAML、AWS EC2 元数据、BoltDBHashicorp ConsulHashicorp Vault 秘密。

快来 Gophers Slack 上的 #gomplate 频道GitHub 讨论区与开发者和社区聊天吧!

以下是一些关于 gomplate 如何工作的实战案例:

$ # 最基本的,gomplate 可以和环境变量一起使用...
$ echo 'Hello, {{ .Env.USER }}' | gomplate
Hello, hairyhenderson
$ # 但这有点无聊。gomplate 也有很多功能来做有用的事情
$ gomplate -i 'the answer is: {{ mul 6 7 }}'
the answer is: 42
$ # 而且,由于 gomplate 使用了 Go 的模板语法,你可以做一些有趣的事情,比如:
$ gomplate -i '{{ range seq 5 1 }}{{ . }} {{ if eq . 1 }}{{ "blastoff" | toUpper }}{{ end }}{{ end }}'
5 4 3 2 1 BLASTOFF
$ # 当你使用数据资源时,真正的乐趣就来了!
$ cat ./config.yaml
foo:
  bar:
    baz: qux
$ gomplate -d config=./config.yaml -i 'the value we want is: {{ (datasource "config").foo.bar.baz }}'
the value we want is: qux
$ # 数据源是由 URL 定义的,gomplate 并不只限于基于文件的数据源:
$ gomplate -d ip=https://ipinfo.io -i 'country code: {{ (ds "ip").country }}'
country code: CA
$ # 标准输入也可以作为数据源使用:
$ echo '{"cities":["London", "Johannesburg", "Windhoek"]}' | gomplate -d city=stdin:///in.json -i '{{ range (ds "city").cities }}{{.}}, {{end}}'
London, Johannesburg, Windhoek, 
$ # 而这里的东西更复杂一点:
$ export CITIES='city: [London, Johannesburg, Windhoek]'
$ cat in.tmpl
{{ range $i, $city := (ds "cities").city -}}
{{ add 1 $i }}: {{ include "weather" (print $city "?0") }}
{{ end }}
$ gomplate -d 'cities=env:///CITIES?type=application/yaml' -d 'weather=https://wttr.in/?0' -H 'weather=User-Agent: curl' -f in.tmpl
1: Weather report: London
    \  /       Partly cloudy
  _ /"".-.     4-7 °C
    \_(   ).   ↑ 20 km/h
    /(___(__)  10 km
               0.0 mm
2: Weather report: Johannesburg
    \  /       Partly cloudy
  _ /"".-.     15 °C
    \_(   ).   ↘ 0 km/h
    /(___(__)  10 km
               2.2 mm
3: Weather report: Windhoek
    \  /       Partly cloudy
  _ /"".-.     20 °C
    \_(   ).   ↑ 6 km/h
    /(___(__)  20 km
               0.0 mm

阅读 docs.gomplate.ca 上的文档,并加入 GitHub 讨论

问题跟踪器中报告任何发现的错误。

许可证

MIT 许可证

版权所有 (c) 2016-2021 Dave Henderson


Overview

Name With Ownerhairyhenderson/gomplate
Primary LanguageGo
Program languageGo (Language Count: 3)
PlatformLinux, Mac, Windows, Docker
License:MIT License
Release Count65
Last Release Namev4.0.0-pre-2 (Posted on 2024-01-23 14:29:49)
First Release Namev0.0.1 (Posted on )
Created At2016-01-23 14:36:27
Pushed At2024-04-20 06:33:49
Last Commit At
Stargazers Count2.5k
Watchers Count17
Fork Count175
Commits Count2.3k
Has Issues Enabled
Issues Count372
Issue Open Count16
Pull Requests Count1205
Pull Requests Open Count9
Pull Requests Close Count376
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Read the docs at [docs.gomplate.ca][docs-url], chat with developers and community in the [#gomplate channel][] on [Gophers Slack][]

[![Build Status][circleci-image]][circleci-url]
[![Build][gh-actions-image]][gh-actions-url]
[![Go Report Card][reportcard-image]][reportcard-url]
[![Codebeat Status][codebeat-image]][codebeat-url]
[![Coverage][gocover-image]][gocover-url]
[![Total Downloads][gh-downloads-image]][gh-downloads-url]
[![CII Best Practices][cii-bp-image]][cii-bp-url]

[![hairyhenderson/gomplate on DockerHub][dockerhub-image]][dockerhub-url]
[![DockerHub Stars][dockerhub-stars-image]][dockerhub-url]
[![DockerHub Pulls][dockerhub-pulls-image]][dockerhub-url]
[![DockerHub Image Layers][microbadger-layers-image]][microbadger-url]
[![DockerHub Latest Version ][microbadger-version-image]][microbadger-url]
[![DockerHub Latest Commit][microbadger-commit-image]][microbadger-url]

[![Install Docs][install-docs-image]][install-docs-url]
[![Slack][slack-image]][slack-url]

gomplate is a template renderer which supports a growing list of datasources,
such as: JSON (including EJSON - encrypted JSON), YAML, AWS EC2 metadata, BoltDB,
Hashicorp Consul and Hashicorp Vault secrets.

Here are some hands-on examples of how gomplate works:

$ # at its most basic, gomplate can be used with environment variables...
$ echo 'Hello, {{ .Env.USER }}'
To the top