Esempio n. 1
0
// NewTestApp creates a new app should be used in unit tests.
func NewTestApp() *TestApp {
	router := mux.NewRouter()
	registry := &registry.NopRegistry{}
	config := scroll.AppConfig{
		Name:     "test",
		Router:   router,
		Registry: registry}

	return &TestApp{
		RestHelper{},
		scroll.NewAppWithConfig(config),
		httptest.NewServer(router),
	}
}
Esempio n. 2
0
// Create a new app with the provided configuration.
func NewAppWithConfig(config AppConfig) *App {
	router := config.Router
	if router == nil {
		router = mux.NewRouter()
	}

	interval := config.Interval
	if interval == 0 {
		interval = defaultRegisterInterval
	}

	registration := &registry.AppRegistration{Name: config.Name, Host: config.ListenIP, Port: config.ListenPort}
	heartbeater := registry.NewHeartbeater(registration, config.Registry, interval)

	return &App{
		Config:      config,
		router:      router,
		heartbeater: heartbeater,
		stats:       newAppStats(config.Client),
	}
}