File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ This is the list of currently supported providers for public ip address resoluti
44
44
| - | - | - |
45
45
| ` ipify ` | https://www.ipify.org | None |
46
46
| ` myipio ` | https://www.my-ip.io | None |
47
+ | ` viaip ` | https://viaip.com.br | None |
47
48
48
49
### DNS
49
50
Original file line number Diff line number Diff line change 7
7
"github.com/loop0/pugdns/providers/cloudflare"
8
8
"github.com/loop0/pugdns/providers/ipify"
9
9
"github.com/loop0/pugdns/providers/myipio"
10
+ "github.com/loop0/pugdns/providers/viaip"
10
11
)
11
12
12
13
type IPAddressService interface {
@@ -28,6 +29,8 @@ func getIPAddressProvider() IPAddressService {
28
29
return ipify .NewClient ()
29
30
case "myipio" :
30
31
return myipio .NewClient ()
32
+ case "viaip" :
33
+ return viaip .NewClient ()
31
34
default :
32
35
slog .Error ("Unsupported ip address provider" , "provider" , provider )
33
36
os .Exit (1 )
Original file line number Diff line number Diff line change
1
+ package viaip
2
+
3
+ import (
4
+ "encoding/json"
5
+ "io"
6
+ "net/http"
7
+ )
8
+
9
+ type ViaIPClient struct {
10
+ BaseURL string
11
+ }
12
+
13
+ type PublicIP struct {
14
+ IP string `json:"ip"`
15
+ }
16
+
17
+ func (client * ViaIPClient ) GetPublicIP () (string , error ) {
18
+ req , err := http .NewRequest ("GET" , client .BaseURL , nil )
19
+ if err != nil {
20
+ return "" , err
21
+ }
22
+
23
+ req .Header .Set ("Content-Type" , "application/json" )
24
+
25
+ httpClient := & http.Client {}
26
+ resp , err := httpClient .Do (req )
27
+ if err != nil {
28
+ return "" , err
29
+ }
30
+ defer resp .Body .Close ()
31
+
32
+ body , err := io .ReadAll (resp .Body )
33
+ if err != nil {
34
+ return "" , err
35
+ }
36
+
37
+ publicIP := PublicIP {}
38
+ json .Unmarshal (body , & publicIP )
39
+ return publicIP .IP , nil
40
+ }
41
+
42
+ func NewClient () * ViaIPClient {
43
+ return & ViaIPClient {
44
+ "https://viaip.com.br" ,
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments