From 84f5c56dca895bf00c7efbd1df049fd784159591 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 4 Oct 2024 08:10:56 +0200 Subject: [PATCH] chore: return to sprig (#16482) --- cmd/configure/configure.go | 4 ++-- cmd/dump.go | 4 ++-- cmd/eebus.go | 4 ++-- cmd/tools/decorate.go | 4 ++-- go.mod | 7 +++++-- go.sum | 14 ++++++++++---- push/hub.go | 6 +++--- util/format.go | 4 ++-- util/templates/documentation.go | 4 ++-- util/templates/template.go | 4 ++-- util/templates/utils.go | 4 ++-- 11 files changed, 34 insertions(+), 25 deletions(-) diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index e0c4f4049..f0ffdb87d 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -5,8 +5,8 @@ import ( _ "embed" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/util/templates" - "github.com/go-sprout/sprout/sprigin" ) type device struct { @@ -116,7 +116,7 @@ var configTmpl string // RenderConfiguration creates a yaml configuration func (c *Configure) RenderConfiguration() ([]byte, error) { - tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(configTmpl) + tmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(configTmpl) if err != nil { panic(err) } diff --git a/cmd/dump.go b/cmd/dump.go index 665243f1d..bc0daf5cc 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -8,10 +8,10 @@ import ( "path/filepath" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/core" "github.com/evcc-io/evcc/server" "github.com/evcc-io/evcc/util/config" - "github.com/go-sprout/sprout/sprigin" "github.com/spf13/cobra" ) @@ -70,7 +70,7 @@ func runDump(cmd *cobra.Command, args []string) { tmpl := template.Must( template.New("dump"). - Funcs(sprigin.FuncMap()). + Funcs(sprig.FuncMap()). Parse(dumpTmpl)) out := new(bytes.Buffer) diff --git a/cmd/eebus.go b/cmd/eebus.go index 1d34618e1..7a60723a9 100644 --- a/cmd/eebus.go +++ b/cmd/eebus.go @@ -4,8 +4,8 @@ import ( "os" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/server/eebus" - "github.com/go-sprout/sprout/sprigin" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ func generateEEBUSCert() { log.FATAL.Fatal("could not process generated certificate", err) } - t := template.Must(template.New("out").Funcs(sprigin.FuncMap()).Parse(tmpl)) + t := template.Must(template.New("out").Funcs(sprig.FuncMap()).Parse(tmpl)) if err := t.Execute(os.Stdout, map[string]interface{}{ "public": pubKey, "private": privKey, diff --git a/cmd/tools/decorate.go b/cmd/tools/decorate.go index 730943df0..98c8cd662 100644 --- a/cmd/tools/decorate.go +++ b/cmd/tools/decorate.go @@ -12,8 +12,8 @@ import ( "strings" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/api" - "github.com/go-sprout/sprout/sprigin" combinations "github.com/mxschmitt/golang-combinations" "github.com/samber/lo" "github.com/spf13/pflag" @@ -74,7 +74,7 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic types := make(map[string]typeStruct, len(dynamicTypes)) combos := make([]string, 0) - tmpl, err := template.New("gen").Funcs(sprigin.FuncMap()).Funcs(template.FuncMap{ + tmpl, err := template.New("gen").Funcs(sprig.FuncMap()).Funcs(template.FuncMap{ // contains checks if slice contains string "contains": slices.Contains[[]string, string], // ordered returns a slice of typeStructs ordered by dynamicType diff --git a/go.mod b/go.mod index 940307754..80fe73e6f 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( dario.cat/mergo v1.0.1 github.com/AlecAivazis/survey/v2 v2.3.7 github.com/BurntSushi/toml v1.4.0 + github.com/Masterminds/sprig/v3 v3.3.0 github.com/PuerkitoBio/goquery v1.10.0 github.com/andig/go-powerwall v0.2.1-0.20230808194509-dd70cdb6e140 github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b @@ -34,7 +35,6 @@ require ( github.com/glebarez/sqlite v1.11.0 github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1 github.com/go-playground/validator/v10 v10.22.1 - github.com/go-sprout/sprout v0.6.0 github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 github.com/go-viper/mapstructure/v2 v2.2.1 github.com/godbus/dbus/v5 v5.1.0 @@ -109,7 +109,8 @@ require ( ) require ( - github.com/Masterminds/semver/v3 v3.2.1 // indirect + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.3.0 // indirect github.com/ahmetb/go-linq/v3 v3.2.0 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect @@ -140,6 +141,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/grid-x/serial v0.0.0-20211107191517-583c7356b3aa // indirect + github.com/huandu/xstrings v1.5.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect github.com/insomniacslk/xjson v0.0.0-20240821125711-1236daaf6808 // indirect @@ -177,6 +179,7 @@ require ( github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect + github.com/shopspring/decimal v1.4.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127 // indirect github.com/spf13/afero v1.11.0 // indirect diff --git a/go.sum b/go.sum index 3cd74d31e..01c7b4bc7 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= -github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= +github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs= +github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4= @@ -200,8 +204,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/go-sprout/sprout v0.6.0 h1:YIcSYNKjFFMORcjts5/N6S0toNcJiX1cbXi619qVjA0= -github.com/go-sprout/sprout v0.6.0/go.mod h1:P6ETppcGn1BR0HZ8r+660aP2hJH7xiamIGiWjA+AE4o= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -316,6 +318,8 @@ github.com/hasura/go-graphql-client v0.13.0/go.mod h1:17qYcHgGSensF/wMAHKUhtMYaR github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= +github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -587,6 +591,8 @@ github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/simonvetter/modbus v1.6.0 h1:RDHJevtc7LDIVoHAbhDun8fy+QwnGe+ZU+sLm9ZZzjc= github.com/simonvetter/modbus v1.6.0/go.mod h1:hh90ZaTaPLcK2REj6/fpTbiV0J6S7GWmd8q+GVRObPw= diff --git a/push/hub.go b/push/hub.go index f08ec87c6..b5826c19e 100644 --- a/push/hub.go +++ b/push/hub.go @@ -5,9 +5,9 @@ import ( "strings" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/evcc-io/evcc/core/vehicle" "github.com/evcc-io/evcc/util" - "github.com/go-sprout/sprout/sprigin" ) // Event is a notification event @@ -38,10 +38,10 @@ type Hub struct { func NewHub(cc map[string]EventTemplateConfig, vv Vehicles, cache *util.Cache) (*Hub, error) { // instantiate all event templates for k, v := range cc { - if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Title); err != nil { + if _, err := template.New("out").Funcs(sprig.FuncMap()).Parse(v.Title); err != nil { return nil, fmt.Errorf("invalid event title: %s (%w)", k, err) } - if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Msg); err != nil { + if _, err := template.New("out").Funcs(sprig.FuncMap()).Parse(v.Msg); err != nil { return nil, fmt.Errorf("invalid event message: %s (%w)", k, err) } } diff --git a/util/format.go b/util/format.go index 6ff27c62e..17f521c57 100644 --- a/util/format.go +++ b/util/format.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/go-sprout/sprout/sprigin" + "github.com/Masterminds/sprig/v3" "github.com/samber/lo" ) @@ -55,7 +55,7 @@ func FormatValue(format string, val interface{}) string { func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) { // Enhanced golang template logic tpl, err := template.New("base"). - Funcs(sprigin.FuncMap()). + Funcs(sprig.FuncMap()). Funcs(map[string]any{ "timeRound": timeRound, }).Parse(s) diff --git a/util/templates/documentation.go b/util/templates/documentation.go index 17d016c55..68a8e85c4 100644 --- a/util/templates/documentation.go +++ b/util/templates/documentation.go @@ -8,7 +8,7 @@ import ( "strings" "text/template" - "github.com/go-sprout/sprout/sprigin" + "github.com/Masterminds/sprig/v3" ) //go:embed documentation.tpl @@ -45,7 +45,7 @@ func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, er var modbusRender string if modbusChoices := t.ModbusChoices(); len(modbusChoices) > 0 { if i, _ := t.ParamByName(ParamModbus); i > -1 { - modbusTmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(documentationModbusTmpl) + modbusTmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(documentationModbusTmpl) if err != nil { panic(err) } diff --git a/util/templates/template.go b/util/templates/template.go index 9077b6b93..649d0e711 100644 --- a/util/templates/template.go +++ b/util/templates/template.go @@ -9,7 +9,7 @@ import ( "strings" "text/template" - "github.com/go-sprout/sprout/sprigin" + "github.com/Masterminds/sprig/v3" ) // Template describes is a proxy device for use with cli and automated testing @@ -207,7 +207,7 @@ var proxyTmpl string // RenderProxyWithValues renders the proxy template func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang string) ([]byte, error) { - tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(proxyTmpl) + tmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(proxyTmpl) if err != nil { panic(err) } diff --git a/util/templates/utils.go b/util/templates/utils.go index 1a83a6a13..b63660806 100644 --- a/util/templates/utils.go +++ b/util/templates/utils.go @@ -7,7 +7,7 @@ import ( "strings" "text/template" - "github.com/go-sprout/sprout/sprigin" + "github.com/Masterminds/sprig/v3" "gopkg.in/yaml.v3" ) @@ -59,5 +59,5 @@ func FuncMap(tmpl *template.Template) *template.Template { "urlEncode": url.QueryEscape, } - return tmpl.Funcs(sprigin.FuncMap()).Funcs(funcMap) + return tmpl.Funcs(sprig.FuncMap()).Funcs(funcMap) }