gomplate

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

Github星跟踪图

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


概览

名称与所有者hairyhenderson/gomplate
主编程语言Go
编程语言Go (语言数: 3)
平台Linux, Mac, Windows, Docker
许可证MIT License
发布数65
最新版本名称v4.0.0-pre-2 (发布于 2024-01-23 14:29:49)
第一版名称v0.0.1 (发布于 )
创建于2016-01-23 14:36:27
推送于2024-05-04 06:56:56
最后一次提交
星数2.5k
关注者数17
派生数175
提交数2.3k
已启用问题?
问题数375
打开的问题数19
拉请求数1206
打开的拉请求数10
关闭的拉请求数378
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

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 }}'
去到顶部