當前位置: 首頁>>代碼示例>>Golang>>正文


Golang martini.Recovery函數代碼示例

本文整理匯總了Golang中github.com/go-martini/martini.Recovery函數的典型用法代碼示例。如果您正苦於以下問題:Golang Recovery函數的具體用法?Golang Recovery怎麽用?Golang Recovery使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Recovery函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mount

func mount(war string) {
	log.Println("mount")

	m := martini.Classic()
	m.Handlers(martini.Recovery())
	m.Use(martini.Static(war, martini.StaticOptions{SkipLogging: true}))
	m.Use(render.Renderer(render.Options{
		Extensions: []string{".html", ".shtml"},
	}))
	broker = NewBroker()
	m.Map(broker)

	m.Get("/", indexHandler)
	m.Get("/events/", sseHandler)
	http.Handle("/", m)

	go func() {
		for i := 0; ; i++ {

			// Create a little message to send to clients,
			// including the current time.
			broker.messages <- fmt.Sprintf(" %d - 哈哈,Oh, Yeah!!! - the time is %v", i, time.Now())

			// Print a nice log message and sleep for 5s.
			log.Printf("Sent message %d ", i)
			time.Sleep(5 * 1e9)

		}
	}()
}
開發者ID:philipbo,項目名稱:sse,代碼行數:30,代碼來源:mount.go

示例2: Start

func Start() {

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	// Gitchain API
	r.Post("/rpc", jsonRpcService().ServeHTTP)
	r.Get("/info", info)

	// Git Server
	r.Post("^(?P<path>.*)/git-upload-pack$", func(params martini.Params, req *http.Request) string {
		body, _ := ioutil.ReadAll(req.Body)
		fmt.Println(req, body)
		return params["path"]
	})

	r.Post("^(?P<path>.*)/git-receive-pack$", func(params martini.Params, req *http.Request) string {
		fmt.Println(req)
		return params["path"]
	})

	r.Get("^(?P<path>.*)/info/refs$", func(params martini.Params, req *http.Request) (int, string) {
		body, _ := ioutil.ReadAll(req.Body)
		fmt.Println(req, body)

		return 404, params["path"]
	})

	log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", env.Port), m))

}
開發者ID:josephyzhou,項目名稱:gitchain,代碼行數:34,代碼來源:http.go

示例3: main

func main() {
	username, password := waitForPostgres(serviceName)
	db, err := postgres.Open(serviceName, fmt.Sprintf("dbname=postgres user=%s password=%s", username, password))
	if err != nil {
		log.Fatal(err)
	}

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Use(render.Renderer())
	m.Action(r.Handle)
	m.Map(db)

	r.Post("/databases", createDatabase)
	r.Get("/ping", ping)

	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}
	addr := ":" + port

	if err := discoverd.Register(serviceName+"-api", addr); err != nil {
		log.Fatal(err)
	}

	log.Fatal(http.ListenAndServe(addr, m))
}
開發者ID:kelsieflynn,項目名稱:flynn-postgres,代碼行數:30,代碼來源:server.go

示例4: init

func init() {
	m = martini.New()
	//setup middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(martini.Static("public"))
}
開發者ID:heltonmarx,項目名稱:thermistor,代碼行數:7,代碼來源:main.go

示例5: main

/*
Application entry point
*/
func main() {
	m := martini.New()

	//Set middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())

	m.Use(cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"OPTIONS", "HEAD", "POST", "GET", "PUT"},
		AllowHeaders:     []string{"Authorization", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))

	//Create the router
	r := martini.NewRouter()

	//Options matches all and sends okay
	r.Options(".*", func() (int, string) {
		return 200, "ok"
	})

	api.SetupTodoRoutes(r)
	api.SetupCommentRoutes(r)

	mscore.StartServer(m, r)
	fmt.Println("Started NSQ Test service")
}
開發者ID:newsquid,項目名稱:newsquidtest,代碼行數:32,代碼來源:main.go

示例6: mount

func mount(war string) {

	m := martini.Classic()
	m.Handlers(martini.Recovery())
	m.Use(gzip.All())
	m.Use(martini.Static(war, martini.StaticOptions{SkipLogging: true}))
	//    m.Use(render.Renderer(render.Options{
	//        Extensions: []string{".html", ".shtml"},
	//    }))
	//	m.Use(render.Renderer())
	//    m.Use(midTextDefault)

	//map web
	m.Use(func(w http.ResponseWriter, c martini.Context) {
		web := &Web{w: w}
		c.Map(web)
	})

	m.Group("/test", func(api martini.Router) {
		api.Get("", mainHandler)
		api.Get("/1", test1Handler)
		api.Get("/2", test2Handler)
	})

	http.Handle("/", m)
}
開發者ID:gavinzhs,項目名稱:laohuo_process,代碼行數:26,代碼來源:mount.go

示例7: launchFrontend

func launchFrontend() {
	m := martini.New()
	m.Use(martini.Static("static"))
	m.Use(martini.Recovery())
	m.Use(martini.Logger())

	r := martini.NewRouter()
	r.Get("/", indexHandler)
	r.Get("/following", followHandler)
	r.Get("/stat", statHandler)
	r.Get("/channel/:streamer", channelHandler)
	r.Get("/add/:streamer", addHandler)
	r.Get("/del/:streamer", delHandler)
	r.Get("/api/stat/:streamer", apiStat)
	r.Get("/api/channel/:streamer", apiStat)
	r.Get("/api/following", apiFollowing)
	db := getDB()
	redis := getRedis()
	m.Map(db)
	m.Map(redis)

	m.Action(r.Handle)
	log.Print("Started Web Server")
	m.Run()
}
開發者ID:grsakea,項目名稱:kappastat,代碼行數:25,代碼來源:web.go

示例8: init

func init() {
	m = martini.New()

	//set up middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(auth.Basic(AuthToken, ""))
	m.Use(MapEncoder)

	// set up routes
	r := martini.NewRouter()
	r.Get(`/albums`, GetAlbums)
	r.Get(`/albums/:id`, GetAlbum)
	r.Post(`/albums`, AddAlbum)
	r.Put(`/albums/:id`, UpdateAlbum)
	r.Delete(`/albums/:id`, DeleteAlbum)

	// inject database
	// maps db package variable to the DB interface defined in data.go
	// The syntax for the second parameter may seem weird,
	// it is just converting nil to the pointer-to-DB-interface type,
	// because all the injector needs is the type to map the first parameter to.
	m.MapTo(db, (*DB)(nil))

	// add route action
	// adds the router’s configuration to the list of handlers that Martini will call.
	m.Action(r.Handle)
}
開發者ID:pyanfield,項目名稱:martini_demos,代碼行數:28,代碼來源:server.go

示例9: main

func main() {
	log.Println("server start11")
	fmt.Printf("access_token:%s", ACCESS_TOKEN)
	m := martini.Classic()
	m.Handlers(martini.Recovery())
	m.Use(render.Renderer(render.Options{
		Extensions: []string{".html", ".shtml"},
	}))

	m.Get("/", checkSignatureHandler)
	m.Post("/", transceiverMsgHandler)
	m.Get("/createMenu", createMenuHandler)
	m.Get("/hi", func() string {
		return "Hello world!"
	})

	http.Handle("/", m)
	if martini.Env == martini.Dev {
		HOST = ":8080"
	} else {
		HOST = ":80"
	}
	log.Printf("start web server on %s", HOST)
	http.ListenAndServe(HOST, nil)
}
開發者ID:sugeladi,項目名稱:goWeb,代碼行數:25,代碼來源:main.go

示例10: init

func init() {
	m = martini.New()

	// I could probably just use martini.Classic() instead of configure these manually

	// Static files
	m.Use(martini.Static(`public`))
	// Setup middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	// m.Use(auth.Basic(AuthToken, ""))
	m.Use(MapEncoder)

	// Setup routes
	r := martini.NewRouter()
	r.Get(`/albums`, server.GetAlbums)
	r.Get(`/albums/:id`, server.GetAlbum)
	r.Post(`/albums`, server.AddAlbum)
	r.Put(`/albums/:id`, server.UpdateAlbum)
	r.Delete(`/albums/:id`, server.DeleteAlbum)

	// Inject database
	m.MapTo(server.DBInstance, (*server.DB)(nil))
	// Add the router action
	m.Action(r.Handle)
}
開發者ID:ivanbportugal,項目名稱:go-albums,代碼行數:26,代碼來源:main.go

示例11: withoutLogging

func withoutLogging() *myClassic {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &myClassic{m, r}
}
開發者ID:JasonSoft,項目名稱:MyGo,代碼行數:8,代碼來源:core.go

示例12: NewWebService

// NewWebService creates a new web service ready to run.
func NewWebService() *martini.Martini {
	m := martini.New()
	m.Handlers(loggerMiddleware(), martini.Recovery(), gzip.All())
	r := newRouter()
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return m
}
開發者ID:PepperSalt42,項目名稱:api,代碼行數:9,代碼來源:http.go

示例13: main

func main() {
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Use(martini.Static("public"))
	r := martini.NewRouter()
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)

	// Instantiate OAuthService with the OAuth App Client Id & Secret from the Environment Variables
	o, err := coinbase.OAuthService(os.Getenv("COINBASE_CLIENT_ID"), os.Getenv("COINBASE_CLIENT_SECRET"), "https://localhost:8443/tokens")
	if err != nil {
		panic(err)
		return
	}

	// At https://localhost:8443/ we will display an "authorize" link
	r.Get("/", func() string {
		authorizeUrl := o.CreateAuthorizeUrl([]string{
			"user",
			"balance",
		})
		link := "<a href='" + authorizeUrl + "'>authorize</a>"
		return link
	})

	// AuthorizeUrl redirects to https://localhost:8443/tokens with 'code' in its
	// query params. If you dont have SSL enabled, replace 'https' with 'http'
	// and reload the page. If successful, the user's balance will show
	r.Get("/tokens", func(res http.ResponseWriter, req *http.Request) string {
		// Get the tokens given the 'code' query param
		tokens, err := o.NewTokensFromRequest(req) // Will use 'code' query param from req
		if err != nil {
			return err.Error()
		}
		// instantiate the OAuthClient
		c := coinbase.OAuthClient(tokens)
		amount, err := c.GetBalance()
		if err != nil {
			return err.Error()
		}
		return strconv.FormatFloat(amount, 'f', 6, 64)
	})

	// HTTP
	go func() {
		if err := http.ListenAndServe(":8080", m); err != nil {
			log.Fatal(err)
		}
	}()

	// HTTPS
	// To generate a development cert and key, run the following from your *nix terminal:
	// go run $(go env GOROOT)/src/pkg/crypto/tls/generate_cert.go --host="localhost"
	if err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", m); err != nil {
		log.Fatal(err)
	}
}
開發者ID:jmptrader,項目名稱:coinbase-go,代碼行數:58,代碼來源:OAuthExample.go

示例14: NewMartini

func NewMartini() *martini.ClassicMartini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.Use(render.Renderer())
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &martini.ClassicMartini{Martini: m, Router: r}
}
開發者ID:ckeyer,項目名稱:go-ci,代碼行數:9,代碼來源:server.go

示例15: nolog

func nolog() *martini.ClassicMartini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.Use(martini.Static("public"))
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &martini.ClassicMartini{m, r}
}
開發者ID:h2so5,項目名稱:murcott,代碼行數:9,代碼來源:web.go


注:本文中的github.com/go-martini/martini.Recovery函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。