// FindStation retrieves the specified station func FindStation(service *services.Service, stationId string) (buoyStation *buoyModels.BuoyStation, err error) { defer helper.CatchPanic(&err, service.UserId, "FindStation") tracelog.Started(service.UserId, "FindStation") queryMap := bson.M{"station_id": stationId} buoyStation = &buoyModels.BuoyStation{} err = service.DBAction(Config.Database, "buoy_stations", func(collection *mgo.Collection) error { tracelog.Trace(service.UserId, "FindStation", "Query : %s", mongo.ToString(queryMap)) return collection.Find(queryMap).One(buoyStation) }) if err != nil { if strings.Contains(err.Error(), "not found") == false { tracelog.CompletedError(err, service.UserId, "FindStation") return buoyStation, err } err = nil } tracelog.Completed(service.UserId, "FindStation") return buoyStation, err }
func main() { tracelog.Start(tracelog.LevelTrace) // Init mongo tracelog.Started("main", "Initializing Mongo") err := mongo.Startup(helper.MainGoRoutine) if err != nil { tracelog.CompletedError(err, helper.MainGoRoutine, "initApp") os.Exit(1) } // Load message strings localize.Init("en-US") SessionConfig, err := session.GetSessionConfig("session") tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.On) tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.Provider) tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.SavePath) beego.SessionOn = SessionConfig.On beego.SessionProvider = SessionConfig.Provider beego.SessionSavePath = SessionConfig.SavePath beego.Run() tracelog.Completed(helper.MainGoRoutine, "Website Shutdown") tracelog.Stop() }
// Startup brings the manager to a running state. func Startup(sessionID string) error { // If the system has already been started ignore the call. if singleton.sessions != nil { return nil } log.Started(sessionID, "Startup") // Pull in the configuration. var config mongoConfiguration if err := envconfig.Process("mgo", &config); err != nil { log.CompletedError(err, sessionID, "Startup") return err } // Create the Mongo Manager. singleton = mongoManager{ sessions: make(map[string]mongoSession), } // Create the strong session. if err := CreateSession(sessionID, "strong", MasterSession, config.Url); err != nil { log.CompletedError(err, sessionID, "Startup") return err } // Create the monotonic session. if err := CreateSession(sessionID, "monotonic", MonotonicSession, config.Url); err != nil { log.CompletedError(err, sessionID, "Startup") return err } log.Completed(sessionID, "Startup") return nil }
func main() { tracelog.StartFile(tracelog.LevelTrace, "logs", 1) tracelog.Started("main", "Initializing Postgres") var confName string = os.Getenv("BOOKS_CONF") if len(confName) == 0 { confName = "default" } s := []string{"conf/db/", confName, ".json"} jsonconf, err := config.NewConfig("json", strings.Join(s, "")) if err != nil { tracelog.Errorf(err, "main", "config.NewConfig", "Failed to find config", strings.Join(s, "")) } var User string = jsonconf.String("User") var Pass string = jsonconf.String("Pass") var DBName string = jsonconf.String("DBName") var buffer bytes.Buffer buffer.WriteString("user="******" password="******" dbname=") buffer.WriteString(DBName) s2 := []string{"user="******" password="******" dbname=", DBName, " sslmode=disable"} orm.RegisterDriver("postgres", orm.DR_Postgres) orm.RegisterDataBase("default", "postgres", strings.Join(s2, "")) beego.SetStaticPath("/images", "static/images") beego.SetStaticPath("/css", "static/css") beego.SetStaticPath("/js", "static/js") beego.SetStaticPath("/fonts", "static/fonts") beego.SetStaticPath("/partials", "static/partials") beego.EnableAdmin = true orm.RunCommand() beego.Run() }
// CloseSession puts the connection back into the pool func CloseSession(sessionId string, mongoSession *mgo.Session) { defer helper.CatchPanic(nil, sessionId, "CloseSession") tracelog.Started(sessionId, "CloseSession") mongoSession.Close() tracelog.Completed(sessionId, "CloseSession") }
// Shutdown systematically brings the manager down gracefully. func Shutdown(sessionID string) error { log.Started(sessionID, "Shutdown") // Close the databases for _, session := range singleton.sessions { CloseSession(sessionID, session.mongoSession) } log.Completed(sessionID, "Shutdown") return nil }
// Shutdown systematically brings the manager down gracefully func Shutdown(sessionId string) (err error) { defer helper.CatchPanic(&err, sessionId, "Shutdown") tracelog.Started(sessionId, "Shutdown") // Close the databases for _, session := range singleton.sessions { CloseSession(sessionId, session.mongoSession) } tracelog.Completed(sessionId, "Shutdown") return err }
// init initializes all required packages and systems func init() { // log.Start(log.LEVEL_TRACE) // Init mongo log.Started("main", "Initializing Mongo") err := mongo.Startup(helper.MainGoRoutine) if err != nil { log.CompletedError(err, helper.MainGoRoutine, "initTesting") return } // Load message strings localize.Init("en-US") }
func main() { tracelog.Start(tracelog.LEVEL_TRACE) // Init mongo tracelog.Started("main", "Initializing Mongo") err := mongo.Startup(helper.MAIN_GO_ROUTINE) if err != nil { tracelog.CompletedError(err, helper.MAIN_GO_ROUTINE, "initApp") os.Exit(1) } // Load message strings localize.Init("en-US") beego.Run() tracelog.Completed(helper.MAIN_GO_ROUTINE, "Website Shutdown") tracelog.Stop() }
func main() { tracelog.Start(tracelog.LevelTrace) // Init mongo tracelog.Started("main", "Initializing Mongo") err := mongo.Startup(helper.MainGoRoutine) if err != nil { tracelog.CompletedError(err, helper.MainGoRoutine, "initApp") os.Exit(1) } // Load message strings localize.Init("en-US") beego.Run() tracelog.Completed(helper.MainGoRoutine, "Website Shutdown") tracelog.Stop() }
// Startup brings the manager to a running state. func Startup(sessionID string) error { // If the system has already been started ignore the call. if singleton.sessions != nil { return nil } log.Started(sessionID, "Startup") // Pull in the configuration. var config mongoConfiguration if err := envconfig.Process("mgo", &config); err != nil { log.CompletedError(err, sessionID, "Startup") return err } // Create the Mongo Manager. singleton = mongoManager{ sessions: make(map[string]mongoSession), } // Log the mongodb connection straps. log.Trace(sessionID, "Startup", "MongoDB : Hosts[%s]", config.Hosts) log.Trace(sessionID, "Startup", "MongoDB : Database[%s]", config.Database) log.Trace(sessionID, "Startup", "MongoDB : Username[%s]", config.UserName) hosts := strings.Split(config.Hosts, ",") // Create the strong session. if err := CreateSession(sessionID, "strong", MasterSession, hosts, config.Database, config.UserName, config.Password); err != nil { log.CompletedError(err, sessionID, "Startup") return err } // Create the monotonic session. if err := CreateSession(sessionID, "monotonic", MonotonicSession, hosts, config.Database, config.UserName, config.Password); err != nil { log.CompletedError(err, sessionID, "Startup") return err } log.Completed(sessionID, "Startup") return nil }
func main() { tracelog.Start(tracelog.LevelTrace) // Init mongo tracelog.Started("main", "Initializing Mongo") err := mongo.Startup(helper.MainGoRoutine) if err != nil { tracelog.CompletedError(err, helper.MainGoRoutine, "initApp") os.Exit(1) } // Load message strings localize.Init("en-US") beego.BConfig.WebConfig.Session.SessionOn = true globalSessions, _ = session.NewManager("redis", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:6379"}`) go globalSessions.GC() beego.Run() tracelog.Completed(helper.MainGoRoutine, "Website Shutdown") tracelog.Stop() }
// FindRegion retrieves the stations for the specified region func FindRegion(service *services.Service, region string) (buoyStations []*buoyModels.BuoyStation, err error) { defer helper.CatchPanic(&err, service.UserId, "FindRegion") tracelog.Started(service.UserId, "FindRegion") queryMap := bson.M{"region": region} buoyStations = []*buoyModels.BuoyStation{} err = service.DBAction(Config.Database, "buoy_stations", func(collection *mgo.Collection) error { tracelog.Trace(service.UserId, "FindRegion", "Query : %s", mongo.ToString(queryMap)) return collection.Find(queryMap).All(&buoyStations) }) if err != nil { tracelog.CompletedError(err, service.UserId, "FindRegion") return buoyStations, err } tracelog.Completed(service.UserId, "FindRegion") return buoyStations, err }
// Startup brings the manager to a running state func Startup(sessionId string) (err error) { defer helper.CatchPanic(&err, sessionId, "Startup") // If the system has already been started ignore the call if singleton != nil { return err } tracelog.Started(sessionId, "Startup") // Pull in the configuration config := mongoConfiguration{} err = envconfig.Process("mgo", &config) if err != nil { tracelog.CompletedError(err, sessionId, "Startup") return err } // Create the Mongo Manager singleton = &mongoManager{ sessions: map[string]*mongoSession{}, } // Log the mongodb connection straps tracelog.Trace(sessionId, "Startup", "MongoDB : Hosts[%s]", config.Hosts) tracelog.Trace(sessionId, "Startup", "MongoDB : Database[%s]", config.Database) tracelog.Trace(sessionId, "Startup", "MongoDB : Username[%s]", config.UserName) hosts := strings.Split(config.Hosts, ",") // Create the strong and monotonic sessions err = CreateSession(sessionId, "strong", MASTER_SESSION, hosts, config.Database, config.UserName, config.Password) err = CreateSession(sessionId, "monotonic", MONOTONIC_SESSION, hosts, config.Database, config.UserName, config.Password) tracelog.Completed(sessionId, "Startup") return err }
// CloseSession puts the connection back into the pool. func CloseSession(sessionID string, mongoSession *mgo.Session) { log.Started(sessionID, "CloseSession") mongoSession.Close() log.Completed(sessionID, "CloseSession") }