Skip to content

Commit

Permalink
Add external drivers to the code base
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed Nov 13, 2017
1 parent bdf9a62 commit 4094c1f
Show file tree
Hide file tree
Showing 19 changed files with 2,109 additions and 0 deletions.
38 changes: 38 additions & 0 deletions drivers/driver_main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package drivers

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

// DriverMain helps dry up the implementation of main.go for drivers
func DriverMain(driver Interface) {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to read from stdin")
os.Exit(1)
}

var config Config
err = json.Unmarshal(b, &config)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse json from stdin: %v\n%s\n", err, b)
os.Exit(1)
}

dinfo, err := driver.Assemble(config)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

b, err = json.Marshal(dinfo)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to marshal json:", err)
os.Exit(1)
}

os.Stdout.Write(b)
}
Loading

0 comments on commit 4094c1f

Please sign in to comment.