'white space separated colon key value pairs string to map

I have an output as follows:

scope -> profile_id:ed829e455a3db779 result:all

I wish to split this into a key value map:

such that m["profile_id"].(string) would give me the value ed829e455a3db779

go


Solution 1:[1]

For those seeking the same info:

scopes := newToken.Extra("scope").(string)
entries := strings.Split(scopes, " ")
m := make(map[string]string)
for _, e := range entries {
    parts := strings.Split(e, ":")
    m[parts[0]] = parts[1]
}
profileID := m["profile_id"]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Will