func Serve(redisHost, redisPWD string) { rdPool = NewRedisPool(redisHost, redisPWD) server := app.New() server.Use(logger.New()) server.Use(middlewares.Auth(rdPool)) server.Use(methodoverride.New()) controllers.NewAPI(rdPool) serverAPI := controllers.NewServerAPI() serverActions := controllers.NewAction() server.Get("/api/servers", controllers.JsonView(serverAPI.Index)) server.Post("/api/servers", controllers.JsonView(serverAPI.Create)) server.Get("/api/servers/:id", controllers.JsonView(serverAPI.Show)) server.Del("/api/servers/:id", controllers.JsonView(serverAPI.Destroy)) server.Put("/api/servers/:id", controllers.JsonView(serverAPI.Update)) server.Post("/api/servers/:id/start", controllers.JsonView(serverActions.Start)) server.Post("/api/servers/:id/stop", controllers.JsonView(serverActions.Stop)) server.Post("/api/servers/:id/restart", controllers.JsonView(serverActions.Restart)) // // server.Get("/api/servers/:id/logs", "get :id server logs") // server.Get("/api/servers/:id/flow", "get :id server flow") server.Listen(":7888") }
func main() { configPath := flag.String("c", "./config.json", "-c=./config.json") outBuildInfo := flag.Bool("v", false, "build info") help := flag.Bool("h", false, "help") flag.Parse() if *help { flag.Usage() return } if *outBuildInfo { outputBuildInfo() return } loadConfig(*configPath) initLog() app := app.New() s := stats.New() app.Use(NewLogMiddle(s)) app.Use(mount.New("/file", NewStaticServeMiddle("/file", config.StaticDir))) registRouter(app) go s.TickEveryTo(time.Second*60, logger) err := startServer(app) if err != nil { logger.Printf(" %v", err) } }
// Start Dockerboard application. func Run(static, port string) { // The Instances of Controllers. containersController := controllers.NewContainers() containerActionsController := controllers.NewContainerActions() imagesController := controllers.NewImages() imageActionsController := controllers.NewImageActions() systemController := controllers.NewSystem() hostsController := controllers.NewHosts() hostActionsController := controllers.NewHostActions() // Create app. app := app.New() app.Use(WSHandler("/ws")) app.Use(logger.New()) app.Use(serve.New(static)) app.Use(methodoverride.New()) app.Get("/api", APIHandler) // Controllers CRUD APIs etc. app.Get("/api/containers", containersController.Index) app.Post("/api/containers", containersController.Create) app.Get("/api/containers/:id", containersController.Show) app.Del("/api/containers/:id", containersController.Destroy) app.Post("/api/containers/:id/start", containerActionsController.Start) app.Post("/api/containers/:id/stop", containerActionsController.Stop) app.Post("/api/containers/:id/restart", containerActionsController.Restart) app.Post("/api/containers/:id/pause", containerActionsController.Pause) app.Post("/api/containers/:id/unpause", containerActionsController.UnPause) app.Post("/api/containers/:id/kill", containerActionsController.Kill) app.Get("/api/containers/:id/logs", containerActionsController.Logs) app.Get("/api/containers/:id/top", containerActionsController.Top) app.Post("/api/containers/:id/rename", containerActionsController.Rename) app.Get("/api/containers/:id/stats", containerActionsController.Stats) // Images CRUD APIs etc. app.Get("/api/images", imagesController.Index) app.Post("/api/images", imagesController.Create) app.Get("/api/images/search", imagesController.Search) app.Get("/api/images/:id", imagesController.Show) app.Del("/api/images/:id", imagesController.Destroy) app.Get("/api/images/:id/history", imageActionsController.History) app.Post("/api/images/:id/tag", imageActionsController.Tag) app.Post("/api/images/:name/push", imageActionsController.Push) // Hosts CRUD APIs etc. app.Get("/api/hosts", hostsController.Index) app.Post("/api/hosts", hostsController.Create) app.Del("/api/hosts/:id", hostsController.Destroy) app.Get("/api/hosts/:id/ping", hostActionsController.Ping) app.Get("/api/hosts/:id/version", hostActionsController.Version) app.Get("/api/system", systemController.Info) app.Get("/api/apps", controllers.NewApps().Index) // Listen Port. app.Listen(":" + port) }
func main() { a := app.New() a.Use(logger.New()) a.Use(serve.New("examples")) a.Get("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hello")) })) a.Listen(":3000") }
func main() { app := app.New() app.Get("/foo", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "foo") })) app.Get("/bar", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "bar") }) app.Listen(":3000") }
func main() { a := app.New() a.Use(logger.New()) a.Get("/", http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { res.Write([]byte("hello")) res.Write([]byte(" world")) })) a.Get("/yahoo", http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { page, _ := http.Get("http://yahoo.com") defer page.Body.Close() io.Copy(res, page.Body) })) a.Get("/error", http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { res.WriteHeader(500) res.Write([]byte("boom")) })) a.Listen(":3000") }