-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from Plaenkler/add-custom-provider
[ADD] Provider Custom
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package providers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type UpdateCustomRequest struct { | ||
Domain string `json:"URL"` | ||
Check string `json:"Check"` | ||
} | ||
|
||
func UpdateCustom(request interface{}, ipAddr string) error { | ||
r, ok := request.(*UpdateCustomRequest) | ||
if !ok { | ||
return fmt.Errorf("invalid request type: %T", request) | ||
} | ||
if !strings.Contains(r.Domain, "<ipv4>") { | ||
return fmt.Errorf("no <ipv4> placeholder found in URL") | ||
} | ||
r.Domain = strings.Replace(r.Domain, "<ipv4>", ipAddr, -1) | ||
resp, err := SendHTTPRequest(http.MethodGet, r.Domain, nil) | ||
if err != nil { | ||
return err | ||
} | ||
if !strings.Contains(resp, r.Check) { | ||
return fmt.Errorf("check string '%s' not found in response", r.Check) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters