kurzd.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. export Export kurzd data.
  21. config Export kurz configuration.
  22. content Export kurz content.
  23. migrate Goose migration commands
  24. <goose commands> See https://github.com/pressly/goose
  25. uninstall Uninstall kurzd completely.
  26. config Uninstall the curz configuration file from ~.
  27. schema Uninstall the curz database schema.
  28. status Report on kurzd status
  29. stop Stop all instances of kurzd on the current server (restricted)
  30. */
  31. func main() {
  32. Execute()
  33. os.Exit(0)
  34. }
  35. type MapEntry struct {
  36. Hash uint64
  37. Url string
  38. Date1, Date2, Date3 time.Time
  39. RefCount uint32
  40. }
  41. func dbDial(dbDriver, dbDsn string) (*sql.DB, error) {
  42. db, err := sql.Open(dbDriver, dbDsn)
  43. if err != nil {
  44. return nil, err
  45. }
  46. return db, nil
  47. }
  48. func parseDbCred() (driver, dsn string) {
  49. viper.SetDefault("database.driver", "mysql")
  50. viper.SetDefault("database.dsn", "root:root@tcp(localhost:3306)/kurz")
  51. driver = viper.Get("database.driver").(string)
  52. dsn = viper.Get("database.dsn").(string)
  53. dsn += "?parseTime=true"
  54. return
  55. }