Beispiel #1
0
func init() {
	// Mongo URL
	url, ok := config.GroupString("db", "mongoURL")
	if !ok {
		log.Fatal("wombat:apps:article: MongoURL missing from configuration")
	}

	// Database name
	db, ok := config.GroupString("db", "mongoDB")
	if !ok {
		db = "main"
	}

	col, ok := config.GroupString("db", "mongoCol")
	if !ok {
		col = "articles"
	}

	// Mongo error
	b, err := New(url, db, col)
	if err != nil {
		log.Fatal("Failed to create backend: %v", err)
	}

	// Register
	backends.Register("wombat:apps:article-reader", b)
	backends.Register("wombat:apps:article-printer", b)
}
Beispiel #2
0
func init() {
	if url, ok := config.GroupString("db", "mongoURL"); !ok {
		log.Fatal("users mongo: MongoURL missing from configuration")
	} else if session, err := mgo.Dial(url); err != nil {
		log.Fatal("Failed to retrieve Mongo session: ", err)
	} else {
		// set monotonic mode
		session.SetMode(mgo.Monotonic, true)
		// register backend
		b := Backend{session}
		backends.Register("mongo:user-reader", b)
		backends.Register("mongo:user-writer", b)
	}

	if d, ok := config.GroupString("db", "mongoDB"); ok {
		db = d
	}
}
Beispiel #3
0
func ExampleGroupString() {
	// for a `config.json` file like:
	/*
		{
			"host": "google.com",
			"links": {
				"google": "https://google.com"
			}
		}
	*/
	groupHost, ok := config.GroupString("links", "google")
	fmt.Println(groupHost, ok)
	// Output:
	// https://google.com true
}
Beispiel #4
0
func setString(group, key string, s *string) {
	if v, ok := config.GroupString(group, key); ok {
		*s = v
	}
}