Пример #1
0
func rootFunc(w http.ResponseWriter, r *http.Request) {

	g := Load()

	l := log551.New(&g.config.Framework.SystemLog)
	l.Open()
	defer l.Close()

	cookie := cookie551.New(w, r)

	sid := g.sid(cookie)
	l.Debugf("%s SID: %s", sid[:10], sid)
	session := memcache551.New(&g.config.Framework.Session.Server, sid)

	route := g.router.FindRouteByPathMatch(r.Method, r.URL.Path)
	response551.UrlFunction = g.router.Url

	var data interface{} = nil
	if route != nil {
		mysql := mysql551.New(&g.config.Framework.Database)
		mysql.Open()
		defer mysql.Close()

		l.Debugf("%s --[ Routing ]--", sid[:10])
		l.Debugf("%s Path: %s", sid[:10], r.URL.Path)
		l.Debugf("%s Neme: %s", sid[:10], route.Name())

		c := container551.New()
		c.SetSID(sid)
		c.SetResponseWriter(w)
		c.SetRequest(r)
		c.SetLogger(l)
		c.SetCookie(cookie)
		c.SetDb(mysql)
		c.SetSession(session)
		c.SetModel(g.modelManager)
		c.SetAuth(g.auth)
		c.SetUrlFunc(g.router.Url)

		baseUrl := "https://" + g.config.Framework.WebServerSSL.Host
		if g.config.Framework.WebServerSSL.Port != "443" {
			baseUrl = baseUrl + ":" + g.config.Framework.WebServerSSL.Port
		}
		c.SetBaseURL(baseUrl)
		response551.BaseUrl = baseUrl

		action := route.Action()
		data = action(c)
		response551.Response(w, r, data, route.PackageName(), route.Name(), c.User(), g.config.Application)
	} else {
		l.Errorf("%s --[ Route not found ]--", sid[:10])
		l.Errorf("%s UA:     %s", sid[:10], r.UserAgent())
		l.Errorf("%s Method: %s", sid[:10], r.Method)
		l.Errorf("%s Path:   %s", sid[:10], r.URL.Path)
		l.Errorf("%s --[/Route not found ]--", sid[:10])
		data = response551.Error(404, "Route not found.")
		response551.Response(w, r, data, "", "", nil, g.config.Application)
	}

}
Пример #2
0
func TestSet(t *testing.T) {
	config := memcache551.Config{
		Host:    "localhost:11211",
		Prefix:  "gorai",
		Expires: 3600,
	}

	m := memcache551.New(&config, sid)
	m.Set("test", "test_string")
}
Пример #3
0
func consoleHandler() {

	g := Load()

	l := log551.New(&g.config.Framework.CommandLog)
	l.Open()
	defer l.Close()

	sid := secure551.Hash()

	// Routing
	name := os.Args[1]
	l.Debugf("%s [ Command ] %s", sid[:10], name)
	route := g.router.FindRouteByName(router551.COMMAND.String(), name)
	if route == nil {
		l.Errorf("%s %s", sid[:10], "Action not found...")
		return
	}

	// Options
	optionArgs := os.Args[2:]
	if len(optionArgs)%2 == 1 {
		l.Errorf("%s %s", sid[:10], "Missing options.")
	}
	options := make(map[string]string, len(optionArgs)/2)
	for i := 0; i < len(optionArgs); i += 2 {
		options[optionArgs[i][1:]] = optionArgs[i+1]
	}

	mysql := mysql551.New(&g.config.Framework.Database)
	mysql.Open()
	defer mysql.Close()

	session := memcache551.New(&g.config.Framework.Session.Server, sid)

	c := container551.New()
	c.SetSID(sid)
	c.SetResponseWriter(nil)
	c.SetRequest(nil)
	c.SetLogger(l)
	c.SetCookie(nil)
	c.SetDb(mysql)
	c.SetSession(session)
	c.SetModel(g.modelManager)
	c.SetCommandOptions(options)
	if g.config.Framework.WebServerSSL.Port == "443" {
		c.SetBaseURL("https://" + g.config.Framework.WebServerSSL.Host)
	} else {
		c.SetBaseURL("https://" + g.config.Framework.WebServerSSL.Host + ":" + g.config.Framework.WebServerSSL.Port)
	}

	action := route.Action()
	action(c)

}
Пример #4
0
func TestLoad(t *testing.T) {
	config := memcache551.Config{
		Host:    "localhost:11211",
		Prefix:  "gorai",
		Expires: 3600,
	}

	m1 := memcache551.New(&config, sid)
	m2 := memcache551.New(&config, sid)

	if m1 == nil {
		t.Errorf("インスタンス生成に失敗しました。")
	}
	if m2 == nil {
		t.Errorf("インスタンス生成に失敗しました。")
	}
	if &m1 == &m2 {
		t.Errorf("インスタンス生成に失敗しました。\n[%p], [%p]", &m1, &m2)
	}
}
Пример #5
0
func BenchmarkLoad(b *testing.B) {
	config := memcache551.Config{
		Host:    "localhost:11211",
		Prefix:  "gorai",
		Expires: 3600,
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = memcache551.New(&config, sid)
	}
}
Пример #6
0
func TestGet(t *testing.T) {
	config := memcache551.Config{
		Host:    "localhost:11211",
		Prefix:  "gorai",
		Expires: 3600,
	}

	m := memcache551.New(&config, sid)
	ret := m.Get("test")

	if ret != "test_string" {
		t.Errorf("取得に失敗しました。")
	}
}
Пример #7
0
func BenchmarkSet(b *testing.B) {
	config := memcache551.Config{
		Host:    "localhost:11211",
		Prefix:  "gorai",
		Expires: 3600,
	}
	m := memcache551.New(&config, sid)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		m.Set("benchmark", "test_string")
	}

}