Last active
February 4, 2020 00:57
-
-
Save jgilless/cf59d912de74aec36d751c75c63e2d8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
type mapDiff struct { | |
a string | |
b string | |
} | |
func compareMapsAndGetDiff(m1, m2 map[string]string) map[string]mapDiff { | |
m := make(map[string]mapDiff) | |
for i, v := range m1 { | |
if m2[i] == v { | |
continue | |
} | |
m[i] = mapDiff{a: v} | |
} | |
for i, v := range m2 { | |
if m1[i] == v { | |
continue | |
} | |
if val, ok := m[i]; ok { | |
val.b = v | |
m[i] = mapDiff{ a: m[i].a, b: v } | |
} else { | |
m[i] = mapDiff{b: v} | |
} | |
} | |
return m | |
} | |
func getMap(s string) map[string]string { | |
m := make(map[string]string) | |
sm := strings.Split(s, "&") | |
for _, v := range sm { | |
kv := strings.Split(v, "=") | |
if len(kv) != 2 { | |
continue | |
} | |
m[kv[0]] = kv[1] | |
} | |
return m | |
} | |
func printDiff(a map[string]mapDiff) string { | |
s := "" | |
for i, v := range a { | |
s += fmt.Sprintf("%s:\n\ta: %s\n\tb: %s\n", i, v.a, v.b) | |
} | |
return s | |
} | |
func main() { | |
s1 := "https://www.google-analytics.com/collect?v=1&_v=j80&a=1685654710&t=pageview&_s=1&dl=http%3A%2F%2Flocalhost%2Fcelebrity-style-rules&ul=en-us&de=UTF-8&dt=The%20One%20Thing%2010%20Celebrities%20Never%20Wear%20%7C%20Who%20What%20Wear&sd=24-bit&sr=1920x1080&vp=1157x981&je=0&_u=SCCAgEADQ~&jid=188526255&gjid=1945574688&cid=908993462.1575507609&tid=UA-1024221-1&_gid=477193130.1580763383>m=2wg1m0K3S2JMX&cd3=shop-curations&cd5=kristen-nichols&cd6=celebrity-style&cd7=Who%20What%20Wear%2Cmuses%2CShop%20Curations%2CFashion%20Trends%2CStyle%20Tips%2CCelebrity%20Style%2CCelebrity&cd8=2019-10-19T05%3A00%3A00Z&cd9=273477&cd10=%2Fcelebrity-style-rules&cd11=0&cd12=&cd14=generalized_story&cd20=The%20One%20Thing%2010%20Celebrities%20Never%20Wear&cd26=2019-10-16T11%3A59%3A02Z&cd27=0&cd28=2020-02-03T16%3A40%3A59.70-08%3A00&cd32=&cd33=2&cd34=20&cd35=16&cd40=GA1.1.908993462.1575507609&cd41=_x_202002jicarbsg3qi6vgpgjtm2lxt32q&cd52=muses&cd55=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F79.0.3945.117%20Safari%2F537.36&cd58=fashion-trends&cd59=style-tips&z=1332779534" | |
s2 := "https://www.google-analytics.com/collect?v=1&_v=j80&a=1011779326&t=event&ni=0&_s=1&dl=http%3A%2F%2Flocalhost%2Fcelebrity-style-rules%2Fslide16&ul=en-us&de=UTF-8&dt=The%20One%20Thing%2010%20Celebrities%20Never%20Wear%20%7C%20Who%20What%20Wear&sd=24-bit&sr=1920x1080&vp=858x981&je=0&ec=Newsletter&ea=Newsletter%20Signup&el=Footer&_u=SCCAAEADQ~&jid=&gjid=&cid=908993462.1575507609&tid=UA-1024221-1&_gid=477193130.1580763383>m=2wg1m0K3S2JMX&cd3=shop-curations&cd5=kristen-nichols&cd6=celebrity-style&cd7=Who%20What%20Wear%2Cmuses%2CShop%20Curations%2CFashion%20Trends%2CStyle%20Tips%2CCelebrity%20Style%2CCelebrity&cd8=2019-10-19T05%3A00%3A00Z&cd9=273477&cd10=%2Fcelebrity-style-rules&cd11=0&cd12=&cd14=generalized_story&cd20=The%20One%20Thing%2010%20Celebrities%20Never%20Wear&cd26=2019-10-16T11%3A59%3A02Z&cd27=0&cd28=2020-02-03T15%3A07%3A11.190-08%3A00&cd30=page-bar&cd32=http%3A%2F%2Flocalhost%3A8900%2F&cd34=20&cd35=9&cd37=footerrectangle-3&cd40=GA1.1.908993462.1575507609&cd41=_x_202001m7n4cr2c7ui6vief3p42lxt32q&cd52=muses&cd55=Mozilla%2F5.0%20(X11%3B%20Linux%20x86_64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F79.0.3945.117%20Safari%2F537.36&cd58=fashion-trends&cd59=style-tips&cm7=1&cm5=1&z=552724908" | |
s1Map := getMap(s1) | |
s2Map := getMap(s2) | |
result := compareMapsAndGetDiff(s1Map, s2Map) | |
fmt.Println(printDiff(result)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment