35 lines
419 B
Go
35 lines
419 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"os"
|
||
|
|
||
|
"github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
Database string
|
||
|
HTTPBind string
|
||
|
}
|
||
|
|
||
|
var C = Config{
|
||
|
HTTPBind: ":8080",
|
||
|
}
|
||
|
|
||
|
func Load() error {
|
||
|
logrus.Info("loading config file")
|
||
|
|
||
|
f, err := os.Open("go-project-template.json")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
|
err = json.NewDecoder(f).Decode(&C)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|