Pull request: all: use http method constants
Merge in DNS/adguard-home from method-const to master Squashed commit of the following: commit ae6d6699a25ca04ba92aa53258d46e50233a9e00 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Jan 29 22:03:59 2021 +0300 all: use http method constants
This commit is contained in:
parent
0c127039cf
commit
2638e271fe
|
@ -242,6 +242,6 @@ func (d *DNSFilter) handleBlockedServicesSet(w http.ResponseWriter, r *http.Requ
|
||||||
|
|
||||||
// registerBlockedServicesHandlers - register HTTP handlers
|
// registerBlockedServicesHandlers - register HTTP handlers
|
||||||
func (d *DNSFilter) registerBlockedServicesHandlers() {
|
func (d *DNSFilter) registerBlockedServicesHandlers() {
|
||||||
d.Config.HTTPRegister("GET", "/control/blocked_services/list", d.handleBlockedServicesList)
|
d.Config.HTTPRegister(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList)
|
||||||
d.Config.HTTPRegister("POST", "/control/blocked_services/set", d.handleBlockedServicesSet)
|
d.Config.HTTPRegister(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet)
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ func (d *DNSFilter) handleRewriteDelete(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSFilter) registerRewritesHandlers() {
|
func (d *DNSFilter) registerRewritesHandlers() {
|
||||||
d.Config.HTTPRegister("GET", "/control/rewrite/list", d.handleRewriteList)
|
d.Config.HTTPRegister(http.MethodGet, "/control/rewrite/list", d.handleRewriteList)
|
||||||
d.Config.HTTPRegister("POST", "/control/rewrite/add", d.handleRewriteAdd)
|
d.Config.HTTPRegister(http.MethodPost, "/control/rewrite/add", d.handleRewriteAdd)
|
||||||
d.Config.HTTPRegister("POST", "/control/rewrite/delete", d.handleRewriteDelete)
|
d.Config.HTTPRegister(http.MethodPost, "/control/rewrite/delete", d.handleRewriteDelete)
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,15 +381,15 @@ func (d *DNSFilter) handleParentalStatus(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSFilter) registerSecurityHandlers() {
|
func (d *DNSFilter) registerSecurityHandlers() {
|
||||||
d.Config.HTTPRegister("POST", "/control/safebrowsing/enable", d.handleSafeBrowsingEnable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/safebrowsing/enable", d.handleSafeBrowsingEnable)
|
||||||
d.Config.HTTPRegister("POST", "/control/safebrowsing/disable", d.handleSafeBrowsingDisable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/safebrowsing/disable", d.handleSafeBrowsingDisable)
|
||||||
d.Config.HTTPRegister("GET", "/control/safebrowsing/status", d.handleSafeBrowsingStatus)
|
d.Config.HTTPRegister(http.MethodGet, "/control/safebrowsing/status", d.handleSafeBrowsingStatus)
|
||||||
|
|
||||||
d.Config.HTTPRegister("POST", "/control/parental/enable", d.handleParentalEnable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/parental/enable", d.handleParentalEnable)
|
||||||
d.Config.HTTPRegister("POST", "/control/parental/disable", d.handleParentalDisable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/parental/disable", d.handleParentalDisable)
|
||||||
d.Config.HTTPRegister("GET", "/control/parental/status", d.handleParentalStatus)
|
d.Config.HTTPRegister(http.MethodGet, "/control/parental/status", d.handleParentalStatus)
|
||||||
|
|
||||||
d.Config.HTTPRegister("POST", "/control/safesearch/enable", d.handleSafeSearchEnable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/safesearch/enable", d.handleSafeSearchEnable)
|
||||||
d.Config.HTTPRegister("POST", "/control/safesearch/disable", d.handleSafeSearchDisable)
|
d.Config.HTTPRegister(http.MethodPost, "/control/safesearch/disable", d.handleSafeSearchDisable)
|
||||||
d.Config.HTTPRegister("GET", "/control/safesearch/status", d.handleSafeSearchStatus)
|
d.Config.HTTPRegister(http.MethodGet, "/control/safesearch/status", d.handleSafeSearchStatus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,9 +297,9 @@ func (clients *clientsContainer) findTemporary(ip net.IP, idStr string) (cj clie
|
||||||
|
|
||||||
// RegisterClientsHandlers registers HTTP handlers
|
// RegisterClientsHandlers registers HTTP handlers
|
||||||
func (clients *clientsContainer) registerWebHandlers() {
|
func (clients *clientsContainer) registerWebHandlers() {
|
||||||
httpRegister("GET", "/control/clients", clients.handleGetClients)
|
httpRegister(http.MethodGet, "/control/clients", clients.handleGetClients)
|
||||||
httpRegister("POST", "/control/clients/add", clients.handleAddClient)
|
httpRegister(http.MethodPost, "/control/clients/add", clients.handleAddClient)
|
||||||
httpRegister("POST", "/control/clients/delete", clients.handleDelClient)
|
httpRegister(http.MethodPost, "/control/clients/delete", clients.handleDelClient)
|
||||||
httpRegister("POST", "/control/clients/update", clients.handleUpdateClient)
|
httpRegister(http.MethodPost, "/control/clients/update", clients.handleUpdateClient)
|
||||||
httpRegister("GET", "/control/clients/find", clients.handleFindClient)
|
httpRegister(http.MethodGet, "/control/clients/find", clients.handleFindClient)
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,14 +417,14 @@ func (f *Filtering) handleCheckHost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// RegisterFilteringHandlers - register handlers
|
// RegisterFilteringHandlers - register handlers
|
||||||
func (f *Filtering) RegisterFilteringHandlers() {
|
func (f *Filtering) RegisterFilteringHandlers() {
|
||||||
httpRegister("GET", "/control/filtering/status", f.handleFilteringStatus)
|
httpRegister(http.MethodGet, "/control/filtering/status", f.handleFilteringStatus)
|
||||||
httpRegister("POST", "/control/filtering/config", f.handleFilteringConfig)
|
httpRegister(http.MethodPost, "/control/filtering/config", f.handleFilteringConfig)
|
||||||
httpRegister("POST", "/control/filtering/add_url", f.handleFilteringAddURL)
|
httpRegister(http.MethodPost, "/control/filtering/add_url", f.handleFilteringAddURL)
|
||||||
httpRegister("POST", "/control/filtering/remove_url", f.handleFilteringRemoveURL)
|
httpRegister(http.MethodPost, "/control/filtering/remove_url", f.handleFilteringRemoveURL)
|
||||||
httpRegister("POST", "/control/filtering/set_url", f.handleFilteringSetURL)
|
httpRegister(http.MethodPost, "/control/filtering/set_url", f.handleFilteringSetURL)
|
||||||
httpRegister("POST", "/control/filtering/refresh", f.handleFilteringRefresh)
|
httpRegister(http.MethodPost, "/control/filtering/refresh", f.handleFilteringRefresh)
|
||||||
httpRegister("POST", "/control/filtering/set_rules", f.handleFilteringSetRules)
|
httpRegister(http.MethodPost, "/control/filtering/set_rules", f.handleFilteringSetRules)
|
||||||
httpRegister("GET", "/control/filtering/check_host", f.handleCheckHost)
|
httpRegister(http.MethodGet, "/control/filtering/check_host", f.handleCheckHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkFiltersUpdateIntervalHours(i uint32) bool {
|
func checkFiltersUpdateIntervalHours(i uint32) bool {
|
||||||
|
|
|
@ -544,7 +544,7 @@ func marshalTLS(w http.ResponseWriter, data tlsConfig) {
|
||||||
|
|
||||||
// registerWebHandlers registers HTTP handlers for TLS configuration
|
// registerWebHandlers registers HTTP handlers for TLS configuration
|
||||||
func (t *TLSMod) registerWebHandlers() {
|
func (t *TLSMod) registerWebHandlers() {
|
||||||
httpRegister("GET", "/control/tls/status", t.handleTLSStatus)
|
httpRegister(http.MethodGet, "/control/tls/status", t.handleTLSStatus)
|
||||||
httpRegister("POST", "/control/tls/configure", t.handleTLSConfigure)
|
httpRegister(http.MethodPost, "/control/tls/configure", t.handleTLSConfigure)
|
||||||
httpRegister("POST", "/control/tls/validate", t.handleTLSValidate)
|
httpRegister(http.MethodPost, "/control/tls/validate", t.handleTLSValidate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ type qlogConfig struct {
|
||||||
|
|
||||||
// Register web handlers
|
// Register web handlers
|
||||||
func (l *queryLog) initWeb() {
|
func (l *queryLog) initWeb() {
|
||||||
l.conf.HTTPRegister("GET", "/control/querylog", l.handleQueryLog)
|
l.conf.HTTPRegister(http.MethodGet, "/control/querylog", l.handleQueryLog)
|
||||||
l.conf.HTTPRegister("GET", "/control/querylog_info", l.handleQueryLogInfo)
|
l.conf.HTTPRegister(http.MethodGet, "/control/querylog_info", l.handleQueryLogInfo)
|
||||||
l.conf.HTTPRegister("POST", "/control/querylog_clear", l.handleQueryLogClear)
|
l.conf.HTTPRegister(http.MethodPost, "/control/querylog_clear", l.handleQueryLogClear)
|
||||||
l.conf.HTTPRegister("POST", "/control/querylog_config", l.handleQueryLogConfig)
|
l.conf.HTTPRegister(http.MethodPost, "/control/querylog_config", l.handleQueryLogConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func httpError(r *http.Request, w http.ResponseWriter, code int, format string, args ...interface{}) {
|
func httpError(r *http.Request, w http.ResponseWriter, code int, format string, args ...interface{}) {
|
||||||
|
|
|
@ -113,8 +113,8 @@ func (s *statsCtx) initWeb() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.conf.HTTPRegister("GET", "/control/stats", s.handleStats)
|
s.conf.HTTPRegister(http.MethodGet, "/control/stats", s.handleStats)
|
||||||
s.conf.HTTPRegister("POST", "/control/stats_reset", s.handleStatsReset)
|
s.conf.HTTPRegister(http.MethodPost, "/control/stats_reset", s.handleStatsReset)
|
||||||
s.conf.HTTPRegister("POST", "/control/stats_config", s.handleStatsConfig)
|
s.conf.HTTPRegister(http.MethodPost, "/control/stats_config", s.handleStatsConfig)
|
||||||
s.conf.HTTPRegister("GET", "/control/stats_info", s.handleStatsInfo)
|
s.conf.HTTPRegister(http.MethodGet, "/control/stats_info", s.handleStatsInfo)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ fi
|
||||||
# variables.
|
# variables.
|
||||||
set -f -u
|
set -f -u
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Deferred Helpers
|
||||||
|
|
||||||
not_found_msg='
|
not_found_msg='
|
||||||
looks like a binary not found error.
|
looks like a binary not found error.
|
||||||
make sure you have installed the linter binaries using:
|
make sure you have installed the linter binaries using:
|
||||||
|
@ -43,6 +47,10 @@ not_found() {
|
||||||
}
|
}
|
||||||
trap not_found EXIT
|
trap not_found EXIT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Simple Analyzers
|
||||||
|
|
||||||
# blocklist_imports is a simple check against unwanted packages.
|
# blocklist_imports is a simple check against unwanted packages.
|
||||||
# Currently it only looks for package log which is replaced by our own
|
# Currently it only looks for package log which is replaced by our own
|
||||||
# package github.com/AdguardTeam/golibs/log.
|
# package github.com/AdguardTeam/golibs/log.
|
||||||
|
@ -50,6 +58,12 @@ blocklist_imports() {
|
||||||
git grep -F -e '"log"' -- '*.go' || exit 0;
|
git grep -F -e '"log"' -- '*.go' || exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# method_const is a simple check against the usage of some raw strings
|
||||||
|
# and numbers where one should use named constants.
|
||||||
|
method_const() {
|
||||||
|
git grep -F -e '"GET"' -e '"POST"' -- '*.go' || exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
# underscores is a simple check against Go filenames with underscores.
|
# underscores is a simple check against Go filenames with underscores.
|
||||||
underscores() {
|
underscores() {
|
||||||
git ls-files '*_*.go' | { grep -F -e '_darwin.go' \
|
git ls-files '*_*.go' | { grep -F -e '_darwin.go' \
|
||||||
|
@ -58,6 +72,10 @@ underscores() {
|
||||||
-v || exit 0; }
|
-v || exit 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
|
||||||
# exit_on_output exits with a nonzero exit code if there is anything in
|
# exit_on_output exits with a nonzero exit code if there is anything in
|
||||||
# the command's combined output.
|
# the command's combined output.
|
||||||
exit_on_output() (
|
exit_on_output() (
|
||||||
|
@ -98,8 +116,14 @@ exit_on_output() (
|
||||||
return "$exitcode"
|
return "$exitcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Checks
|
||||||
|
|
||||||
exit_on_output blocklist_imports
|
exit_on_output blocklist_imports
|
||||||
|
|
||||||
|
exit_on_output method_const
|
||||||
|
|
||||||
exit_on_output underscores
|
exit_on_output underscores
|
||||||
|
|
||||||
exit_on_output gofumpt --extra -l -s .
|
exit_on_output gofumpt --extra -l -s .
|
||||||
|
|
Loading…
Reference in New Issue