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

Commit

Permalink
Merge pull request #24 from jmillerv/22-configyaml-not-found-inside-o…
Browse files Browse the repository at this point in the history
…f-binary

22: config.yaml not found inside of binary
  • Loading branch information
jmillerv authored Aug 19, 2022
2 parents 09c45fe + faaa710 commit 46a2934
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
9 changes: 7 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

# Builds all binarys

# Builds all binaries for the /bin directory
build-all: build-linux build-osx build-windows

# Builds Linux executable
Expand All @@ -12,4 +13,8 @@ build-windows:

# Builds MacOS executable
build-osx:
cd ./src && GOOS=darwin GOARCH=amd64 go build -o bin/gophrase-386-darwin main.go
cd ./src && GOOS=darwin GOARCH=amd64 go build -o bin/gophrase-386-darwin main.go

# Build local
build-local:
cd ./src && go build -o ../gophrase
Binary file modified src/bin/gophrase-386-darwin
Binary file not shown.
Binary file modified src/bin/gophrase-amd64-linux
Binary file not shown.
Binary file modified src/bin/gophrase-amd64.exe
Binary file not shown.
31 changes: 20 additions & 11 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
"gopkg.in/yaml.v3"
"io/ioutil"
"log"
"os"
)

// Static asset constants
const (
EffLarge = "assets/wordlists/eff_large_wordlist.json"
EffShort1 = "assets/wordlists/eff_short_wordlist_1.json"
EffShort2 = "assets/wordlists/eff_short_wordlist_2.json"
Reinhold = "assets/wordlists/reinhold_wordlist.json"
Characters = "assets/wordlists/special_characters.json"
ListOptions = "assets/list_options.txt"
Configuration = "assets/config/config.yaml"
EffLarge = "assets/wordlists/eff_large_wordlist.json"
EffShort1 = "assets/wordlists/eff_short_wordlist_1.json"
EffShort2 = "assets/wordlists/eff_short_wordlist_2.json"
Reinhold = "assets/wordlists/reinhold_wordlist.json"
Characters = "assets/wordlists/special_characters.json"
ListOptions = "assets/list_options.txt"
DefaultConfiguration = "assets/config/config.yaml"
CustomConfiguration = "config.yaml"
)

// Assets is the embed.FS file system to access embedded files throughout the application.
Expand All @@ -41,24 +43,31 @@ func (c *Config) PrintConfig() {

// SetConfig takes in a config and writes it to the configuration file.
func SetConfig(config *Config) {
fileLocation := Configuration
file, err := yaml.Marshal(config)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(fileLocation, file, 0644)
err = ioutil.WriteFile(CustomConfiguration, file, 0644)
if err != nil {
log.Fatal(err)
}
}

// LoadConfig reads a configuration file and loads it into the LoadedConfig variable.
func LoadConfig() {
fileLocation, err := Assets.ReadFile(Configuration)
customFileLocation, err := os.ReadFile(CustomConfiguration)
if customFileLocation != nil {
err = yaml.Unmarshal(customFileLocation, &LoadedConfig)
if err != nil {
log.Fatal(err)
}
return
}
defaultFileLocation, err := Assets.ReadFile(DefaultConfiguration)
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal(fileLocation, &LoadedConfig)
err = yaml.Unmarshal(defaultFileLocation, &LoadedConfig)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 46a2934

Please sign in to comment.