kurzd.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Package kurzd contains the Kurz daemon command.
  2. package main
  3. import (
  4. "os"
  5. "time"
  6. "database/sql"
  7. _ "github.com/go-sql-driver/mysql"
  8. )
  9. /**
  10. kurzd
  11. -v Verbose (default: false).
  12. help Display help.
  13. server Serve kurz (default option).
  14. -p|--port <port_id> Serve on this IP port (default: 80).
  15. -m|--monitoring <port_id> Serve monitoring on this IP port (default: none)
  16. install Install kurzd completely.
  17. config Install the configuration define by command line to ~.
  18. schema Install the kurz database schema.
  19. export Export kurzd data.
  20. -o <file> Specify a destination file.
  21. config Export kurz configuration.
  22. content Export kurz content.
  23. uninstall Uninstall kurzd completely.
  24. config Uninstall the curz configuration file from ~.
  25. schema Uninstall the curz database schema.
  26. status Report on kurzd status
  27. stop Stop all instances of kurzd on the current server (restricted)
  28. */
  29. func main() {
  30. Execute()
  31. os.Exit(0)
  32. }
  33. type MapEntry struct {
  34. Hash uint64
  35. Url string
  36. Date1, Date2, Date3 time.Time
  37. RefCount uint32
  38. }
  39. func dbDial(dbDriver, dbDsn string) (*sql.DB, error) {
  40. db, err := sql.Open(dbDriver, dbDsn)
  41. if err != nil {
  42. return nil, err
  43. }
  44. return db, nil
  45. }
  46. func parseDbCred() (driver, dsn string) {
  47. const DefaultDriver = "mysql"
  48. const DefaultDsn = "root:root@tcp(localhost:3306)/kurz"
  49. envDriver := os.Getenv("DB_DRIVER")
  50. if envDriver == "" {
  51. envDriver = DefaultDriver
  52. }
  53. envDsn := os.Getenv("DB_DSN")
  54. if envDsn == "" {
  55. envDsn = DefaultDsn
  56. }
  57. envDsn += "?parseTime=true"
  58. return envDriver, envDsn
  59. }