func TestNew(t *testing.T) { c1 := container551.New() c2 := container551.New() if c1 == nil { t.Error("インスタンスの生成に失敗しました。") } if c2 == nil { t.Error("インスタンスの生成に失敗しました。") } if &c1 == &c2 { t.Error("インスタンスの生成に失敗しました。") } }
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) } }
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) }
func BenchmarkNew(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { _ = container551.New() } }