fixed comment, update validQueryArgs

This commit is contained in:
Linh Vo 2017-05-25 11:48:08 -05:00
parent 108c644938
commit e34e9f9789
2 changed files with 7 additions and 6 deletions

View file

@ -31,7 +31,7 @@ type ExportCommand struct {
// Name of the index & frame to export from.
Index string
Frame string
View string
View string
// Filename to export to.
Path string

View file

@ -844,7 +844,7 @@ func (h *Handler) readProtobufQueryRequest(r *http.Request) (*QueryRequest, erro
// readURLQueryRequest parses query parameters from URL parameters from r.
func (h *Handler) readURLQueryRequest(r *http.Request) (*QueryRequest, error) {
q := r.URL.Query()
validQuery := h.getValidURLQuery(r)
validQuery := validOptions(QueryRequest{})
for key, _ := range q {
if _, ok := validQuery[key]; !ok {
return nil, errors.New("invalid query params")
@ -882,12 +882,13 @@ func (h *Handler) readURLQueryRequest(r *http.Request) (*QueryRequest, error) {
}, nil
}
func (h *Handler) getValidURLQuery(r *http.Request) map[string]bool {
// validOptions return all attributes of an interface with lower first character.
func validOptions(v interface{}) map[string]bool {
validQuery := make(map[string]bool)
args := reflect.ValueOf(QueryRequest{})
argsType := reflect.ValueOf(v)
for i := 0; i < args.Type().NumField(); i++ {
fieldName := args.Type().Field(i).Name
for i := 0; i < argsType.Type().NumField(); i++ {
fieldName := argsType.Type().Field(i).Name
chars := []rune(fieldName)
chars[0] = unicode.ToLower(chars[0])
fieldName = string(chars)