httpserver

package
v0.13.8 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 12 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 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 gateway.EventInteractionCreate)

EventHandlerFunc is used to handle events from Discord's Outgoing Webhooks

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 {
	// Logger returns the logger used by the Server
	Logger() log.Logger

	// PublicKey returns the public key used by the Server
	PublicKey() PublicKey

	// Start starts the Server
	Start()

	// Close closes the Server
	Close(ctx context.Context)

	// Handle passes a payload to the Server for processing
	Handle(respondFunc RespondFunc, event gateway.EventInteractionCreate)
}

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)

type WebhookInteractionHandler

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

WebhookInteractionHandler implements the http.Handler interface and is used to handle interactions from Discord.

func (*WebhookInteractionHandler) ServeHTTP

Jump to

Keyboard shortcuts

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