chore: use gofumpt for code formatting

This commit is contained in:
Quentin McGaw
2024-10-11 19:20:48 +00:00
parent 3daf15a612
commit 76a4bb5dc3
289 changed files with 784 additions and 548 deletions

View File

@@ -12,7 +12,8 @@ import (
var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code is not OK")
func Fetch(ctx context.Context, client *http.Client, url string) (
rootNode *html.Node, err error) {
rootNode *html.Node, err error,
) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("creating HTTP request: %w", err)

View File

@@ -23,7 +23,8 @@ func MatchData(data string) MatchFunc {
}
func DirectChild(parent *html.Node,
matchFunc MatchFunc) (child *html.Node) {
matchFunc MatchFunc,
) (child *html.Node) {
for child := parent.FirstChild; child != nil; child = child.NextSibling {
if matchFunc(child) {
return child
@@ -33,7 +34,8 @@ func DirectChild(parent *html.Node,
}
func DirectChildren(parent *html.Node,
matchFunc MatchFunc) (children []*html.Node) {
matchFunc MatchFunc,
) (children []*html.Node) {
for child := parent.FirstChild; child != nil; child = child.NextSibling {
if matchFunc(child) {
children = append(children, child)

View File

@@ -43,7 +43,8 @@ type Logger interface {
}
func NewLoop(settings settings.Updater, providers updater.Providers,
storage updater.Storage, client *http.Client, logger Logger) *Loop {
storage updater.Storage, client *http.Client, logger Logger,
) *Loop {
return &Loop{
state: state{
status: constants.Stopped,

View File

@@ -8,7 +8,8 @@ import (
)
func FetchFile(ctx context.Context, client *http.Client, url string) (
host string, err error) {
host string, err error,
) {
b, err := fetchData(ctx, client, url)
if err != nil {
return "", err
@@ -25,7 +26,8 @@ func FetchFile(ctx context.Context, client *http.Client, url string) (
}
func fetchData(ctx context.Context, client *http.Client, url string) (
b []byte, err error) {
b []byte, err error,
) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err

View File

@@ -9,7 +9,8 @@ import (
// parses them to extract each of their host. A mapping from host to
// URL is returned.
func FetchMultiFiles(ctx context.Context, client *http.Client, urls []string,
failEarly bool) (hostToURL map[string]string, errors []error) {
failEarly bool,
) (hostToURL map[string]string, errors []error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

View File

@@ -18,7 +18,8 @@ type Provider interface {
var ErrServerHasNotEnoughInformation = errors.New("server has not enough information")
func (u *Updater) updateProvider(ctx context.Context, provider Provider,
minRatio float64) (err error) {
minRatio float64,
) (err error) {
providerName := provider.Name()
existingServersCount := u.storage.GetServersCount(providerName)
minServers := int(minRatio * float64(existingServersCount))

View File

@@ -40,7 +40,8 @@ var (
)
func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) (
hostToIPs map[string][]netip.Addr, warnings []string, err error) {
hostToIPs map[string][]netip.Addr, warnings []string, err error,
) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@@ -96,7 +97,8 @@ func (pr *Parallel) Resolve(ctx context.Context, settings ParallelSettings) (
}
func (pr *Parallel) resolveAsync(ctx context.Context, host string,
settings RepeatSettings, results chan<- parallelResult, errors chan<- error) {
settings RepeatSettings, results chan<- parallelResult, errors chan<- error,
) {
IPs, err := pr.repeatResolver.Resolve(ctx, host, settings)
if err != nil {
errors <- err

View File

@@ -31,7 +31,8 @@ type RepeatSettings struct {
}
func (r *Repeat) Resolve(ctx context.Context, host string, settings RepeatSettings) (
ips []netip.Addr, err error) {
ips []netip.Addr, err error,
) {
timedCtx, cancel := context.WithTimeout(ctx, settings.MaxDuration)
defer cancel()
@@ -68,7 +69,8 @@ var (
func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) (
newNoNewCounter, newFailCounter int, err error) {
newNoNewCounter, newFailCounter int, err error,
) {
IPs, err := r.lookupIPs(timedCtx, host)
if err != nil {
failCounter++

View File

@@ -8,12 +8,11 @@ import (
"net/http"
)
var (
ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK")
)
var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK")
func (u *Unzipper) FetchAndExtract(ctx context.Context, url string) (
contents map[string][]byte, err error) {
contents map[string][]byte, err error,
) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err

View File

@@ -24,7 +24,8 @@ type Updater struct {
}
func New(httpClient *http.Client, storage Storage,
providers Providers, logger Logger) *Updater {
providers Providers, logger Logger,
) *Updater {
unzipper := unzip.New(httpClient)
return &Updater{
providers: providers,
@@ -37,7 +38,8 @@ func New(httpClient *http.Client, storage Storage,
}
func (u *Updater) UpdateServers(ctx context.Context, providers []string,
minRatio float64) (err error) {
minRatio float64,
) (err error) {
caser := cases.Title(language.English)
for _, providerName := range providers {
u.logger.Info("updating " + caser.String(providerName) + " servers...")