mirror of https://github.com/qwc/backive.git
Another small meterstone (no milestone... :P)
This commit is contained in:
parent
924bbf134d
commit
53a230fb0a
|
@ -1,7 +1,41 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
f, err := os.OpenFile("/tmp/backive/udev.log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating logfile!")
|
||||
panic("no logfile no info")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
log.SetOutput(f)
|
||||
|
||||
env := map[string]string{}
|
||||
|
||||
for _, e := range os.Environ() {
|
||||
pair := strings.SplitN(e, "=", 2)
|
||||
env[pair[0]] = pair[1]
|
||||
log.Println("%s", e)
|
||||
}
|
||||
|
||||
c, err := net.Dial("unix", "/tmp/backive/backive.sock")
|
||||
if err != nil {
|
||||
log.Fatalln("Could not instantiate unix socket. Aborting")
|
||||
}
|
||||
jsonstr, err := json.Marshal(env)
|
||||
if err != nil {
|
||||
log.Fatalln("Could not convert to json. Aborting")
|
||||
}
|
||||
c.Write(jsonstr)
|
||||
defer c.Close()
|
||||
log.Printf("Sent %d bytes to unix socket.\n", len(jsonstr))
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qwc/backive/core"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
@ -41,6 +42,13 @@ func Load() *Configuration {
|
|||
panic(fmt.Errorf("Fatal error config file: %w \n", err))
|
||||
}
|
||||
|
||||
var cfg *Configuration
|
||||
|
||||
err := vconfig.Unmarshal(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("Error occured when loading config: %v\n", err)
|
||||
panic("No configuration available!")
|
||||
}
|
||||
//Unmarshal all into Configuration type
|
||||
return nil
|
||||
return cfg
|
||||
}
|
||||
|
|
|
@ -6,11 +6,14 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func TestDummyConfig(t *testing.T) {
|
||||
|
||||
v := CreateViper()
|
||||
v := viper.New()
|
||||
v.SetConfigType("yaml")
|
||||
var yamlExample = []byte(`
|
||||
settings:
|
||||
systemMountPoint: /media/backive
|
||||
|
@ -31,9 +34,10 @@ backups:
|
|||
var theConfig Configuration
|
||||
err := v.Unmarshal(&theConfig)
|
||||
if err != nil {
|
||||
fmt.Errorf("Unable to decode into struct, %v \n", err)
|
||||
fmt.Printf("Unable to decode into struct, %v \n", err)
|
||||
panic("Failed!")
|
||||
}
|
||||
fmt.Printf("systemMountpoint is %v \n", theConfig)
|
||||
|
||||
fmt.Printf("System Mountpoint is %v\n", v.Get("settings.systemmountpoint"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue