From b66e370ffc7be134153714d5e7e74e70178264a6 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 23 Jul 2019 11:43:30 +0300 Subject: [PATCH] * dnsfilter: refactor: a simple approach to convert Reason to string --- dnsfilter/dnsfilter.go | 17 +++++++++++++++++ dnsfilter/reason_string.go | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 dnsfilter/reason_string.go diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index bc03e448..a642abe4 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -133,6 +133,23 @@ const ( FilteredSafeSearch ) +func (i Reason) String() string { + names := []string{ + "NotFilteredNotFound", + "NotFilteredWhiteList", + "NotFilteredError", + "FilteredBlackList", + "FilteredSafeBrowsing", + "FilteredParental", + "FilteredInvalid", + "FilteredSafeSearch", + } + if uint(i) >= uint(len(names)) { + return "" + } + return names[i] +} + type dnsFilterContext struct { stats Stats dialCache gcache.Cache // "host" -> "IP" cache for safebrowsing and parental control servers diff --git a/dnsfilter/reason_string.go b/dnsfilter/reason_string.go deleted file mode 100644 index cb097e52..00000000 --- a/dnsfilter/reason_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by "stringer -type=Reason"; DO NOT EDIT. - -package dnsfilter - -import "strconv" - -const _Reason_name = "NotFilteredNotFoundNotFilteredWhiteListNotFilteredErrorFilteredBlackListFilteredSafeBrowsingFilteredParentalFilteredInvalidFilteredSafeSearch" - -var _Reason_index = [...]uint8{0, 19, 39, 55, 72, 92, 108, 123, 141} - -func (i Reason) String() string { - if i < 0 || i >= Reason(len(_Reason_index)-1) { - return "Reason(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Reason_name[_Reason_index[i]:_Reason_index[i+1]] -}