Documentation
¶
Overview ¶
Package apikey provides authentication profile support for APIs that require a pre-generated constant authenticationn key passed via a header, query parameter, or cookie value in each request.
Example ¶
// Initialize the CLI.
cli.Init(&cli.Config{
AppName: "example",
EnvPrefix: "EXAMPLE",
})
// Initialize the API key authentication.
Init("X-API-Key", LocationHeader)
// Mock out a profile to be used in the request.
cli.Creds.Set("profiles.default.api_key", "my-secret")
// Make a request.
req := cli.Client.Get().URL("http://example.com/")
if _, err := req.Do(); err != nil {
panic(err)
}
// Look at the header that was used in the request. It should match the
// profile's API key value.
fmt.Println(req.Context.Request.Header.Get("X-API-Key"))
Output: my-secret
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
Init sets up the API key client authentication. Must be called *after* you have called `cli.Init()`. Passing `extra` values will set additional custom keys to store for each profile.
Example (Header) ¶
// Use a custom header for authentication.
Init("X-API-Key", LocationHeader)
Example (Query) ¶
// Use a query parameter for authentication.
Init("apikey", LocationHeader)
Types ¶
Click to show internal directories.
Click to hide internal directories.