1
0
Fork 0
forked from External/ergo

move db init/open functions into a single file

This commit is contained in:
Jeremy Latt 2014-03-01 15:02:24 -08:00
parent 542744d52a
commit b421971b61
3 changed files with 34 additions and 31 deletions

View file

@ -2,12 +2,10 @@ package main
import (
"code.google.com/p/go.crypto/bcrypt"
"database/sql"
"encoding/base64"
"flag"
"fmt"
"github.com/jlatt/ergonomadic/irc"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
)
@ -21,27 +19,6 @@ func genPasswd(passwd string) {
fmt.Println(encoded)
}
func initDB(config *irc.Config) {
os.Remove(config.Database())
db, err := sql.Open("sqlite3", config.Database())
if err != nil {
log.Fatal(err)
}
defer db.Close()
_, err = db.Exec(`
CREATE TABLE channel (
name TEXT NOT NULL UNIQUE,
flags TEXT NOT NULL,
key TEXT NOT NULL,
topic TEXT NOT NULL,
user_limit INTEGER DEFAULT 0)`)
if err != nil {
log.Fatal(err)
}
}
func main() {
conf := flag.String("conf", "ergonomadic.json", "ergonomadic config file")
initdb := flag.Bool("initdb", false, "initialize database")
@ -59,7 +36,7 @@ func main() {
}
if *initdb {
initDB(config)
irc.InitDB(config.Database())
return
}