kurzd.go 1.7 KB

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