func runWeb(c *cli.Context) error { startServerService() m := macaron.New() //Set Macaron Web Middleware And Routers web.SetDockyardMacaron(m) switch setting.ListenMode { case "http": listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port")) if err := http.ListenAndServe(listenaddr, m); err != nil { fmt.Printf("Start Dockyard http service error: %v\n", err.Error()) return err } break case "https": listenaddr := fmt.Sprintf("%s:443", c.String("address")) server := &http.Server{Addr: listenaddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m} if err := server.ListenAndServeTLS(setting.HTTPSCertFile, setting.HTTPSKeyFile); err != nil { fmt.Printf("Start Dockyard https service error: %v\n", err.Error()) return err } break case "unix": listenaddr := fmt.Sprintf("%s", c.String("address")) if utils.IsFileExist(listenaddr) { os.Remove(listenaddr) } if listener, err := net.Listen("unix", listenaddr); err != nil { fmt.Printf("Start Dockyard unix socket error: %v\n", err.Error()) return err } else { server := &http.Server{Handler: m} if err := server.Serve(listener); err != nil { fmt.Printf("Start Dockyard unix socket error: %v\n", err.Error()) return err } } break default: break } return nil }
func runWeb(c *cli.Context) { m := macaron.New() if err := db.InitDB(setting.DBURI, setting.DBPasswd, setting.DBDB); err != nil { fmt.Printf("Connect Database Error %s", err.Error()) } web.SetWharfMacaron(m) dockyard.SetDockyardMacaron(m) crew.SetCrewMacaron(m) generator.SetGeneratorMacaron(m) switch setting.ListenMode { case "http": listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port")) if err := http.ListenAndServe(listenaddr, m); err != nil { fmt.Printf("start wharf http service error: %v", err.Error()) } break case "https": listenaddr := fmt.Sprintf("%s:443", c.String("address")) server := &http.Server{Addr: listenaddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m} if err := server.ListenAndServeTLS(setting.HttpsCertFile, setting.HttpsKeyFile); err != nil { fmt.Printf("start wharf https service error: %v", err.Error()) } break case "unix": listenaddr := fmt.Sprintf("%s", c.String("address")) if utils.IsFileExist(listenaddr) { os.Remove(listenaddr) } if listener, err := net.Listen("unix", listenaddr); err != nil { fmt.Printf("start wharf unix socket error: %v", err.Error()) } else { server := &http.Server{Handler: m} if err := server.Serve(listener); err != nil { fmt.Printf("start wharf unix socket error: %v", err.Error()) } } break default: break } }
func runWeb(c *cli.Context) { m := macaron.New() //Set Macaron Web Middleware And Routers web.SetDockyardMacaron(m) switch setting.ListenMode { case "http": listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port")) if err := http.ListenAndServe(listenaddr, m); err != nil { fmt.Printf("启动 dockyard 的 HTTP 服务错误: %v", err) } break case "https": //HTTPS 强制使用 443 端口 listenaddr := fmt.Sprintf("%s:443", c.String("address")) server := &http.Server{Addr: listenaddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m} if err := server.ListenAndServeTLS(setting.HttpsCertFile, setting.HttpsKeyFile); err != nil { fmt.Printf("启动 dockyard 的 HTTPS 服务错误: %v", err) } break case "unix": listenaddr := fmt.Sprintf("%s", c.String("address")) //如果存在 Unix Socket 文件就删除 if utils.Exist(listenaddr) { os.Remove(listenaddr) } if listener, err := net.Listen("unix", listenaddr); err != nil { fmt.Printf("启动 dockyard 的 Unix Socket 监听错误: %v", err) } else { server := &http.Server{Handler: m} if err := server.Serve(listener); err != nil { fmt.Printf("启动 dockyard 的 Unix Socket 监听错误: %v", err) } } break default: break } }