Пример #1
0
func sortQuery(u *url.URL) {
	q := u.Query()

	if len(q) > 0 {
		arKeys := make([]string, len(q))
		i := 0
		for k, _ := range q {
			arKeys[i] = k
			i++
		}
		sort.Strings(arKeys)
		buf := new(bytes.Buffer)
		for _, k := range arKeys {
			sort.Strings(q[k])
			for _, v := range q[k] {
				if buf.Len() > 0 {
					buf.WriteRune('&')
				}
				buf.WriteString(fmt.Sprintf("%s=%s", k, urlesc.QueryEscape(v)))
			}
		}

		// Rebuild the raw query string
		u.RawQuery = buf.String()
	}
}
Пример #2
0
func editQuery(u *url.URL, shouldSort bool, c Customizer) {
	q := make(url.Values)
	parseQuery(q, u.RawQuery)

	if c != nil {
		// possibly pre-process the values
		c.EditValues(q)
	}

	if len(q) > 0 {
		arKeys := make([]string, len(q))
		i := 0
		for k, _ := range q {
			arKeys[i] = k
			i++
		}
		if shouldSort {
			sort.Strings(arKeys)
		}
		buf := new(bytes.Buffer)
		for _, k := range arKeys {
			if shouldSort {
				sort.Strings(q[k])
			}
			for _, v := range q[k] {
				if buf.Len() > 0 {
					buf.WriteRune('&')
				}
				if v == noQueryValue {
					buf.WriteString(k)
				} else {
					buf.WriteString(fmt.Sprintf("%s=%s", k, urlesc.QueryEscape(v)))
				}
			}
		}

		// Rebuild the raw query string
		u.RawQuery = buf.String()
	} else {
		u.RawQuery = ""
	}
}
Пример #3
0
func removeUtmFromQuery(u *url.URL) {
	q := u.Query()

	if len(q) > 0 {
		buf := new(bytes.Buffer)
		for key, value := range q {
			if key != "utm_source" &&
				key != "utm_medium" &&
				key != "utm_term" &&
				key != "utm_content" &&
				key != "utm_campaign" {
				for _, v := range value {
					if buf.Len() > 0 {
						_, _ = buf.WriteRune('&')
					}
					_, _ = buf.WriteString(fmt.Sprintf("%s=%s", key, urlesc.QueryEscape(v)))
				}
			}
		}

		// Rebuild the raw query string
		u.RawQuery = buf.String()
	}
}