Пример #1
0
// This example demonstrates a trivial echo server.
func ExampleHandler() {
	http.Handle("/echo", websocket.Handler(EchoServer))
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
Пример #2
0
func startWeb() {
	if p := os.Getenv("PORT"); p != "" {
		port = p
	}

	router := mux.NewRouter()

	// router.HandleFunc("/", redirect("/apps")).Methods("GET")

	router.HandleFunc("/check", check).Methods("GET")

	router.HandleFunc("/apps", controllers.AppList).Methods("GET")
	router.HandleFunc("/apps", controllers.AppCreate).Methods("POST")
	router.HandleFunc("/apps/{app}", controllers.AppShow).Methods("GET")
	router.HandleFunc("/apps/{app}", controllers.AppUpdate).Methods("POST")
	router.HandleFunc("/apps/{app}", controllers.AppDelete).Methods("DELETE")
	router.HandleFunc("/apps/{app}/available", controllers.AppNameAvailable).Methods("GET")
	router.HandleFunc("/apps/{app}/build", controllers.BuildCreate).Methods("POST")
	router.HandleFunc("/apps/{app}/builds", controllers.BuildList).Methods("GET")
	router.HandleFunc("/apps/{app}/builds/{build}", controllers.BuildGet).Methods("GET")
	router.Handle("/apps/{app}/builds/{build}/logs", websocket.Handler(controllers.BuildLogs)).Methods("GET")
	router.HandleFunc("/apps/{app}/builds/{build}/status", controllers.BuildStatus).Methods("GET")
	router.HandleFunc("/apps/{app}/changes", controllers.AppChanges).Methods("GET")
	router.HandleFunc("/apps/{app}/debug", controllers.AppDebug).Methods("GET")
	router.HandleFunc("/apps/{app}/deployments", controllers.AppDeployments).Methods("GET")
	router.HandleFunc("/apps/{app}/environment", controllers.AppEnvironment).Methods("GET")
	router.HandleFunc("/apps/{app}/environment", controllers.EnvironmentSet).Methods("POST")
	router.HandleFunc("/apps/{app}/environment/{name}", controllers.EnvironmentCreate).Methods("POST")
	router.HandleFunc("/apps/{app}/environment/{name}", controllers.EnvironmentDelete).Methods("DELETE")
	router.HandleFunc("/apps/{app}/events", controllers.AppEvents).Methods("GET")
	router.HandleFunc("/apps/{app}/logs", controllers.AppLogs)
	router.HandleFunc("/apps/{app}/logs/stream", controllers.AppStream)
	router.HandleFunc("/apps/{app}/processes", controllers.ProcessList).Methods("GET")
	router.HandleFunc("/apps/{app}/processes/{process}", controllers.ProcessShow).Methods("GET")
	router.HandleFunc("/apps/{app}/processes/{id}", controllers.ProcessStop).Methods("DELETE")
	router.HandleFunc("/apps/{app}/processes/{id}/top", controllers.ProcessTop).Methods("GET")
	router.HandleFunc("/apps/{app}/processes/{process}/logs", controllers.ProcessLogs).Methods("GET")
	router.Handle("/apps/{app}/processes/{process}/run", websocket.Handler(controllers.ProcessRunAttached)).Methods("GET")
	router.HandleFunc("/apps/{app}/processes/{process}/run", controllers.ProcessRun).Methods("POST")
	router.HandleFunc("/apps/{app}/promote", controllers.AppPromote).Methods("POST")
	router.HandleFunc("/apps/{app}/releases", controllers.AppReleases).Methods("GET")
	router.HandleFunc("/apps/{app}/releases", controllers.ReleaseCreate).Methods("POST")
	router.HandleFunc("/apps/{app}/releases/{release}", controllers.ReleaseShow).Methods("GET")
	router.HandleFunc("/apps/{app}/releases/{release}/promote", controllers.ReleasePromote).Methods("POST")
	router.HandleFunc("/apps/{app}/resources", controllers.AppResources).Methods("GET")
	router.HandleFunc("/apps/{app}/services", controllers.ServiceLink).Methods("POST")
	router.HandleFunc("/apps/{app}/services/{name}", controllers.ServiceUnlink).Methods("DELETE")
	router.HandleFunc("/apps/{app}/status", controllers.AppStatus).Methods("GET")
	router.HandleFunc("/services", controllers.ServiceList).Methods("GET")
	router.HandleFunc("/services", controllers.ServiceCreate).Methods("POST")
	router.HandleFunc("/services/{service}", controllers.ServiceShow).Methods("GET")
	router.HandleFunc("/services/{service}", controllers.ServiceDelete).Methods("DELETE")
	router.HandleFunc("/services/{service}/logs", controllers.ServiceLogs).Methods("GET")
	router.HandleFunc("/services/{service}/logs/stream", controllers.ServiceStream).Methods("GET")
	router.HandleFunc("/services/types/{type}", controllers.ServiceNameList).Methods("GET")
	router.HandleFunc("/settings", controllers.SettingsList).Methods("GET")
	router.HandleFunc("/settings", controllers.SettingsUpdate).Methods("POST")
	router.HandleFunc("/system", controllers.SystemShow).Methods("GET")
	router.HandleFunc("/system", controllers.SystemUpdate).Methods("POST")
	router.HandleFunc("/version", controllers.VersionGet).Methods("GET")

	n := negroni.New(
		negroni.NewRecovery(),
		nlogger.New("ns=kernel", nil),
		negroni.NewStatic(http.Dir("public")),
	)

	n.Use(negroni.HandlerFunc(parseForm))
	n.Use(negroni.HandlerFunc(basicAuthentication))
	n.UseHandler(router)
	n.Run(fmt.Sprintf(":%s", port))
}