コード例 #1
0
ファイル: app.go プロジェクト: ursiform/forest
func New(configFile string) *App {
	app := new(App)
	app.Config = new(Config)
	if len(configFile) > 0 {
		app.Config.File = configFile
	} else {
		app.Config.File = ConfigFile
	}
	app.Mux = bear.New()
	err := loadConfig(app)
	app.Log, _ = logger.New(app.Config.LogLevel)
	if err != nil {
		logger.MustWarn("%s was not loaded", app.Config.File)
	}
	if app.Config.Address == "" {
		app.Config.Address = address
		app.Log.Warn("address is not defined in %s, using default %s",
			app.Config.File, address)
	}
	app.durations = make(map[string]time.Duration)
	app.errors = make(map[string]string)
	app.messages = make(map[string]string)
	app.wares = make(map[string]func(ctx *bear.Context))
	initDefaults(app)
	return app
}
コード例 #2
0
func ExampleMux_On_error() {
	mux := bear.New()
	handlerOne := func(http.ResponseWriter, *http.Request) {}
	handlerTwo := func(http.ResponseWriter, *http.Request) {}
	if err := mux.On("GET", "/foo/", handlerOne); err != nil {
		fmt.Println(err)
	} else if err := mux.On("*", "/foo/", handlerTwo); err != nil {
		fmt.Println(err)
	}
	// Output: bear: GET /foo/ exists, ignoring
}
コード例 #3
0
// Test ursiform/bear ns/op
func BenchmarkBearMux(b *testing.B) {
	request, _ := http.NewRequest("GET", "/sd", nil)
	response := httptest.NewRecorder()
	muxx := bear.New()

	muxx.On("GET", "/", Bench)
	muxx.On("GET", "/a", Bench)
	muxx.On("GET", "/aas", Bench)
	muxx.On("GET", "/sd", Bench)

	for n := 0; n < b.N; n++ {
		muxx.ServeHTTP(response, request)
	}
}