func worker(
	jobs <-chan string, results chan<- string,
	db *bolt.DB, c *cache.Cache, locales []string, limit int,
) {
	for query := range jobs {
		ds.CachedCitiesSearch(db, c, locales, query, 5)
		results <- query
	}
}
Exemple #2
0
func MakeCitiesEndpoint(
	db *bolt.DB, options *config.Options, cache *cache.Cache,
) func(*gin.Context) {
	return func(c *gin.Context) {
		query := ds.PrepareCityNameKey(c.Query("q"))

		if query == "" {
			c.JSON(200, nil)
		} else {
			cities, err := ds.CachedCitiesSearch(db, cache, options.Locales, query, 5)

			if err != nil {
				c.JSON(500, nil)
			} else {
				c.JSON(200, cities.ForSerialization(c.Request.URL, options))
			}
		}
	}
}