Initial code commit

This commit is contained in:
Warezpeddler
2026-01-29 00:03:02 +00:00
commit 8f35bb7ec8
38 changed files with 6039 additions and 0 deletions

44
pkg/utils/ip.go Normal file
View File

@@ -0,0 +1,44 @@
package utils
import (
"fmt"
"io"
"net/http"
"time"
)
func GetPublicIP() (string, error) {
client := &http.Client{
Timeout: 10 * time.Second,
}
services := []string{
"https://api.ipify.org",
"https://icanhazip.com",
"https://ifconfig.me/ip",
}
for _, service := range services {
resp, err := client.Get(service)
if err != nil {
continue
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
continue
}
body, err := io.ReadAll(resp.Body)
if err != nil {
continue
}
ip := string(body)
if ip != "" {
return ip, nil
}
}
return "", fmt.Errorf("failed to determine public IP address from any service")
}