Watch-IP

Use Watch-IP with Go

github.com/Digitload/watch-ip-sdk-go (v0.1.1) wraps GET /v1/geo with context-aware requests and no dependencies outside the standard library.

Install

Requires Go 1.21+. This module is mirrored read-only from the main Watch-IP repository to a public repository so go get can fetch it.

go get

go get github.com/Digitload/watch-ip-sdk-go

Quick start

GetGeo takes a context.Context as its first argument — Go's equivalent of the JS SDK's AbortSignal. As with the other server-side SDKs, set WithOrigin to satisfy the key's allowed-origins check when calling from a server rather than a browser. Every location field is a pointer, since Watch-IP fields are independently nullable — check for nil before dereferencing.

Go

client, err := watchip.New("wip_pub_xxxxxxxx", watchip.WithOrigin("https://example.com"))
if err != nil {
    log.Fatal(err)
}

geo, err := client.GetGeo(context.Background())
if err != nil {
    log.Fatal(err)
}

if geo.Country != nil && geo.City != nil {
    fmt.Println(*geo.Country, *geo.City)
} else {
    fmt.Println("location unavailable for this connection")
}

Error handling and timeouts

Every failure returns a *WatchIPError with Status and Code fields. Bound request time with context.WithTimeout rather than a client-level timeout option.

Go

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

geo, err := client.GetGeo(ctx)
var wipErr *watchip.WatchIPError
if errors.As(err, &wipErr) {
    fmt.Println(wipErr.Code, wipErr.Status, wipErr.Message)
}

What this SDK doesn't cover

This module only calls GET /v1/geo. IP lookup, email validation, and risk checks are separate server-to-server endpoints with no Go client yet — call them directly with net/http, authenticated the same way the authentication guide describes.

Related pages