client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package client provides methods for accessing the discord bouncer REST API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCredentials is returned when the server rejects credentials while logging in.
	ErrInvalidCredentials = errors.New("invalid credentials")

	// ErrPasswordTooShort is returned by ChangePassword if the password is too short.
	ErrPasswordTooShort = errors.New("password too short")

	// ErrPasswordTooLong is returned by ChangePassword if the password is too long.
	ErrPasswordTooLong = errors.New("password too long")
)
View Source
var ErrNotLoggedIn = errors.New("not logged in")

ErrNotLoggedIn is returned when a 401: Unauthorized is returned by the server.

Functions

This section is empty.

Types

type AdminService

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

AdminService is used to manage authentication with the server.

func (*AdminService) ChangePassword

func (s *AdminService) ChangePassword(ctx context.Context, oldPass, newPass string) error

ChangePassword updates the password on the server. Must be logged in.

func (*AdminService) Login

func (s *AdminService) Login(ctx context.Context, user, pass string) error

Login and store the session for later use by the client.

func (*AdminService) Logout

func (s *AdminService) Logout(ctx context.Context) error

Logout invalidates the currently held session. You will need to call Login again in order to use the API.

type Client

type Client struct {
	Admin AdminService
	Users UsersService
	// contains filtered or unexported fields
}

Client implements methods to access the disco-bouncer API.

func NewClient

func NewClient(baseURL string) (*Client, error)

NewClient creates a new client that sends requests to the given URL.

type FilterOption

type FilterOption = func(f *filters)

FilterOption is a way to add filter options to the request when calling GetAllUsers.

func WithKeyHash

func WithKeyHash(keyHash string) FilterOption

WithKeyHash returns a FilterOption that filters by the provided MD5 key hash.

type UsersService

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

UserService is used to view and modify the users table on the server.

func (*UsersService) CreateUser

func (s *UsersService) CreateUser(ctx context.Context, u *db.User) (int, error)

CreateUser creates a new user and returns the ID. u.ID is ignored.

func (*UsersService) DeleteUser

func (s *UsersService) DeleteUser(ctx context.Context, id int) error

DeleteUser removes the user from the server.

func (*UsersService) GetAllUsers

func (s *UsersService) GetAllUsers(ctx context.Context, opts ...FilterOption) ([]*db.User, error)

GetAllUsers gets the current users table.

func (*UsersService) GetUser

func (s *UsersService) GetUser(ctx context.Context, id int) (*db.User, error)

GetUser gets the information of the user with the specified ID.

func (*UsersService) UpdateUser

func (s *UsersService) UpdateUser(ctx context.Context, u *db.User) error

UpdateUser updates the information for an existing user, selected by u.ID.

func (*UsersService) Upload

func (s *UsersService) Upload(ctx context.Context, u *db.User) (id int, key string, err error)

Upload uploads a new user to the server. It encrypts u.Name, fills in u.NameKeyHash, and returns the received ID and the encrypted key. The fields of u will be updated.

Jump to

Keyboard shortcuts

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