oauth

package
v0.0.0-...-4c137d3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount() http.Handler

func Require

func Require(next http.Handler) http.Handler

Require marks handlers as requiring Discord authentication. If not, the client will be promptly redirected to Discord.

Types

type CacheKey

type CacheKey uint32

func NewCacheKey

func NewCacheKey() CacheKey

NewCacheKey generates a global cache key unique to each usage of the cache.

type CacheStore

type CacheStore map[CacheKey]interface{}

CacheStore contains cache values.

type UserClient

type UserClient struct {
	*api.Client
	Cache CacheStore
	// contains filtered or unexported fields
}

UserClient provides a small cache on top of common self-identifying endpoints.

func Client

func Client(ctx context.Context) *UserClient

Client gets the Discord API client with the OAuth Bearer token from the cookies set after a redirection. The function requires the RequireOAuth middleware; it panics if the middleware is not used.

func (*UserClient) Guild

func (c *UserClient) Guild(guildID discord.GuildID) (*discord.Guild, error)

Guild overrides the other method to fetch the list and manually search through it. This has to be done because Discord does not allow single guild ID lookup.

The method limits itself to 100 guilds. It also caches, making it thread unsafe.

func (*UserClient) Guilds

func (c *UserClient) Guilds() ([]discord.Guild, error)

Guilds fetches a list of guilds. It is cached, and is therefore not thread-safe. It limits itself to 100 guilds.

func (*UserClient) InvalidateCache

func (c *UserClient) InvalidateCache()

InvalidateCache invalidates the current cache.

func (*UserClient) Me

func (c *UserClient) Me() (*discord.User, error)

Me gets the current user. It saves the user ID, so it is not thread-safe.

func (*UserClient) UserID

func (c *UserClient) UserID() (discord.UserID, error)

UserID gets the current user's ID. This method is not thread-safe, as it relies on a stateful cache.

Jump to

Keyboard shortcuts

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