Welcome To Golang By Example

Menu
  • Home
  • Blog
  • Contact Us
  • Support this website
Menu

Convert Query Param String to Query Param Hash in Go (Golang)

Posted on July 23, 2021July 23, 2021 by admin

Table of Contents

  • Overview
  • Program

Overview

Assume we have below query param string

a=b&x=y

We want the output as a map as below

map[a:b x:y]

Program

Below is the program for the same

package main

import (
	"fmt"
	"strings"
)

func main() {
	query_param_map := make(map[string]string)

	input := "a=b&x=y"

	input_split := strings.Split(input, "&")

	for _, v := range input_split {
		v_split := strings.Split(v, "=")
		query_param_map[v_split[0]] = v_split[1]

	}
	fmt.Println(query_param_map)

}

Output

map[a:b x:y]
  • go
  • golang
  • Follow @golangbyexample

    Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2025 Welcome To Golang By Example | Design: Newspaperly WordPress Theme