2014-10-12 20:02:53 +00:00
|
|
|
package script
|
|
|
|
|
|
|
|
import (
|
2014-11-11 17:26:15 +00:00
|
|
|
"sort"
|
2014-10-12 20:02:53 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Inject(script string, params map[string]string) string {
|
|
|
|
if params == nil {
|
|
|
|
return script
|
|
|
|
}
|
2014-11-11 17:26:15 +00:00
|
|
|
keys := []string{}
|
|
|
|
for k, _ := range params {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
sort.Sort(sort.Reverse(sort.StringSlice(keys)))
|
2014-10-12 20:02:53 +00:00
|
|
|
injected := script
|
2014-11-11 17:26:15 +00:00
|
|
|
for _, k := range keys {
|
|
|
|
v := params[k]
|
2014-10-12 20:02:53 +00:00
|
|
|
injected = strings.Replace(injected, "$$"+k, v, -1)
|
|
|
|
}
|
|
|
|
return injected
|
|
|
|
}
|