Ejemplo n.º 1
0
func TestContextMustGetter(t *testing.T) {
	mr := config.NewMockGetter()
	ctx := config.WithContextGetter(context.Background(), mr)
	mrHave := config.FromContextGetter(ctx)
	assert.Exactly(t, mr, mrHave)

	ctx = config.WithContextGetter(context.Background(), nil)
	mrHave = config.FromContextGetter(ctx)
	assert.Exactly(t, config.DefaultService, mrHave)
}
Ejemplo n.º 2
0
func main() {
	a := newApp()
	defer a.close() // @todo check signal and close gracefully

	ctx := store.WithContextMustService(
		scope.Option{Website: scope.MockID(1)}, // run website ID 1, see database table, like Mage::run('code','store')
		store.MustNewStorage(store.WithDatabaseInit(a.dbc.NewSession())),
	)

	ctx = config.WithContextGetter(ctx, a.config)

	router := ctxrouter.New(ctx)
	a.routeLogin(router)
	a.setupStoreRoutes(router)

	router.Handle("GET", "/error", func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		return store.ErrContextServiceNotFound
	})

	println("Starting server @ ", ServerAddress)

	log.Fatal("ListenAndServe", "err", http.ListenAndServe(ServerAddress, router))

}