randomuser

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package randomuser is the library behind the randomuser command line: the HTTP client, request shaping, and the typed data models for randomuser.me.

The Client sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.

Index

Constants

View Source
const Host = "randomuser.me"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to randomuser.me over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Generate added in v0.1.1

func (c *Client) Generate(ctx context.Context, p GenerateParams) ([]User, error)

Generate fetches randomly generated user profiles with the given params.

type Config added in v0.1.1

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the randomuser driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id). Numeric input is classified as "count"; otherwise "nationality".

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type GenerateParams added in v0.1.1

type GenerateParams struct {
	Results int
	Nat     string
	Gender  string
	Seed    string
}

GenerateParams holds all parameters for the generate API call.

type User added in v0.1.1

type User struct {
	UUID     string `kit:"id" json:"uuid"` // login.uuid
	Name     string `json:"name"`          // "First Last"
	Email    string `json:"email"`
	Phone    string `json:"phone"`
	Gender   string `json:"gender"`
	Age      int    `json:"age"`     // dob.age
	City     string `json:"city"`    // location.city
	State    string `json:"state"`   // location.state
	Country  string `json:"country"` // location.country
	Nat      string `json:"nat"`
	Username string `json:"username"` // login.username
}

User is one randomly generated user profile from randomuser.me.

Jump to

Keyboard shortcuts

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