A web blog and personal homepage engine written in Go.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

82 rader
1.9 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. "git.kirsle.net/apps/gophertype/pkg"
  9. _ "git.kirsle.net/apps/gophertype/pkg/controllers"
  10. _ "github.com/jinzhu/gorm/dialects/mysql"
  11. _ "github.com/jinzhu/gorm/dialects/postgres"
  12. _ "github.com/jinzhu/gorm/dialects/sqlite"
  13. )
  14. // Build parameters.
  15. var (
  16. Build string
  17. BuildDate string
  18. )
  19. // Command-line flags.
  20. var (
  21. optDebug bool
  22. optBind string
  23. // Database option flags.
  24. optSQLite string
  25. optPostgres string
  26. optMySQL string
  27. // Chosen DB options.
  28. dbDriver string
  29. dbPath string
  30. )
  31. func init() {
  32. flag.BoolVar(&optDebug, "debug", false, "Debug level logging")
  33. flag.StringVar(&optBind, "bind", ":8000", "Bind address for HTTP server")
  34. // Database driver. Choose one.
  35. flag.StringVar(&optSQLite, "sqlite3", "", "Use SQLite database, default 'database.sqlite'")
  36. flag.StringVar(&optPostgres, "postgres", "",
  37. "Use Postgres database, format: "+
  38. "host=myhost port=myport user=gorm dbname=gorm password=mypassword")
  39. flag.StringVar(&optMySQL, "mysql", "",
  40. "Use MySQL database, format: "+
  41. "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
  42. }
  43. func main() {
  44. flag.Parse()
  45. // Validate the choice of database.
  46. if optSQLite != "" {
  47. dbDriver = "sqlite3"
  48. dbPath = optSQLite
  49. } else if optPostgres != "" {
  50. dbDriver = "postgres"
  51. dbPath = optPostgres
  52. } else if optMySQL != "" {
  53. dbDriver = "mysql"
  54. dbPath = optMySQL
  55. } else {
  56. fmt.Print(
  57. "Choose a database to use when running this command. Examples:\n" +
  58. "gophertype -sqlite3 database.sqlite\n" +
  59. "gophertype -postgres host=myhost port=myport user=gorm dbname=gorm password=mypassword\n" +
  60. "gophertype -mysql user:password@/dbname?charset=utf8&parseTime=True&loc=Local",
  61. )
  62. os.Exit(1)
  63. }
  64. fmt.Println("Hello world")
  65. app := gophertype.NewSite()
  66. app.UseDB(dbDriver, dbPath)
  67. app.SetupRouter()
  68. app.ListenAndServe(optBind)
  69. }