Skip to content

Commit

Permalink
aghhttp: add register func
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 4, 2022
1 parent 61adc7f commit c63f5f4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions internal/aghhttp/aghhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/AdguardTeam/golibs/log"
)

// RegisterFunc is the function that sets the handler to handle the URL for the
// method.
//
// TODO(e.burkov, a.garipov): Get rid of it.
type RegisterFunc func(method, url string, handler http.HandlerFunc)

// OK responds with word OK.
func OK(w http.ResponseWriter) {
if _, err := io.WriteString(w, "OK\n"); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/dhcpd/dhcpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"encoding/json"
"fmt"
"net"
"net/http"
"path/filepath"
"runtime"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
)
Expand Down Expand Up @@ -126,7 +126,7 @@ type ServerConfig struct {
ConfigModified func() `yaml:"-"`

// Register an HTTP handler
HTTPRegister func(string, string, http.HandlerFunc) `yaml:"-"`
HTTPRegister aghhttp.RegisterFunc `yaml:"-"`

Enabled bool `yaml:"enabled"`
InterfaceName string `yaml:"interface_name"`
Expand Down
4 changes: 2 additions & 2 deletions internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"crypto/x509"
"fmt"
"net"
"net/http"
"os"
"sort"
"strings"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
Expand Down Expand Up @@ -193,7 +193,7 @@ type ServerConfig struct {
ConfigModified func()

// Register an HTTP handler
HTTPRegister func(string, string, http.HandlerFunc)
HTTPRegister aghhttp.RegisterFunc

// ResolveClients signals if the RDNS should resolve clients' addresses.
ResolveClients bool
Expand Down
4 changes: 2 additions & 2 deletions internal/filtering/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"io/fs"
"net"
"net/http"
"os"
"runtime"
"runtime/debug"
"strings"
"sync"
"sync/atomic"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
Expand Down Expand Up @@ -94,7 +94,7 @@ type Config struct {
ConfigModified func() `yaml:"-"`

// Register an HTTP handler
HTTPRegister func(string, string, http.HandlerFunc) `yaml:"-"`
HTTPRegister aghhttp.RegisterFunc `yaml:"-"`

// CustomResolver is the resolver used by DNSFilter.
CustomResolver Resolver `yaml:"-"`
Expand Down
4 changes: 2 additions & 2 deletions internal/querylog/querylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package querylog

import (
"net"
"net/http"
"path/filepath"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/errors"
Expand Down Expand Up @@ -38,7 +38,7 @@ type Config struct {
ConfigModified func()

// HTTPRegister registers an HTTP handler.
HTTPRegister func(string, string, http.HandlerFunc)
HTTPRegister aghhttp.RegisterFunc

// FindClient returns client information by their IDs.
FindClient func(ids []string) (c *Client, err error)
Expand Down
5 changes: 3 additions & 2 deletions internal/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package stats

import (
"net"
"net/http"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
)

// UnitIDGenFunc is the signature of a function that generates a unique ID for
Expand All @@ -30,7 +31,7 @@ type Config struct {

// HTTPRegister is the function that registers handlers for the stats
// endpoints.
HTTPRegister func(string, string, http.HandlerFunc)
HTTPRegister aghhttp.RegisterFunc

// Filename is the name of the database file.
Filename string
Expand Down
4 changes: 2 additions & 2 deletions internal/stats/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"encoding/gob"
"fmt"
"net"
"net/http"
"os"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"go.etcd.io/bbolt"
Expand Down Expand Up @@ -46,7 +46,7 @@ type StatsCtx struct {
unitIDGen UnitIDGenFunc

// httpRegister is used to set HTTP handlers.
httpRegister func(string, string, http.HandlerFunc)
httpRegister aghhttp.RegisterFunc

// configModified is called whenever the configuration is modified via web
// interface.
Expand Down

0 comments on commit c63f5f4

Please sign in to comment.