httpserver

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 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 = func(publicKey PublicKey, message, sig []byte) bool {
		return ed25519.Verify(publicKey, message, sig)
	}
	SignatureSize = ed25519.SignatureSize
)

Functions

func VerifyRequest

func VerifyRequest(logger log.Logger, 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
	PublicKey  string
	CertFile   string
	KeyFile    string
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Apply

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

type ConfigOpt

type ConfigOpt func(config *Config)

func WithAddress

func WithAddress(address string) ConfigOpt

func WithHTTPServer

func WithHTTPServer(httpServer *http.Server) ConfigOpt

func WithLogger

func WithLogger(logger log.Logger) ConfigOpt

func WithPublicKey

func WithPublicKey(publicKey string) ConfigOpt

func WithServeMux

func WithServeMux(serveMux *http.ServeMux) ConfigOpt

func WithTLS

func WithTLS(certFile string, keyFile string) ConfigOpt

func WithURL

func WithURL(url string) ConfigOpt

type EventHandlerFunc

type EventHandlerFunc func(responseFunc RespondFunc, payload io.Reader)

type PublicKey

type PublicKey = []byte

type RespondFunc added in v0.8.9

type RespondFunc func(response discord.InteractionResponse) error

type Server

type Server interface {
	Logger() log.Logger
	PublicKey() PublicKey

	Start()
	Close(ctx context.Context)
	Handle(respondFunc RespondFunc, payload io.Reader)
}

Server is used for receiving an Interaction over httpserver

func New

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

type WebhookInteractionHandler

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

func (*WebhookInteractionHandler) ServeHTTP

Jump to

Keyboard shortcuts

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