-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df6afec
commit bc40c52
Showing
9 changed files
with
171 additions
and
28 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,2 +1,4 @@ | ||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= | ||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= |
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,3 +1,4 @@ | ||
package constants | ||
|
||
const Filename = "pecker.conf" | ||
const ConfigFilename = "pecker.conf" | ||
const CurrentIpFilename = "current_ip.conf" |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"woodpecker/src/constants" | ||
) | ||
|
||
func GetAppPath() (string, error) { | ||
var dir string | ||
|
||
switch runtime.GOOS { | ||
case "windows": | ||
appData := os.Getenv("APPDATA") | ||
dir = filepath.Join(appData, "woodpecker") | ||
case "linux": | ||
home := os.Getenv("HOME") | ||
dir = filepath.Join(home, ".local", "share", "woodpecker") | ||
} | ||
|
||
err := os.MkdirAll(dir, os.ModePerm) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to create directory: %v", err) | ||
} | ||
|
||
return dir, nil | ||
} | ||
|
||
func ReadIPFromFile(configPath string) (string, error) { | ||
ipFile := filepath.Join(configPath, constants.CurrentIpFilename) | ||
data, err := os.ReadFile(ipFile) | ||
if os.IsNotExist(err) { | ||
fmt.Println("IP file does not exist yet, assuming first run") | ||
return "", nil | ||
} | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("failed to read IP from file: %v", err) | ||
} | ||
|
||
return string(data), nil | ||
} | ||
|
||
func WriteIPToFile(ip, configPath string) error { | ||
ipFile := filepath.Join(configPath, constants.CurrentIpFilename) | ||
err := os.WriteFile(ipFile, []byte(ip), 0644) | ||
if err != nil { | ||
return fmt.Errorf("failed to write IP to file: %v", err) | ||
} | ||
|
||
return 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