-
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.
Feature: Move config to TOML file. Closes #120
- Loading branch information
Showing
15 changed files
with
191 additions
and
290 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
package config | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"path" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/danstis/Plex-Sync/plex" | ||
) | ||
|
||
//ConfigFile defines the path to the configuration file | ||
var ( | ||
configFile = path.Join("config", "config.toml") | ||
) | ||
|
||
// Settings defines the program configureation | ||
type Settings struct { | ||
WebServerPort int | ||
CacheLifetime int | ||
SyncInterval int | ||
Logging logging `toml:"logging"` | ||
LocalServer plex.Host `toml:"localserver"` | ||
RemoteServer plex.Host `toml:"remoteserver"` | ||
} | ||
|
||
type logging struct { | ||
Logfile string | ||
Webserverlogfile string | ||
MaxLogSize int | ||
MaxLogCount int | ||
MaxLogAge int | ||
} | ||
|
||
// GetConfig returns the application configuration from the config TOML file. | ||
func GetConfig() (Settings, error) { | ||
var s Settings | ||
_, err := toml.DecodeFile(configFile, &s) | ||
if os.IsNotExist(err) { | ||
s := Settings{ | ||
WebServerPort: 8080, | ||
Logging: logging{ | ||
MaxLogSize: 5, | ||
MaxLogCount: 1, | ||
MaxLogAge: 30, | ||
}, | ||
LocalServer: plex.Host{}, | ||
RemoteServer: plex.Host{}, | ||
CacheLifetime: 30, | ||
SyncInterval: 3600, | ||
} | ||
err := UpdateConfig(s) | ||
return s, err | ||
} | ||
if err != nil { | ||
return Settings{}, err | ||
} | ||
return s, nil | ||
} | ||
|
||
// UpdateConfig sets the configuration settings in the config TOML file. | ||
func UpdateConfig(s Settings) error { | ||
f, err := os.OpenFile(configFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
w := bufio.NewWriter(f) | ||
defer w.Flush() | ||
return toml.NewEncoder(w).Encode(s) | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
module github.com/danstis/Plex-Sync | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 | ||
github.com/gopherjs/gopherjs v0.0.0-20180227192048-df18d38287ab // indirect | ||
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect | ||
github.com/gorilla/handlers v1.3.0 | ||
github.com/gorilla/mux v1.6.1 | ||
github.com/jtolds/gls v4.2.1+incompatible // indirect | ||
github.com/smartystreets/assertions v0.0.0-20170925172151-0b37b35ec743 // indirect | ||
github.com/smartystreets/goconvey v0.0.0-20170602164621-9e8dc3f972df | ||
github.com/smartystreets/gunit v0.0.0-20180314194857-6f0d6275bdcd // indirect | ||
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3 | ||
gopkg.in/yaml.v2 v2.2.2 // indirect | ||
) |
Oops, something went wrong.