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

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

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

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

Loading…
Cancel
Save