Merge pull request #23 from studiokaiji/fix-file-path-error

Fix file path error
This commit is contained in:
kaiji
2023-08-25 10:25:08 +09:00
committed by GitHub
3 changed files with 30 additions and 4 deletions

View File

@@ -57,7 +57,17 @@ func GetPublic() (string, error) {
}
func GetSecret() (string, error) {
secretBytes, err := os.ReadFile(PATH)
dir, err := paths.GetSettingsDirectory()
if err != nil {
return "", err
}
filePath := filepath.Join(dir, PATH)
if err != nil {
return "", err
}
secretBytes, err := os.ReadFile(filePath)
if err != nil {
return "", errors.New("Could not read secret")
}

View File

@@ -14,6 +14,8 @@ func GetSettingsDirectory() (string, error) {
}
dirPath := filepath.Join(homeDir, BaseDirName)
_, err = os.Stat(dirPath)
if os.IsNotExist(err) {
// ディレクトリが存在しない場合に作成
err = os.Mkdir(dirPath, 0700)
@@ -21,7 +23,7 @@ func GetSettingsDirectory() (string, error) {
return "", err
}
} else if err != nil {
return "", err
return "", nil
}
return dirPath, nil

View File

@@ -28,7 +28,14 @@ func AddRelay(relayURL string) error {
}
func RemoveRelay(targetURL string) error {
content, err := os.ReadFile(PATH)
dir, err := paths.GetSettingsDirectory()
if err != nil {
return err
}
filePath := filepath.Join(dir, PATH)
content, err := os.ReadFile(filePath)
if err != nil {
return err
}
@@ -49,7 +56,14 @@ func RemoveRelay(targetURL string) error {
}
func GetAllRelays() ([]string, error) {
content, err := os.ReadFile(PATH)
dir, err := paths.GetSettingsDirectory()
if err != nil {
return nil, err
}
filePath := filepath.Join(dir, PATH)
content, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}