A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 lines
2.6 KiB

  1. //go:generate go-bindata -pkg bundled -o pkg/bundled/bindata.go pvt-www/...
  2. //go:generate echo hello world
  3. package main
  4. import (
  5. "flag"
  6. "fmt"
  7. "os"
  8. gophertype "git.kirsle.net/apps/gophertype/pkg"
  9. "git.kirsle.net/apps/gophertype/pkg/console"
  10. _ "git.kirsle.net/apps/gophertype/pkg/controllers"
  11. _ "github.com/jinzhu/gorm/dialects/mysql"
  12. _ "github.com/jinzhu/gorm/dialects/postgres"
  13. _ "github.com/jinzhu/gorm/dialects/sqlite"
  14. )
  15. // Build parameters.
  16. var (
  17. Build string
  18. BuildDate string
  19. )
  20. // Command-line flags.
  21. var (
  22. optVersion bool
  23. optDebug bool
  24. optBind string
  25. optRoot string
  26. // Database option flags.
  27. optSQLite string
  28. optPostgres string
  29. optMySQL string
  30. // Chosen DB options.
  31. dbDriver string
  32. dbPath string
  33. )
  34. func init() {
  35. flag.BoolVar(&optVersion, "version", false, "Show version number and exit")
  36. flag.BoolVar(&optVersion, "v", false, "Show version number and exit (alias)")
  37. flag.BoolVar(&optDebug, "debug", false, "Debug level logging")
  38. flag.StringVar(&optBind, "bind", ":8000", "Bind address for HTTP server")
  39. flag.StringVar(&optRoot, "root", "./public_html", "User root for custom web pages")
  40. // Database driver. Choose one.
  41. flag.StringVar(&optSQLite, "sqlite3", "", "Use SQLite database, default 'database.sqlite'")
  42. flag.StringVar(&optPostgres, "postgres", "",
  43. "Use Postgres database, format: "+
  44. "host=myhost port=myport user=gorm dbname=gorm password=mypassword")
  45. flag.StringVar(&optMySQL, "mysql", "",
  46. "Use MySQL database, format: "+
  47. "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
  48. }
  49. func main() {
  50. flag.Parse()
  51. if optVersion {
  52. fmt.Printf("This is gophertype v%s build %s (built on %s)\n", gophertype.Version, Build, BuildDate)
  53. os.Exit(0)
  54. }
  55. console.SetDebug(optDebug)
  56. // Validate the choice of database.
  57. if optSQLite != "" {
  58. dbDriver = "sqlite3"
  59. dbPath = optSQLite
  60. } else if optPostgres != "" {
  61. dbDriver = "postgres"
  62. dbPath = optPostgres
  63. } else if optMySQL != "" {
  64. dbDriver = "mysql"
  65. dbPath = optMySQL
  66. } else {
  67. fmt.Print(
  68. "Choose a database to use when running this command. Examples:\n" +
  69. "gophertype -sqlite3 database.sqlite\n" +
  70. "gophertype -postgres host=myhost port=myport user=gorm dbname=gorm password=mypassword\n" +
  71. "gophertype -mysql user:password@/dbname?charset=utf8&parseTime=True&loc=Local",
  72. )
  73. os.Exit(1)
  74. }
  75. fmt.Println("Hello world")
  76. app := gophertype.NewSite(optRoot)
  77. if err := app.UseDB(dbDriver, dbPath); err != nil {
  78. panic(err)
  79. }
  80. app.SetupRouter()
  81. if err := app.ListenAndServe(optBind); err != nil {
  82. console.Error("ListenAndServe: %s", err)
  83. os.Exit(0)
  84. }
  85. }