chore: use gofumpt for code formatting
This commit is contained in:
@@ -26,7 +26,8 @@ const (
|
||||
)
|
||||
|
||||
func New(provider Provider, client *http.Client, token string) ( //nolint:ireturn
|
||||
a API, err error) {
|
||||
a API, err error,
|
||||
) {
|
||||
switch provider {
|
||||
case Cloudflare:
|
||||
return newCloudflare(client), nil
|
||||
@@ -41,9 +42,7 @@ func New(provider Provider, client *http.Client, token string) ( //nolint:iretur
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProviderNotValid = errors.New("API name is not valid")
|
||||
)
|
||||
var ErrProviderNotValid = errors.New("API name is not valid")
|
||||
|
||||
func ParseProvider(s string) (provider Provider, err error) {
|
||||
switch strings.ToLower(s) {
|
||||
|
||||
@@ -26,7 +26,8 @@ func newCloudflare(client *http.Client) *cloudflare {
|
||||
// and returns an error if the `ip` argument is set since the Cloudflare API
|
||||
// can only be used to provide details about the current machine public IP.
|
||||
func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
result models.PublicIP, err error) {
|
||||
result models.PublicIP, err error,
|
||||
) {
|
||||
url := "https://speed.cloudflare.com/meta"
|
||||
if ip.IsValid() {
|
||||
return result, fmt.Errorf("%w: cloudflare cannot provide information on the arbitrary IP address %s",
|
||||
|
||||
@@ -24,7 +24,8 @@ func newIfConfigCo(client *http.Client) *ifConfigCo {
|
||||
// using the ifconfig.co/json API. If the ip is the zero value,
|
||||
// the public IP address of the machine is used as the IP.
|
||||
func (i *ifConfigCo) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
result models.PublicIP, err error) {
|
||||
result models.PublicIP, err error,
|
||||
) {
|
||||
url := "https://ifconfig.co/json"
|
||||
if ip.IsValid() {
|
||||
url += "?ip=" + ip.String()
|
||||
|
||||
@@ -27,7 +27,8 @@ func newIP2Location(client *http.Client, token string) *ip2Location {
|
||||
// using the api.ip2location.io API. If the ip is the zero value,
|
||||
// the public IP address of the machine is used as the IP.
|
||||
func (i *ip2Location) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
result models.PublicIP, err error) {
|
||||
result models.PublicIP, err error,
|
||||
) {
|
||||
url := "https://api.ip2location.io/"
|
||||
if ip.IsValid() {
|
||||
url += "?ip=" + ip.String()
|
||||
|
||||
@@ -28,7 +28,8 @@ func newIPInfo(client *http.Client, token string) *ipInfo {
|
||||
// using the ipinfo.io API. If the ip is the zero value, the public IP address
|
||||
// of the machine is used as the IP.
|
||||
func (i *ipInfo) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
result models.PublicIP, err error) {
|
||||
result models.PublicIP, err error,
|
||||
) {
|
||||
url := "https://ipinfo.io/"
|
||||
switch {
|
||||
case ip.Is6():
|
||||
|
||||
@@ -14,7 +14,8 @@ import (
|
||||
// an error is returned, so the results returned should be considered
|
||||
// incomplete in this case.
|
||||
func FetchMultiInfo(ctx context.Context, fetcher Fetcher, ips []netip.Addr) (
|
||||
results []models.PublicIP, err error) {
|
||||
results []models.PublicIP, err error,
|
||||
) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
type asyncResult struct {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func persistPublicIP(path string, content string, puid, pgid int) error {
|
||||
const permission = fs.FileMode(0644)
|
||||
const permission = fs.FileMode(0o644)
|
||||
file, err := os.OpenFile(path, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, permission)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -38,7 +38,8 @@ type Loop struct {
|
||||
}
|
||||
|
||||
func NewLoop(fetcher Fetcher, logger Logger,
|
||||
settings settings.PublicIP, puid, pgid int) *Loop {
|
||||
settings settings.PublicIP, puid, pgid int,
|
||||
) *Loop {
|
||||
return &Loop{
|
||||
settings: settings,
|
||||
fetcher: fetcher,
|
||||
@@ -73,7 +74,8 @@ func (l *Loop) Start(_ context.Context) (_ <-chan error, err error) {
|
||||
|
||||
func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
|
||||
runTrigger <-chan context.Context, runResult chan<- error,
|
||||
updateTrigger <-chan settings.PublicIP, updatedResult chan<- error) {
|
||||
updateTrigger <-chan settings.PublicIP, updatedResult chan<- error,
|
||||
) {
|
||||
defer close(runDone)
|
||||
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user