init.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package common
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. "path/filepath"
  8. )
  9. var (
  10. Port = flag.Int("port", 3000, "the listening port")
  11. PrintVersion = flag.Bool("version", false, "print version and exit")
  12. LogDir = flag.String("log-dir", "", "specify the log directory")
  13. //Host = flag.Key("host", "localhost", "the server's ip address or domain")
  14. //Path = flag.Key("path", "", "specify a local path to public")
  15. //VideoPath = flag.Key("video", "", "specify a video folder to public")
  16. //NoBrowser = flag.Bool("no-browser", false, "open browser or not")
  17. )
  18. // UploadPath Maybe override by ENV_VAR
  19. var UploadPath = "upload"
  20. //var ExplorerRootPath = UploadPath
  21. //var ImageUploadPath = "upload/images"
  22. //var VideoServePath = "upload"
  23. func init() {
  24. flag.Parse()
  25. if *PrintVersion {
  26. fmt.Println(Version)
  27. os.Exit(0)
  28. }
  29. if os.Getenv("SESSION_SECRET") != "" {
  30. SessionSecret = os.Getenv("SESSION_SECRET")
  31. }
  32. if os.Getenv("SQLITE_PATH") != "" {
  33. SQLitePath = os.Getenv("SQLITE_PATH")
  34. }
  35. if os.Getenv("UPLOAD_PATH") != "" {
  36. UploadPath = os.Getenv("UPLOAD_PATH")
  37. //ExplorerRootPath = UploadPath
  38. //ImageUploadPath = path.Join(UploadPath, "images")
  39. //VideoServePath = UploadPath
  40. }
  41. if *LogDir != "" {
  42. var err error
  43. *LogDir, err = filepath.Abs(*LogDir)
  44. if err != nil {
  45. log.Fatal(err)
  46. }
  47. if _, err := os.Stat(*LogDir); os.IsNotExist(err) {
  48. err = os.Mkdir(*LogDir, 0777)
  49. if err != nil {
  50. log.Fatal(err)
  51. }
  52. }
  53. }
  54. //if *Path != "" {
  55. // ExplorerRootPath = *Path
  56. //}
  57. //if *VideoPath != "" {
  58. // VideoServePath = *VideoPath
  59. //}
  60. //
  61. //ExplorerRootPath, _ = filepath.Abs(ExplorerRootPath)
  62. //VideoServePath, _ = filepath.Abs(VideoServePath)
  63. //ImageUploadPath, _ = filepath.Abs(ImageUploadPath)
  64. //
  65. if _, err := os.Stat(UploadPath); os.IsNotExist(err) {
  66. _ = os.Mkdir(UploadPath, 0777)
  67. }
  68. //if _, err := os.Stat(ImageUploadPath); os.IsNotExist(err) {
  69. // _ = os.Mkdir(ImageUploadPath, 0777)
  70. //}
  71. }