mirror of
https://github.com/gwoo/goforever.git
synced 2025-09-26 19:41:10 +08:00
50 lines
835 B
Go
50 lines
835 B
Go
// goforever - processes management
|
|
// Copyright (c) 2013 Garrett Woodworth (https://github.com/gwoo).
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type Config struct {
|
|
Username string
|
|
Password string
|
|
Processes []*Process `toml:"process"`
|
|
}
|
|
|
|
func (c Config) Keys() []string {
|
|
keys := []string{}
|
|
for _, p := range c.Processes {
|
|
keys = append(keys, p.Name)
|
|
}
|
|
return keys
|
|
}
|
|
|
|
func (c Config) Get(key string) *Process {
|
|
for _, p := range c.Processes {
|
|
if p.Name == key {
|
|
return p
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func LoadConfig(file string) (*Config, error) {
|
|
if string(file[0]) != "/" {
|
|
wd, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
file = filepath.Join(wd, file)
|
|
}
|
|
var c *Config
|
|
if _, err := toml.DecodeFile(file, &c); err != nil {
|
|
return nil, err
|
|
}
|
|
return c, nil
|
|
}
|