app

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

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ping               = 1
	ApplicationCommand = 2
)

InteractionTypes https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype

Variables

This section is empty.

Functions

func Start

func Start(opts ...ServerOption)

Start is the main entry point to the app

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v interface{})

WriteJSON marshals the object provided as json and writes it to the http.ResponseWriter

Types

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (token string, ok bool)
}

Authenticator of http requests

type Authorizer

type Authorizer interface {
	Authorize(r *http.Request) (ok bool)
}

Authorizer of http requests

type ErrorResponse

type ErrorResponse struct {
	Error   string     `json:"error"`
	Request logRequest `json:"request"`
}

ErrorResponse is the standard http error response

func NewErrorResponse

func NewErrorResponse(r *http.Request, err error) ErrorResponse

NewErrorResponse ..

type InteractionApplicationCommandCallbackData

type InteractionApplicationCommandCallbackData struct {
	TTS             *bool            `json:"tts,omitempty"`              // is the response TTS
	Content         string           `json:"content"`                    // message content
	Embeds          []Embed          `json:"embeds,omitempty"`           // supports up to 10 embeds
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"` // allowed mentions object
}

InteractionApplicationCommandCallbackData ... https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata

type InteractionResponse

type InteractionResponse struct {
	Type InteractionResponseType                    `json:"type"`
	Data *InteractionApplicationCommandCallbackData `json:"data,omitempty"`
}

InteractionResponse ... https://discord.com/developers/docs/interactions/slash-commands#interaction-response

type InteractionResponseType

type InteractionResponseType int

InteractionResponseType ...

const (
	// ACK a Ping
	Pong InteractionResponseType = 1
	// ACK a command without sending a message, eating the user's input
	Acknowledge InteractionResponseType = 2
	// respond with a message, eating the user's input
	ChannelMessage InteractionResponseType = 3
	// respond with a message, showing the user's input
	ChannelMessageWithSource InteractionResponseType = 4
	// ACK a command without sending a message, showing the user's input
	AcknowledgeWithSource InteractionResponseType = 5
)

Discord InteractionResponseTypes https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype

type InteractionType

type InteractionType int

InteractionType ...

type Server

type Server struct {
	Authorizer
	Authenticator

	WhitelistGetter WhitelistGetter
	// contains filtered or unexported fields
}

Server of the apps

func NewServer

func NewServer(opts ...ServerOption) Server

NewServer creates a new server

func (*Server) Err

func (s *Server) Err(w http.ResponseWriter, r *http.Request, status int, err error)

Err handles errors

func (*Server) ErrInternal

func (s *Server) ErrInternal(w http.ResponseWriter, r *http.Request, err error)

ErrInternal handles internal server error

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler is the servers main Handler

func (*Server) IsValid

func (s *Server) IsValid() error

IsValid checks a servers configuration

func (*Server) Middleware

func (s *Server) Middleware(next http.Handler) http.Handler

Middleware is the apps main middleware.

func (*Server) Set

func (s *Server) Set(opts ...ServerOption)

Set a servers configuration

type ServerOption

type ServerOption func(*Server)

ServerOption is an option server parameter

func WithAuthenticator

func WithAuthenticator(a Authenticator) ServerOption

WithAuthenticator ..

func WithAuthorizer

func WithAuthorizer(a Authorizer) ServerOption

WithAuthorizer ..

func WithDiscordPublicKey

func WithDiscordPublicKey(key string) (ServerOption, error)

WithDiscordPublicKey is a ServerOption

func WithPort

func WithPort(port uint64) ServerOption

WithPort server http port

func WithWhitelist

func WithWhitelist(w Whitelister) ServerOption

WithWhitelist add a whitelist.json file path the server

type WhitelistGetter

type WhitelistGetter interface {
	Get(ctx context.Context) ([]minecraft.User, error)
}

WhitelistGetter gets users in a whitelist

type Whitelister

type Whitelister interface {
	WhitelistGetter
}

Whitelister is a wrapper interface for managing whitelist

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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