Skip to content

Commit

Permalink
Handle filenames with filepath package (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
avorima authored Feb 23, 2023
1 parent 0263444 commit 494e167
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
3 changes: 1 addition & 2 deletions grafana/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grafana

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -27,7 +26,7 @@ func writeToFile(directory string, content []byte, name string, tag string) erro
return err
}
}
fileName = fmt.Sprintf("%s/%s.json", path, name)
fileName = filepath.Join(path, name+".json")
dashboardFile, err = os.Create(fileName)
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions grafana/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package grafana
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"path/filepath"

"github.com/grafana-tools/sdk"
)
Expand Down Expand Up @@ -75,8 +74,8 @@ func PushDashboard(grafanaURL string, apiKey string, directory string, folderId
return err
}
for _, file := range filesInDir {
if strings.HasSuffix(file.Name(), ".json") {
if rawBoard, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", directory, file.Name())); err != nil {
if filepath.Ext(file.Name()) == ".json" {
if rawBoard, err = ioutil.ReadFile(filepath.Join(directory, file.Name())); err != nil {
log.Println(err)
ExecutionErrorHappened = true
continue
Expand Down
7 changes: 3 additions & 4 deletions grafana/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package grafana
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"path/filepath"

"github.com/grafana-tools/sdk"
)
Expand Down Expand Up @@ -57,8 +56,8 @@ func PushDatasources(grafanaURL string, apiKey string, directory string) error {
return err
}
for _, file := range filesInDir {
if strings.HasSuffix(file.Name(), ".json") {
if rawFolder, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", directory, file.Name())); err != nil {
if filepath.Ext(file.Name()) == ".json" {
if rawFolder, err = ioutil.ReadFile(filepath.Join(directory, file.Name())); err != nil {
log.Println(err)
continue
}
Expand Down
7 changes: 3 additions & 4 deletions grafana/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package grafana
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"path/filepath"

"github.com/grafana-tools/sdk"
)
Expand Down Expand Up @@ -57,8 +56,8 @@ func PushFolder(grafanaURL string, apiKey string, directory string) error {
return err
}
for _, file := range filesInDir {
if strings.HasSuffix(file.Name(), ".json") {
if rawFolder, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", directory, file.Name())); err != nil {
if filepath.Ext(file.Name()) == ".json" {
if rawFolder, err = ioutil.ReadFile(filepath.Join(directory, file.Name())); err != nil {
log.Println(err)
ExecutionErrorHappened = true
continue
Expand Down
7 changes: 3 additions & 4 deletions grafana/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package grafana
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"path/filepath"

"github.com/grafana-tools/sdk"
)
Expand Down Expand Up @@ -56,8 +55,8 @@ func PushNotification(grafanaURL string, apiKey string, directory string) error
return err
}
for _, file := range filesInDir {
if strings.HasSuffix(file.Name(), ".json") {
if rawFolder, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", directory, file.Name())); err != nil {
if filepath.Ext(file.Name()) == ".json" {
if rawFolder, err = ioutil.ReadFile(filepath.Join(directory, file.Name())); err != nil {
log.Println(err)
ExecutionErrorHappened = true
continue
Expand Down

0 comments on commit 494e167

Please sign in to comment.