Country code to flag emojie in Go
Friday 4 November 2022

I’m in the process of rewriting my news website web interface in #go.

The interface is written in Ruby/Rails right now and I’m looking for improving my Go writing skills so I decided to rewrite this part in Go.

I have a function in my code that convert the country code like “eg” to it’s flag emojie (you can see that at the bottom of the website or in the sidebar).

This code looks like so:

1def flag(code)
2'A-Z', "\u{1F1E6}-\u{1F1FF}")

After translating it to Go it looks like this:

 1import (
 2	""
 3	""
 6var FlagReplacer = runes.Map(func(r rune) rune {
 7	return r - 'a' + '\U0001F1E6'
10func Flag(code string) string {
11	s, _, _ := transform.String(FlagReplacer, code)
13	return s

this will return the flag emojie that correspond to the country code. for example “eg” will return “🇪🇬”

See Also