Пример #1
0
func TestFlash(t *testing.T) {
	codecKey1 := "ePAPW9vJv7gHoftvQTyNj5VkWB52mlza"
	codecKey2 := "N8SmpJ00aSpepNrKoyYxmAJhwVuKEWZD"
	jar, err := cookiejar.New(nil)
	if err != nil {
		t.Error(err)
	}
	client := &http.Client{Jar: jar}
	o := &router.Options{
		Log:          logger.NewDefaultLogger(os.Stdout),
		SessionStore: sessions.NewCookieStore([]byte(codecKey1), []byte(codecKey2)),
	}
	r := router.NewRouter(o)
	r.Add(NewFlashTest)
	ts := httptest.NewServer(r)
	defer ts.Close()
	_, err = client.Get(fmt.Sprintf("%s/", ts.URL))
	if err != nil {
		t.Error(err)
	}
	_, err = client.Get(fmt.Sprintf("%s/flash", ts.URL))
	if err != nil {
		t.Error(err)
	}

	if len(result) != 3 {
		t.Errorf("expected 3 got %d", len(result))
	}
}
Пример #2
0
	"github.com/gernest/utron/logger"
	"github.com/gernest/utron/models"
	"github.com/gernest/utron/view"
	"github.com/gorilla/mux"
	"github.com/gorilla/sessions"
	"github.com/hashicorp/hcl"
	"github.com/justinas/alice"
	"gopkg.in/yaml.v2"
)

var (

	// ErrRouteStringFormat is returned when the route string is of the wrong format
	ErrRouteStringFormat = errors.New("wrong route string, example is\" get,post;/hello/world;Hello\"")

	defaultLogger = logger.NewDefaultLogger(os.Stdout)
)

// Router registers routes and handlers. It embeds gorilla mux Router
type Router struct {
	*mux.Router
	config  *config.Config
	routes  []*route
	Options *Options
}

//Options additional settings for the router.
type Options struct {
	Model        *models.Model
	View         view.View
	Config       *config.Config