Giter Site home page Giter Site logo

templo's Introduction

go template with csv

templo -t data/fwrules.bicep.tmpl -c data/fwrules.csv

param mysql object // external resources


// https://docs.microsoft.com/ja-jp/azure/templates/microsoft.dbformysql/2017-12-01/servers/firewallrules

resource fw0_resource 'Microsoft.DBforMySQL/servers/firewallRules@2017-12-01' = {
  name: '${mysql.name}/apple'
  properties: {
    startIpAddress: '192.168.12.1/32'
    endIpAddress: '192.168.12.1/32'
  }
}

resource fw1_resource 'Microsoft.DBforMySQL/servers/firewallRules@2017-12-01' = {
  name: '${mysql.name}/orange'
  properties: {
    startIpAddress: '192.168.12.2/32'
    endIpAddress: '192.168.12.2/32'
  }
}

Run in docker

$ docker run --rm -i -v ${PWD}:/app takekazuomi/templo -t data/fwrules.bicep.tmpl -c data/fwrules.csv

0.1.0 new custom function

templo implemented three custom functions split, barray, barrayq to decompose strings and convert them to bicep arrays. Separate the string with split and make it an array of strings. barray/barrayq takes a string or an array of strings and converts it to bicep array syntax.

  • split string sep -> []string
    • split string to string array
  • barray []string -> string
    • string array to bicep array
  • barrayq []string -> string
    • string array to bicep array with quote

go template Functions

barray sample

A template is the go template syntax. The example below uses the pipeline syntax.

{{- range $i, $v := .env -}}
bicep array: {{ .f1 | barray }}
bicep array with quote: {{ .f1 | barrayq }}
bicep array with sep: {{ barray .f2 "|" }}
{{- end }}
f1,f2
"1 2", "AB|CD"
$ docker run --rm -i -v ${PWD}:/app takekazuomi/templo -t data/barray.tmpl -c data/barray.csv
bicep array: [1, 2]
bicep array with quote: ['1', '2']
bicep array with sep: [AB, CD]

ChangeLog

  • 0.1.1
    • fix pipeline args bug
    • make more small container image

templo's People

Contributors

takekazuomi avatar

Watchers

 avatar James Cloos avatar

templo's Issues

importCsvにて入力ファイル名がstdoutの1行目に出力される

多分デバッグ用途と思われますが、出力結果の1行目にファイル名が出力されており、その後の出力された結果(json)の利用が不便となっています。

修正案を以下に示します。

diff --git a/templo.go b/templo.go
index eb8142c..c7f2996 100644
--- a/templo.go
+++ b/templo.go
@@ -2,7 +2,6 @@ package main
 
 import (
        "encoding/csv"
-       "fmt"
        "io"
        "log"
        "os"
@@ -12,8 +11,6 @@ import (
 )
 
 func importCsv(name string) []map[string]string {
-       fmt.Println(name)
-
        file, err := os.Open(name)
        if err != nil {
                log.Fatal(err)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.