redirect

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package redirect wraps the /redirect API endpoint — currently just /redirect/list_redirects.json, the per-account inventory of HTTP redirect rules grouped by domain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the api.Client for the /redirect endpoints.

func New

func New(c *api.Client) *Client

New initialises a redirect Client.

func (*Client) ListRedirects

func (s *Client) ListRedirects(ctx context.Context, request ListRedirectsRequest) (response ListRedirectsResponse, err error)

ListRedirects returns every redirect rule on the account via /redirect/list_redirects.json, grouped by domain → source URL → (destination + HTTP type).

Pagination filters control the result window if the account has a lot of rules.

type ListRedirectsRequest

type ListRedirectsRequest struct {
	SortBy     string
	SortDir    string
	PageSize   int
	PageNumber int
}

ListRedirectsRequest paginates / sorts the redirect listing. All fields are optional.

type ListRedirectsResponse

type ListRedirectsResponse struct {
	Return map[string]map[string]Rule `json:"return"`
	models.APIResponse
}

ListRedirectsResponse is the return from /redirect/list_redirects.json.

**Wire-shape quirk** (verified live, May 2026): when the account has redirects, "return" is a nested map keyed by domain → source URL → Rule:

{
  "example.kiwi.nz": {
    "a.example.kiwi.nz": {"destination": "https://...", "type": 301},
    "b.example.kiwi.nz/blog": {"destination": "https://...", "type": 302}
  }
}

When the account has **zero** redirects, "return" is the JSON array `[]`, not the empty object `{}`. The docs only show the populated form, so consumers parsing the obvious map shape would fail on empty accounts.

Custom UnmarshalJSON handles both: the empty array is decoded as an empty map; the populated map is decoded normally.

func (*ListRedirectsResponse) UnmarshalJSON

func (r *ListRedirectsResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON tolerates the empty-array form the API returns when the account has no redirect rules. See type comment.

type Rule

type Rule struct {
	Destination string `json:"destination"`
	Type        int    `json:"type"`
}

Rule describes one redirect: where the source URL points to and the HTTP status code (typically 301 or 302).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL