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
Showing
7 changed files
with
109 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
package servermanager | ||
|
||
type Account struct { | ||
Name string `yaml:"name"` | ||
Group Group `yaml:"group"` | ||
PasswordMD5Hash string `yaml:"password"` | ||
} | ||
|
||
type Group string |
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package servermanager | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/etcd-io/bbolt" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
HTTP HTTPConfig `yaml:"http"` | ||
Steam SteamConfig `yaml:"steam"` | ||
Store StoreConfig `yaml:"store"` | ||
Users UsersConfig `yaml:"users"` | ||
} | ||
|
||
type HTTPConfig struct { | ||
Hostname string `yaml:"hostname"` | ||
} | ||
|
||
type SteamConfig struct { | ||
Username string `yaml:"username"` | ||
Password string `yaml:"password"` | ||
InstallPath string `yaml:"install_path"` | ||
ForceUpdate bool `yaml:"force_update"` | ||
} | ||
|
||
type StoreConfig struct { | ||
Type string `yaml:"type"` | ||
Path string `yaml:"path"` | ||
} | ||
|
||
func (s *StoreConfig) BuildStore() (RaceStore, error) { | ||
switch s.Type { | ||
case "boltdb": | ||
bbdb, err := bbolt.Open(s.Path, 0644, nil) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return NewBoltRaceStore(bbdb), nil | ||
case "json": | ||
return NewJSONRaceStore(s.Path), nil | ||
default: | ||
return nil, fmt.Errorf("invalid store type (%s), must be either boltdb/json", s.Type) | ||
} | ||
} | ||
|
||
type UsersConfig struct { | ||
Accounts []Account `yaml:"accounts"` | ||
|
||
ReadOpen bool `yaml:"read_open"` | ||
} | ||
|
||
func ReadConfig(location string) (conf *Config, err error) { | ||
f, err := os.Open(location) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer f.Close() | ||
|
||
err = yaml.NewDecoder(f).Decode(&conf) | ||
|
||
return conf, err | ||
} |