about summary refs log tree commit diff
path: root/templater
diff options
context:
space:
mode:
authorNiklas Wik <niklas.wik@nokia.com>2018-01-09T13·12+0200
committerVincent Ambo <github@tazj.in>2018-03-09T13·54+0100
commitbafb792339b5898a0e6b6219ad54b5f501d727c2 (patch)
tree1b364cfb260ddc24642c64ad0e17c1ac486dac58 /templater
parent850fdcf3e0270db885f661ae59225db92143c3f2 (diff)
feat(templater): Added support for file include
Adds a 'fileContent' template function to insert the literal contents
of a file specified in the template.

Signed-off-by: Niklas Wik <niklas.wik@nokia.com>
Diffstat (limited to 'templater')
-rw-r--r--templater/fromfile.go24
-rw-r--r--templater/templater.go1
2 files changed, 25 insertions, 0 deletions
diff --git a/templater/fromfile.go b/templater/fromfile.go
new file mode 100644
index 000000000000..f4f1e79cbfba
--- /dev/null
+++ b/templater/fromfile.go
@@ -0,0 +1,24 @@
+// Copyright (C) 2017  Niklas Wik <niklas.wik@nokia.com>
+//
+// This file is part of Kontemplate.
+//
+// Kontemplate is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+package templater
+
+import (
+	"io/ioutil"
+)
+
+//GetFromFile returns file content as string
+func GetFromFile(file string) (string, error) {
+
+	data, err := ioutil.ReadFile(file)
+	if err != nil {
+		return "", err
+	}
+	return string(data), nil
+}
diff --git a/templater/templater.go b/templater/templater.go
index 7fb85e8b235f..5bdb2f2e3bb1 100644
--- a/templater/templater.go
+++ b/templater/templater.go
@@ -193,6 +193,7 @@ func templateFuncs() template.FuncMap {
 	}
 	m["passLookup"] = GetFromPass
 	m["lookupIPAddr"] = GetIPsFromDNS
+	m["fileContent"] = GetFromFile
 
 	return m
 }