Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
fix: marker map interface conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed May 22, 2020
1 parent 9baa761 commit 0a3eb22
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ func getNginxDirectories(filename string, m Config) (string, string) {
return pathAvailable, pathEnabled
}

func CreateOrUpdateServerBlock(filename string, content string, m Config, markers map[string]string) (string, error) {
func CreateOrUpdateServerBlock(filename string, content string, m Config, markers map[string]interface{}) (string, error) {
fullPathAvailable, _ := getNginxDirectories(filename, m)

// Replace markers in content
var re *regexp.Regexp
for key, value := range markers {
re, _ = regexp.Compile("{#\\s*" + key + "\\s*#}")
content = re.ReplaceAllString(content, value)
content = re.ReplaceAllString(content, value.(string))
}

if err := ioutil.WriteFile(fullPathAvailable, []byte(content), 0744); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions src/resource_server_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func resourceServerBlockCreate(d *schema.ResourceData, m interface{}) error {

// Create file
content := d.Get("content").(string)
fullPathAvailable, err := nginx.CreateOrUpdateServerBlock(d.Get("filename").(string), content, config, d.Get("markers").(map[string]string))
fullPathAvailable, err := nginx.CreateOrUpdateServerBlock(d.Get("filename").(string), content, config, d.Get("markers").(map[string]interface{}))
if err != nil {
return err
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func resourceServerBlockRead(d *schema.ResourceData, m interface{}) error {
func resourceServerBlockUpdate(d *schema.ResourceData, m interface{}) error {
// Content changed: replace old file content
if d.HasChange("content") || d.HasChange("variables") {
_, err := nginx.CreateOrUpdateServerBlock(d.Id(), d.Get("content").(string), m.(nginx.Config), d.Get("markers").(map[string]string))
_, err := nginx.CreateOrUpdateServerBlock(d.Id(), d.Get("content").(string), m.(nginx.Config), d.Get("markers").(map[string]interface{}))
if err != nil {
return err
}
Expand Down

0 comments on commit 0a3eb22

Please sign in to comment.