kurzd.go 1.8 KB

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