Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "database/sql"
  5. "fmt"
  6. "github.com/coopernurse/gorp"
  7. _ "github.com/go-sql-driver/mysql"
  8. "io/ioutil"
  9. "strconv"
  10. "strings"
  11. )
  12.  
  13. func iii(i interface{}) {
  14. fmt.Println("")
  15. }
  16.  
  17. func init() {
  18. buf := errA(ioutil.ReadFile("config.cfg"))
  19.  
  20. loginstr = strings.TrimSpace(string(buf))
  21. }
  22.  
  23. /*
  24. insertion
  25.  
  26.  
  27. */
  28. type dbtype *gorp.DbMap
  29.  
  30. type Cfgt struct {
  31. Option string `db:"option"`
  32. Value string `db:"value"`
  33. }
  34.  
  35. type Siplogt struct {
  36. Id uint `db:"id"`
  37. Gen bool `db:"gen"`
  38. From string `db:"from"`
  39. To string `db:"to"`
  40. }
  41.  
  42. func initDb() *gorp.DbMap {
  43. // connect to db using standard Go database/sql API
  44. // use whatever database/sql driver you wish
  45. db := errB(sql.Open("mysql", loginstr))
  46.  
  47. dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{}}
  48. dbmap.AddTableWithName(Cfgt{}, "cfg").SetKeys(false, "option")
  49. dbmap.AddTableWithName(Siplogt{}, "siplog").SetKeys(true, "id")
  50.  
  51. dbmap.AddTableWithName(Domaint{}, "Domain").SetKeys(true, "ID")
  52. dbmap.AddTableWithName(Regt{}, "Reg").SetKeys(true, "ID")
  53. dbmap.AddTableWithName(Contactt{}, "Contact").SetKeys(true, "ID")
  54.  
  55. return dbmap
  56. }
  57. func closeDb(dbmap *gorp.DbMap) {
  58. dbmap.Db.Close()
  59. }
  60.  
  61. func dblogmsg(dbmap *gorp.DbMap, gen bool, from string, to string) {
  62. errD(dbmap.Insert(&Siplogt{Gen: gen, From: from, To: to}))
  63. }
  64.  
  65. func loadcfg(dbmap *gorp.DbMap) (string, int, int) {
  66. host_row := errG(dbmap.Get(Cfgt{}, "host")).(*Cfgt)
  67. port_row := errG(dbmap.Get(Cfgt{}, "port")).(*Cfgt)
  68. blksize_row := errG(dbmap.Get(Cfgt{}, "blksize")).(*Cfgt)
  69.  
  70. host := host_row.Value
  71. port := errC(strconv.Atoi(port_row.Value))
  72. blksize := errC(strconv.Atoi(blksize_row.Value))
  73.  
  74. return host, port, blksize
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement