-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: all files about templates and kubectl
Signed-off-by: Bird <aflybird0@gmail.com>
- Loading branch information
Showing
34 changed files
with
507 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,19 @@ | ||
package configmanager | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"regexp" | ||
"github.com/devstream-io/devstream/pkg/util/template" | ||
) | ||
|
||
// this is because our variables' syntax is [[ varName ]] | ||
// while Go's template is [[ .varName ]] | ||
func addDotForVariablesInConfig(s string) string { | ||
// regex := `\[\[\s*(.*)\s*\]\]` | ||
// r := regexp.MustCompile(regex) | ||
// return r.ReplaceAllString(s, "[[ .$1 ]]") | ||
regex := `\[\[\s*` | ||
r := regexp.MustCompile(regex) | ||
return r.ReplaceAllString(s, "[[ .") | ||
} | ||
|
||
func renderConfigWithVariables(fileContent string, variables map[string]interface{}) ([]byte, error) { | ||
tpl, err := template.New("configfile").Delims("[[", "]]").Parse(fileContent) | ||
if err != nil { | ||
return nil, err | ||
} | ||
str, err := template.New(). | ||
FromContent(fileContent). | ||
AddProcessor(template.AddDotForVariablesInConfigProcessor()). | ||
DefaultRender(fileContent, variables). | ||
Render() | ||
|
||
var results bytes.Buffer | ||
err = tpl.Execute(&results, variables) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return results.Bytes(), err | ||
return []byte(str), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
package java | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"html/template" | ||
|
||
"github.com/devstream-io/devstream/pkg/util/template" | ||
) | ||
|
||
//go:embed gitlabci-template.yml | ||
var gitlabCITemplate string | ||
|
||
// Render gitlab-ci.yml template with Options | ||
func renderTmpl(Opts *Options) (string, error) { | ||
t := template.Must(template.New("gitlabci-java").Delims("[[", "]]").Option("missingkey=error").Parse(gitlabCITemplate)) | ||
|
||
var buf bytes.Buffer | ||
err := t.Execute(&buf, Opts) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
return template.New().FromContent(gitlabCITemplate).DefaultRender("gitlabci-java", Opts).Render() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.