Skip to content

Commit

Permalink
refactor: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
igoogolx committed Oct 23, 2023
1 parent 20d1c0e commit 94a6ed1
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions internal/configuration/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

var mux sync.RWMutex
var fileMutex sync.Mutex
var configFilePath = atomic.NewString("")

//go:embed assets/config.json
Expand Down Expand Up @@ -41,25 +40,21 @@ func Write(c Config) error {
return nil
}

func SetConfigFilePath(path string) {
configFilePath.Store(path)
}

func Reset() error {
mux.Lock()
defer mux.Unlock()
fileMutex.Lock()
defer fileMutex.Unlock()
return write(defaultConfigContent)
}

func SetConfigFilePath(path string) {
configFilePath.Store(path)
}

func GetConfigFilePath() (string, error) {
return configFilePath.Load(), nil
}

func readFile() (*Config, error) {
fileMutex.Lock()
defer fileMutex.Unlock()
if !fileExists(configFilePath.Load()) {
err := write(defaultConfigContent)
if err != nil {
Expand All @@ -84,23 +79,13 @@ func readFile() (*Config, error) {
}

func writeFile(config Config) error {
fileMutex.Lock()
defer fileMutex.Unlock()
buf, err := json.MarshalIndent(config, "", " ")
if err != nil {
return fmt.Errorf("fail to marchal json, err:%v", err)
}
return write(buf)
}

func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

func write(data []byte) error {
f, err := os.Create(configFilePath.Load())
if err != nil {
Expand All @@ -118,3 +103,11 @@ func write(data []byte) error {
}
return nil
}

func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

0 comments on commit 94a6ed1

Please sign in to comment.