From bafb792339b5898a0e6b6219ad54b5f501d727c2 Mon Sep 17 00:00:00 2001 From: Niklas Wik Date: Tue, 9 Jan 2018 15:12:50 +0200 Subject: 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 --- templater/fromfile.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 templater/fromfile.go (limited to 'templater/fromfile.go') 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 +// +// 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 +} -- cgit 1.4.1