server

package
v0.0.0-...-f8b93fe Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillEmptyOpts

func FillEmptyOpts(opts *Opts)

Types

type ApplicationError

type ApplicationError struct {
	// ErrorCode should have its 3 first digits represent http status code.
	// For example, 50001 will return 500, 40401 will return 404...
	ErrorCode int
	Message   string
}

func NewApplicationError

func NewApplicationError(errorCode int, message string) ApplicationError

func (ApplicationError) Error

func (err ApplicationError) Error() string

type Bot

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

func NewBot

func NewBot(discordToken string, service *Service) (*Bot, error)

func (*Bot) RegisterCommands

func (b *Bot) RegisterCommands(guildId string)

type CodeInformation

type CodeInformation struct {
	Code    string
	XUID    string
	Issued  string
	Expires string
}

type CodeStore

type CodeStore interface {
	GetInformation(code string) (*CodeInformation, error)
	GetForXuid(xuid string) (*CodeInformation, error)
	Issue(xuid string) (*CodeInformation, error)
	Revoke(code string) error
}

type ErrorInformation

type ErrorInformation struct {
	Code    int
	Message string
}

type NewUserHandler

type NewUserHandler func(user *User)

type Opts

type Opts struct {
	Logger  *slog.Logger
	Repo    Repository
	CodeStr CodeStore
}

func DefaultOpts

func DefaultOpts() *Opts

type Payload

type Payload struct {
	Error *ErrorInformation `json:"error"`
	Data  interface{}       `json:"data"`
}

func FailurePayload

func FailurePayload(err ApplicationError) Payload

func SuccessPayload

func SuccessPayload(data interface{}) Payload

type Repository

type Repository interface {
	GetUserByDiscord(discordId string) (*User, error)
	GetUserByXUID(xuid string) (*User, error)
	CreateUser(discordId, xuid string) (*User, error)
	DeleteUserByDiscord(discordId string) error
	DeleteUserByXUID(xuid string) error
}

func NewDefaultRepository

func NewDefaultRepository() (Repository, error)

type Server

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

func NewServer

func NewServer(accessToken, discordBotToken string, opts *Opts) *Server

func (*Server) Bot

func (s *Server) Bot() *Bot

func (*Server) GetHttpHandler

func (s *Server) GetHttpHandler(isDevelopment bool) (http.Handler, error)

GetHttpHandler returns http.Handler

func (*Server) ServeWeb

func (s *Server) ServeWeb(addr string) error

ServeWeb listens to the specific address

type Service

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

func NewService

func NewService(repo Repository, codeStr CodeStore) *Service

func (*Service) AddHandler

func (s *Service) AddHandler(handler NewUserHandler)

func (*Service) CheckCode

func (s *Service) CheckCode(code string) (*CodeInformation, error)

func (*Service) CreateUser

func (s *Service) CreateUser(discord, xuid string) (*User, error)

func (*Service) DeleteUserByDiscord

func (s *Service) DeleteUserByDiscord(discord string) error

func (*Service) DeleteUserByXUID

func (s *Service) DeleteUserByXUID(xuid string) error

func (*Service) GetUserByDiscord

func (s *Service) GetUserByDiscord(discord string) (*User, error)

func (*Service) GetUserByXUID

func (s *Service) GetUserByXUID(xuid string) (*User, error)

func (*Service) IssueCode

func (s *Service) IssueCode(xuid string) (*CodeInformation, error)

func (*Service) RevokeCode

func (s *Service) RevokeCode(code string) error

type User

type User struct {
	Discord string
	XUID    string
}

type UserData

type UserData struct {
	*gorm.Model
	Discord string
	XUID    string `gorm:"column:xuid"`
}

func (*UserData) ToUser

func (u *UserData) ToUser() *User

Jump to

Keyboard shortcuts

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