Documentation
¶
Index ¶
- func HandleInteraction(verifier Verifier, publicKey PublicKey, logger *slog.Logger, ...) http.HandlerFunc
- func VerifyRequest(verifier Verifier, r *http.Request, key PublicKey) bool
- type ConfigOpt
- func WithAddress(address string) ConfigOpt
- func WithHTTPServer(httpServer *http.Server) ConfigOpt
- func WithLogger(logger *slog.Logger) ConfigOpt
- func WithServeMux(serveMux *http.ServeMux) ConfigOpt
- func WithTLS(certFile string, keyFile string) ConfigOpt
- func WithURL(url string) ConfigOpt
- func WithVerifier(verifier Verifier) ConfigOpt
- type DefaultVerifier
- type EventHandlerFunc
- type EventInteractionCreate
- type PublicKey
- type RespondFunc
- type Server
- type Verifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleInteraction ¶ added in v0.13.10
func HandleInteraction(verifier Verifier, publicKey PublicKey, logger *slog.Logger, handleFunc EventHandlerFunc) http.HandlerFunc
HandleInteraction handles an interaction from Discord's Outgoing Webhooks. It verifies and parses the interaction and then calls the passed EventHandlerFunc.
func VerifyRequest ¶
VerifyRequest implements the verification side of the discord interactions api signing algorithm, as documented here: https://discord.com/developers/docs/interactions/slash-commands#security-and-authorization Credit: https://github.com/bsdlp/discord-interactions-go/blob/main/interactions/verify.go
Types ¶
type ConfigOpt ¶
type ConfigOpt func(config *config)
ConfigOpt is a type alias for a function that takes a config and is used to configure your Server.
func WithAddress ¶
WithAddress sets the Address of the config.
func WithHTTPServer ¶
WithHTTPServer sets the http.Server of the config.
func WithLogger ¶
WithLogger sets the Logger of the config.
func WithServeMux ¶
WithServeMux sets the http.ServeMux of the config.
func WithVerifier ¶ added in v0.19.0
WithVerifier sets the Verifier of the config.
type DefaultVerifier ¶ added in v0.19.0
type DefaultVerifier struct{}
DefaultVerifier is the default implementation of the Verifier interface.
func (DefaultVerifier) SignatureSize ¶ added in v0.19.0
func (DefaultVerifier) SignatureSize() int
type EventHandlerFunc ¶
type EventHandlerFunc func(responseFunc RespondFunc, event EventInteractionCreate)
EventHandlerFunc is used to handle events from Discord's Outgoing Webhooks
type EventInteractionCreate ¶ added in v0.13.10
type EventInteractionCreate struct {
discord.Interaction
}
EventInteractionCreate is the event payload when an interaction is created via Discord's Outgoing Webhooks
func (EventInteractionCreate) MarshalJSON ¶ added in v0.15.1
func (e EventInteractionCreate) MarshalJSON() ([]byte, error)
func (*EventInteractionCreate) UnmarshalJSON ¶ added in v0.13.10
func (e *EventInteractionCreate) UnmarshalJSON(data []byte) error
type RespondFunc ¶ added in v0.8.9
type RespondFunc func(response discord.InteractionResponse) error
RespondFunc is used to respond to Discord's Outgoing Webhooks
type Server ¶
type Server interface {
// Start starts the Server
Start()
// Close closes the Server
Close(ctx context.Context)
}
Server is used for receiving Discord's interactions via Outgoing Webhooks
type Verifier ¶ added in v0.19.0
type Verifier interface {
// Verify verifies the signature of the message using the public key.
// It returns true if the signature is valid, false otherwise.
Verify(publicKey PublicKey, message []byte, sig []byte) bool
// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
SignatureSize() int
}
Verifier is used to verify Ed25519 signatures.