httpserver

package
v0.13.17 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 11 Imported by: 5

README

httpserver

HTTPServer uses crypto/ed25519 by default for signing verification. You can inject your own implementation by setting the Verify in this package.

Example

For a simple command crypto/ed25519 takes around 0.54ms on my machine and github.com/oasisprotocol/curve25519-voi takes about 0.13ms.

package main

import (
	"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
	"github.com/disgoorg/disgo/httpserver"
)
func main() {
	httpserver.Verify = func(publicKey httpserver.PublicKey, message, sig []byte) bool {
		return ed25519.Verify(publicKey, message, sig)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Verify reports whether sig is a valid signature of message by publicKey. It
	Verify = func(publicKey PublicKey, message []byte, sig []byte) bool {
		return ed25519.Verify(publicKey, message, sig)
	}

	// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
	SignatureSize = ed25519.SignatureSize
)

Functions

func HandleInteraction added in v0.13.10

func HandleInteraction(publicKey PublicKey, logger log.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

func VerifyRequest(r *http.Request, key PublicKey) bool

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 Config

type Config struct {
	Logger     log.Logger
	HTTPServer *http.Server
	ServeMux   *http.ServeMux
	URL        string
	Address    string
	CertFile   string
	KeyFile    string
}

Config lets you configure your Server instance.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

func (*Config) Apply

func (c *Config) Apply(opts []ConfigOpt)

Apply applies the given ConfigOpt(s) to the Config

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

func WithAddress(address string) ConfigOpt

WithAddress sets the Address of the Config.

func WithHTTPServer

func WithHTTPServer(httpServer *http.Server) ConfigOpt

WithHTTPServer sets the http.Server of the Config.

func WithLogger

func WithLogger(logger log.Logger) ConfigOpt

WithLogger sets the Logger of the Config.

func WithServeMux

func WithServeMux(serveMux *http.ServeMux) ConfigOpt

WithServeMux sets the http.ServeMux of the Config.

func WithTLS

func WithTLS(certFile string, keyFile string) ConfigOpt

WithTLS sets the CertFile of the Config.

func WithURL

func WithURL(url string) ConfigOpt

WithURL sets the URL of the Config.

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) UnmarshalJSON added in v0.13.10

func (e *EventInteractionCreate) UnmarshalJSON(data []byte) error

type PublicKey

type PublicKey = []byte

PublicKey is the type of Ed25519 public keys.

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

func New

func New(publicKey string, eventHandlerFunc EventHandlerFunc, opts ...ConfigOpt) Server

New creates a new Server with the given publicKey eventHandlerFunc and ConfigOpt(s)

Jump to

Keyboard shortcuts

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