pull/5/head
Jordan Orelli 10 years ago
parent c78214da96
commit 37dd4afc74

@ -1,32 +1,32 @@
package main package main
import ( import (
"strings" "strings"
) )
const ( const (
E_Ok int = iota E_Ok int = iota
E_No_Data E_No_Data
E_No_DB E_No_DB
) )
type errorGroup []error type errorGroup []error
func (e errorGroup) Error() string { func (e errorGroup) Error() string {
messages := make([]string, 0, len(e)) messages := make([]string, 0, len(e))
for i, _ := range e { for i, _ := range e {
messages[i] = e[i].Error() messages[i] = e[i].Error()
} }
return strings.Join(messages, " && ") return strings.Join(messages, " && ")
} }
func (g *errorGroup) AddError(err error) { func (g *errorGroup) AddError(err error) {
if err == nil { if err == nil {
return return
} }
if g == nil { if g == nil {
panic("fart") panic("fart")
*g = make([]error, 0, 4) *g = make([]error, 0, 4)
} }
*g = append(*g, err) *g = append(*g, err)
} }

@ -1,31 +1,31 @@
package main package main
import ( import (
"fmt" "fmt"
"os" "os"
) )
var dataPath = "/projects/exo/expl.speck" var dataPath = "/projects/exo/expl.speck"
func log_error(template string, args ...interface{}) { func log_error(template string, args ...interface{}) {
fmt.Fprint(os.Stderr, "ERROR ") fmt.Fprint(os.Stderr, "ERROR ")
fmt.Fprintf(os.Stderr, template+"\n", args...) fmt.Fprintf(os.Stderr, template+"\n", args...)
} }
func log_info(template string, args ...interface{}) { func log_info(template string, args ...interface{}) {
fmt.Fprint(os.Stdout, "INFO ") fmt.Fprint(os.Stdout, "INFO ")
fmt.Fprintf(os.Stdout, template+"\n", args...) fmt.Fprintf(os.Stdout, template+"\n", args...)
} }
func bail(status int, template string, args ...interface{}) { func bail(status int, template string, args ...interface{}) {
if status == 0 { if status == 0 {
fmt.Fprintf(os.Stdout, template, args...) fmt.Fprintf(os.Stdout, template, args...)
} else { } else {
fmt.Fprintf(os.Stderr, template, args...) fmt.Fprintf(os.Stderr, template, args...)
} }
os.Exit(status) os.Exit(status)
} }
func main() { func main() {
setupDb() setupDb()
} }

@ -31,7 +31,7 @@ func speckStream(r io.ReadCloser, c chan exoSystem) {
continue continue
} }
planet := parseSpeckLine(line) planet := parseSpeckLine(line)
c <- *planet c <- *planet
} }
} }
@ -49,17 +49,17 @@ func (e exoSystem) Store(db *sql.DB) {
values values
(?, ?, ?, ?, ?) (?, ?, ?, ?, ?)
;`, e.name, e.x, e.y, e.z, e.planets) ;`, e.name, e.x, e.y, e.z, e.planets)
if err != nil { if err != nil {
log_error("%v", err) log_error("%v", err)
} }
} }
func countPlanets(db *sql.DB) (int, error) { func countPlanets(db *sql.DB) (int, error) {
row := db.QueryRow(`select count(*) from planets`) row := db.QueryRow(`select count(*) from planets`)
var n int var n int
err := row.Scan(&n) err := row.Scan(&n)
return n, err return n, err
} }
func (e exoSystem) String() string { func (e exoSystem) String() string {

Loading…
Cancel
Save