check locale in news headlines

This commit is contained in:
Asim Aslam
2022-03-03 10:16:15 +00:00
parent bbe83c2af6
commit 6a87833d07
2 changed files with 72 additions and 0 deletions

View File

@@ -79,6 +79,17 @@ func (n *News) Headlines(ctx context.Context, req *pb.HeadlinesRequest, rsp *pb.
date = req.Date
}
var seen bool
for _, locale := range Locales {
if locale == req.Locale {
seen = true
break
}
}
if !seen {
return errors.BadRequest("news.headlines", "invalid locale")
}
vals := url.Values{}
vals.Set("api_token", n.apiKey)
vals.Set("locale", locale)

61
news/handler/types.go Normal file
View File

@@ -0,0 +1,61 @@
package handler
var (
Locales = []string{
"ar",
"am",
"au",
"at",
"by",
"be",
"bo",
"br",
"bg",
"ca",
"cl",
"cn",
"co",
"hr",
"cz",
"ec",
"eg",
"fr",
"de",
"gr",
"hn",
"hk",
"in",
"id",
"ir",
"ie",
"il",
"it",
"jp",
"kr",
"mx",
"nl",
"nz",
"ni",
"pk",
"pa",
"pe",
"pl",
"pt",
"qa",
"ro",
"ru",
"sa",
"za",
"es",
"ch",
"sy",
"tw",
"th",
"tr",
"ua",
"gb",
"us",
"uy",
"ve",
}
)