go-genderize: github.com/SteelPangolin/go-genderize Index | Examples | Files

package genderize

import "github.com/SteelPangolin/go-genderize"

Package genderize provides a client for the Genderize.io web service.

Index

Examples

Package Files

genderize.go

Constants

const (
    Male    = "male"
    Female  = "female"
    Unknown = ""
)

Gender string constants.

const Version = "0.1.0"

Version of this library. Used to form the default user agent string.

func Get Uses

func Get(names []string) ([]Response, error)

Get gender info for names, using the default client and country/language IDs.

Simple interface with minimal configuration.

Code:

responses, err := Get([]string{"James", "Eva", "Thunderhorse"})
if err != nil {
    panic(err)
}
for _, response := range responses {
    fmt.Printf("%s: %s\n", response.Name, response.Gender)
}

Output:

James: male
Eva: female
Thunderhorse:

type Client Uses

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

Client for the Genderize API.

func NewClient Uses

func NewClient(config Config) (*Client, error)

NewClient constructs a Genderize client from a Config.

func (*Client) Get Uses

func (client *Client) Get(query Query) ([]Response, error)

Get gender info for names with optional country and language IDs.

Client with custom API key and user agent, query with language and country IDs.

Code:

client, err := NewClient(Config{
    UserAgent: "GoGenderizeDocs/0.0",
    // Note that you'll need to use your own API key.
    APIKey: "",
})
if err != nil {
    panic(err)
}
responses, err := client.Get(Query{
    Names:      []string{"Kim"},
    CountryID:  "dk",
    LanguageID: "da",
})
if err != nil {
    panic(err)
}
for _, response := range responses {
    fmt.Printf("%s: %s\n", response.Name, response.Gender)
}

Output:

Kim: male

type Config Uses

type Config struct {
    UserAgent  string
    APIKey     string
    Server     string
    HTTPClient *http.Client
}

Config for a Genderize client.

type Query Uses

type Query struct {
    Names      []string
    CountryID  string
    LanguageID string
}

A Query is a list of names with optional country and language IDs.

type Response Uses

type Response struct {
    Name string
    // Gender can be "male", "female", or empty,
    // in which case Probability and Count should be ignored.
    Gender      string
    Probability float64
    Count       int64
}

A Response is a name with gender and probability information attached.

type ServerError Uses

type ServerError struct {
    Message string `json:"error"`
}

A ServerError contains a message from the Genderize API server.

func (ServerError) Error Uses

func (serverError ServerError) Error() string

Error returns the error message.

Package genderize imports 4 packages (graph). Updated 2016-07-19. Refresh now. Tools for package owners.