api.go
changeset 243 7386c6a454a8
parent 240 80c81e9b77b4
child 248 f287d505dfda
equal deleted inserted replaced
242:2ec8b4cdf94e 243:7386c6a454a8
    89 	// Build the HTTP request object.
    89 	// Build the HTTP request object.
    90 	if len(request.QueryParams) != 0 {
    90 	if len(request.QueryParams) != 0 {
    91 		// Add parameters to the URL
    91 		// Add parameters to the URL
    92 		request.BaseURL += "?"
    92 		request.BaseURL += "?"
    93 		urlp := url.Values{}
    93 		urlp := url.Values{}
       
    94 		arrayRe := regexp.MustCompile(`^\[\d+\](.*)$`)
    94 		for key, value := range request.QueryParams {
    95 		for key, value := range request.QueryParams {
    95 			// It seems Mastodon doesn't like parameters with index
    96 			// It seems Mastodon doesn't like parameters with index
    96 			// numbers, but it needs the brackets.
    97 			// numbers, but it needs the brackets.
    97 			// Let's check if the key matches '^.+\[.*\]$'
    98 			// Let's check if the key matches '^.+\[.*\]$'
    98 			// Do not proceed if there's another bracket pair.
    99 			// Do not proceed if there's another bracket pair.
    99 			klen := len(key)
   100 			klen := len(key)
   100 			if klen == 0 {
   101 			if klen == 0 {
   101 				continue
   102 				continue
   102 			}
   103 			}
   103 			i := strings.Index(key, "[")
   104 			if m := arrayRe.FindStringSubmatch(key); len(m) > 0 {
   104 			if i > 0 && key[klen-1] == ']' && strings.Index(key[i+1:], "[") < 0 {
       
   105 				// This is an array, let's remove the index number
   105 				// This is an array, let's remove the index number
   106 				key = key[:i] + "[]"
   106 				key = m[1] + "[]"
   107 			}
   107 			}
   108 			urlp.Add(key, value)
   108 			urlp.Add(key, value)
   109 		}
   109 		}
   110 		urlpstr := urlp.Encode()
   110 		urlpstr := urlp.Encode()
   111 		request.BaseURL += urlpstr
   111 		request.BaseURL += urlpstr