From de2221f243492ecc6c4017227e80d0677297c942 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 18 Feb 2021 09:37:20 +1000 Subject: [PATCH] fix main.css not being served on /topics/ panic when we try to reference an agent which doesn't exist in gen router init --- gen_router.go | 23 +++++++++++++++-------- router_gen/main.go | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/gen_router.go b/gen_router.go index 4d66c0ae..cb8048f0 100644 --- a/gen_router.go +++ b/gen_router.go @@ -873,15 +873,22 @@ func init() { co.SetReverseAgentMapEnum(reverseAgentMapEnum) co.SetOSMapEnum(osMapEnum) co.SetReverseOSMapEnum(reverseOSMapEnum) - c.Chrome = agentMapEnum["chrome"] - c.Firefox = agentMapEnum["firefox"] - ame := agentMapEnum + + g := func(n string) int { + a, ok := agentMapEnum[n] + if !ok { + panic("name not found in agentMapEnum") + } + return a + } + c.Chrome = g("chrome") + c.Firefox = g("firefox") c.SimpleBots = []int{ - ame["semrush"], - ame["ahrefs"], - ame["python"], - ame["go"], - ame["curl"], + g("semrush"), + g("ahrefs"), + g("python"), + //g("go"), + g("curl"), } } diff --git a/router_gen/main.go b/router_gen/main.go index 3c497022..4cca9442 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -465,15 +465,22 @@ func init() { co.SetReverseAgentMapEnum(reverseAgentMapEnum) co.SetOSMapEnum(osMapEnum) co.SetReverseOSMapEnum(reverseOSMapEnum) - c.Chrome = agentMapEnum["chrome"] - c.Firefox = agentMapEnum["firefox"] - ame := agentMapEnum + + g := func(n string) int { + a, ok := agentMapEnum[n] + if !ok { + panic("name not found in agentMapEnum") + } + return a + } + c.Chrome = g("chrome") + c.Firefox = g("firefox") c.SimpleBots = []int{ - ame["semrush"], - ame["ahrefs"], - ame["python"], - ame["go"], - ame["curl"], + g("semrush"), + g("ahrefs"), + g("python"), + //g("go"), + g("curl"), } }