Goth.start_link

You're seeing just the function start_link, go back to Goth module for more information.
Link to this function

start_link(opts)

View Source (since 1.3.0)

Starts the server.

When the server is started, we attempt to fetch the token and store it in internal cache. If we fail, we'll try up to 3 times with 1000ms cooldown between requests and if we couldn't retrieve it, we crash.

Options

  • :name - the name to register the server under.

  • :source - the source to retrieve the token from.

    See documentation for the :source option in Goth.Token.fetch/1 for more information.

  • :retry_after - Time in milliseconds between retrying requests, defaults to 1000.

  • :refresh_before - Time in seconds before the token is about to expire that it is tried to be automatically refreshed. Defaults to 300 (5 minutes).

  • :http_client - a {module, opts} tuple, where module implements the Goth.HTTPClient behaviour and opts is a keywords list to initialize the client with. Defaults to {Goth.HTTPClient.Hackney, []}.

Examples

Generate a token using a service account credentials file:

iex> credentials = "credentials.json" |> File.read!() |> Jason.decode!()
iex> Goth.start_link(name: MyApp.Goth, source: {:service_account, credentials, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}

Retrieve the token using a refresh token:

iex> credentials = "credentials.json" |> File.read!() |> Jason.decode!()
iex> Goth.start_link(name: MyApp.Goth, source: {:refresh_token, credentials, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}

Retrieve the token using the Google metadata server:

iex> Goth.start_link(name: MyApp.Goth, source: {:metadata, []})
iex> Goth.fetch(MyApp.Goth)
{:ok, %Goth.Token{...}}