Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "database/sql"
- "fmt"
- "github.com/coopernurse/gorp"
- _ "github.com/go-sql-driver/mysql"
- "io/ioutil"
- "strconv"
- "strings"
- )
- func iii(i interface{}) {
- fmt.Println("")
- }
- func init() {
- buf := errA(ioutil.ReadFile("config.cfg"))
- loginstr = strings.TrimSpace(string(buf))
- }
- /*
- insertion
- */
- type dbtype *gorp.DbMap
- type Cfgt struct {
- Option string `db:"option"`
- Value string `db:"value"`
- }
- type Siplogt struct {
- Id uint `db:"id"`
- Gen bool `db:"gen"`
- From string `db:"from"`
- To string `db:"to"`
- }
- func initDb() *gorp.DbMap {
- // connect to db using standard Go database/sql API
- // use whatever database/sql driver you wish
- db := errB(sql.Open("mysql", loginstr))
- dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{}}
- dbmap.AddTableWithName(Cfgt{}, "cfg").SetKeys(false, "option")
- dbmap.AddTableWithName(Siplogt{}, "siplog").SetKeys(true, "id")
- dbmap.AddTableWithName(Domaint{}, "Domain").SetKeys(true, "ID")
- dbmap.AddTableWithName(Regt{}, "Reg").SetKeys(true, "ID")
- dbmap.AddTableWithName(Contactt{}, "Contact").SetKeys(true, "ID")
- return dbmap
- }
- func closeDb(dbmap *gorp.DbMap) {
- dbmap.Db.Close()
- }
- func dblogmsg(dbmap *gorp.DbMap, gen bool, from string, to string) {
- errD(dbmap.Insert(&Siplogt{Gen: gen, From: from, To: to}))
- }
- func loadcfg(dbmap *gorp.DbMap) (string, int, int) {
- host_row := errG(dbmap.Get(Cfgt{}, "host")).(*Cfgt)
- port_row := errG(dbmap.Get(Cfgt{}, "port")).(*Cfgt)
- blksize_row := errG(dbmap.Get(Cfgt{}, "blksize")).(*Cfgt)
- host := host_row.Value
- port := errC(strconv.Atoi(port_row.Value))
- blksize := errC(strconv.Atoi(blksize_row.Value))
- return host, port, blksize
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement