getQueryKey returns the etcd key for the query.
(q *protocol.KontrolQuery)
| 337 | |
| 338 | // getQueryKey returns the etcd key for the query. |
| 339 | func GetQueryKey(q *protocol.KontrolQuery) (string, error) { |
| 340 | fields := q.Fields() |
| 341 | |
| 342 | if q.Username == "" { |
| 343 | return "", errors.New("Empty username field") |
| 344 | } |
| 345 | |
| 346 | // Validate query and build key. |
| 347 | path := "/" |
| 348 | |
| 349 | empty := false // encountered with empty field? |
| 350 | empytField := "" // for error log |
| 351 | |
| 352 | // http://golang.org/doc/go1.3#map, order is important and we can't rely on |
| 353 | // maps because the keys are not ordered :) |
| 354 | for _, key := range keyOrder { |
| 355 | v := fields[key] |
| 356 | if v == "" { |
| 357 | empty = true |
| 358 | empytField = key |
| 359 | continue |
| 360 | } |
| 361 | |
| 362 | if empty && v != "" { |
| 363 | return "", fmt.Errorf("Invalid query. Query option is not set: %s", empytField) |
| 364 | } |
| 365 | |
| 366 | path = path + v + "/" |
| 367 | } |
| 368 | |
| 369 | path = strings.TrimSuffix(path, "/") |
| 370 | |
| 371 | return path, nil |
| 372 | } |
| 373 | |
| 374 | func getAudience(q *protocol.KontrolQuery) string { |
| 375 | if q.Name != "" { |