Tools Coverters

Decoding URLs with Golang - A Comprehensive Guide

Decoding URLs with Golang - A Comprehensive Guide Image

Published Date: September 9, 2022

Updated Date: September 9, 2022

Golang as a language provides means to encode your strings. Go's net/url package provides a method called as QueryEscape to encode a string or a URL.

How to encode a string or a URL in Golang using the QueryEscape

Here is an example of how you can encode a string in Golang using the QueryEscape

package main

import (
	"fmt"
	"net/url"
)

func main() {
	query := "Tööls Cönverters xyz URLEncoder@Go"
	fmt.Println(url.QueryEscape(query))
}

Output:

#Output
T%C3%B6%C3%B6ls%20C%C3%B6nverters%20xyz%20URLEncoder%40Go

How to decode a string or a URL in Golang using the QueryUnescape

Similar to the QueryEscape we can use the QueryUnescape method from the net/url from the Go library.

Here is an example of how you can encode a string in Golang using the QueryEscape

package main

import (
	"fmt"
	"net/url"
)

func main() {
	query := "T%C3%B6%C3%B6ls%20C%C3%B6nverters%20xyz%20URLEncoder%40GoTööls Cönverters xyz URLDecoder@Go"
	fmt.Println(url.QueryUnescape(query))
}

Output:

#Output
Tööls Cönverters xyz URLDecoder@Go

Related Decoding techniques:

Related Encoding techniques:

There are many applications that require you to encode your URL into a format that the systems can understand. If you wish to encode a URL, check out our free online URL Encoder.

Some systems communicate with encoded URLs, so you may need to decode a URL. If you want to decode a URL online, we have our free online URL Decoder.