Пример #1
0
func NewServer(config *Config) (*iris.Framework, error) {
	ir := iris.New(
		iris.OptionDisableBanner(true),
	)

	source := NewS3(config.SourceAwsId, config.SourceAwsSecret, config.SourceAwsS3Bucket, config.SourceAwsS3Region)

	p := NewProcessor(source)

	ir.Get("/*path", handler(p))

	return ir, nil
}
Пример #2
0
// New Prepares and returns a new test framework based on the api
// is useful when you need to have more than one test framework for the same iris instance
// usage:
// iris.Get("/mypath", func(ctx *iris.Context){ctx.Write("my body")})
// ...
// e := httptest.New(iris.Default, t)
// e.GET("/mypath").Expect().Status(iris.StatusOK).Body().Equal("my body")
//
// You can find example on the https://github.com/kataras/iris/glob/master/context_test.go
func New(api *iris.Framework, t *testing.T, setters ...OptionSetter) *httpexpect.Expect {
	conf := DefaultConfiguration()
	for _, setter := range setters {
		setter.Set(conf)
	}

	api.Set(iris.OptionDisableBanner(true))

	baseURL := ""
	if !api.Plugins.PreBuildFired() {
		api.Build()
	}
	if !conf.ExplicitURL {
		baseURL = api.Config.VScheme + api.Config.VHost
		// if it's still empty then set it to the default server addr
		if baseURL == "" {
			baseURL = iris.SchemeHTTP + iris.DefaultServerAddr
		}

	}

	testConfiguration := httpexpect.Config{
		BaseURL: baseURL,
		Client: &http.Client{
			Transport: httpexpect.NewFastBinder(api.Router),
			Jar:       httpexpect.NewJar(),
		},
		Reporter: httpexpect.NewAssertReporter(t),
	}

	if conf.Debug {
		testConfiguration.Printers = []httpexpect.Printer{
			httpexpect.NewDebugPrinter(t, true),
		}
	}

	return httpexpect.WithConfig(testConfiguration)
}
Пример #3
0
func ExamplePlugins_Add() {
	iris.ResetDefault()
	iris.Default.Set(iris.OptionDisableBanner(true))
	iris.Plugins.Add(iris.PreListenFunc(func(*iris.Framework) {
		fmt.Println("PreListen Func")
	}))

	iris.Plugins.Add(iris.PostListenFunc(func(*iris.Framework) {
		fmt.Println("PostListen Func")
	}))

	iris.Plugins.Add(iris.PreCloseFunc(func(*iris.Framework) {
		fmt.Println("PreClose Func")
	}))

	myplugin := &testPluginEx{}
	iris.Plugins.Add(myplugin)
	desc := iris.Plugins.GetDescription(myplugin)
	fmt.Println(desc)

	// travis have problems if I do that using
	// Listen(":8080") and Close()
	iris.Plugins.DoPreListen(iris.Default)
	iris.Plugins.DoPostListen(iris.Default)
	iris.Plugins.DoPreClose(iris.Default)

	// Output:
	// GetName Struct
	// Activate Struct
	// GetDescription Struct
	// Description for My test plugin
	// PreListen Func
	// PreListen Struct
	// PostListen Func
	// PostListen Struct
	// PreClose Func
	// PreClose Struct
}