func connectToDB(ctx context.Context) { version := appengine.VersionID(ctx) versionID := strings.Split(version, ".") log.Infof(ctx, "Current serving app version: %s", versionID[0]) if versionID[0] == "live" { DB_STRING = os.Getenv("LIVE_DB") } else { DB_STRING = os.Getenv("TEST_DB") } log.Infof(ctx, "connecting to DB with string %s", DB_STRING) db = backend.SqlInit(DB_STRING) }
Users: make(map[int]userData), } } const timeout = 6 * time.Hour // Global variable with cache info var data = newWebData() // Standard guest user var guest = stackongo.User{ Display_name: "Guest", } // Pointer to database connection to communicate with Cloud SQL var db = backend.SqlInit() //Stores the last time the database was read into the cache //This is then checked against the update time of the database and determine whether the cache should be updated var mostRecentUpdate int64 var recentChangedQns []string func (r genReply) CacheUpdated() bool { return mostRecentUpdate > r.UpdateTime } func (r genReply) Timestamp(timeUnix int64) time.Time { return time.Unix(timeUnix, 0) } //The app engine will run its own main function and imports this code as a package //So no main needs to be defined