http

package
v0.0.0-...-a85e8f0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ThumbsUp   = "+1"
	ThumbsDown = "-1"
)
View Source
const ShutdownTimeout = 1 * time.Second

ShutdownTimeout is the time given for outstanding requests to finish before shutdown.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server represents an HTTP server. It is meant to wrap all http functionality used by the application so that dependent packages (such as cmd/statsd) do not need to reference the "net/http" package at all.

func NewServer

func NewServer(logger *slog.Logger, serverAddr string, ss Slacker) *Server

NewServer creates a new instance of Server.

func (*Server) Close

func (s *Server) Close() error

Close gracefully shuts down the server.

func (*Server) Open

func (s *Server) Open() (err error)

Open establishes a connection to an address and begins listening for requests.

type Slack

type Slack struct {
	// Services used by Slack
	LeaderboardService statsd.LeaderboardService
	MemberService      statsd.MemberService
	// contains filtered or unexported fields
}

Slack represents a service for handling specific Slack events.

func (*Slack) HandleEvents

func (s *Slack) HandleEvents(w http.ResponseWriter, r *http.Request) error

handleEvents handles Slack push events.

func (*Slack) HandleMonthlyUpdate

func (s *Slack) HandleMonthlyUpdate(w http.ResponseWriter, r *http.Request) error

HandleMonthlyUpdate sends a summary of the recorded metrics into Slack.

Expecting x-www-form-urlencoded payload in the form of `channel=<channelID>&date=<month>-<year>`. I.e. to represent October 2023, the key=value combination would be `date=10-2023`.

func (*Slack) HandleReactionAddedEvent

func (s *Slack) HandleReactionAddedEvent(e *slackevents.ReactionAddedEvent) error

HandleReactionAddedEvent handles the event when a user reacts to the post of another user.

func (*Slack) HandleReactionEvent

func (s *Slack) HandleReactionEvent(memSlackUID string, update func(m *statsd.Member)) error

HandleReactionEvent handles an event by updating the member with the specified slackUID.

func (*Slack) HandleReactionRemovedEvent

func (s *Slack) HandleReactionRemovedEvent(e *slackevents.ReactionRemovedEvent) error

HandleReactionRemovedEvent handles the event when a user removes a reaction from another user's post.

type Slacker

type Slacker interface {
	HandleEvents(w http.ResponseWriter, r *http.Request) error
	HandleMonthlyUpdate(w http.ResponseWriter, r *http.Request) error
}

Slacker represents a service for handling Slack push events.

func NewSlackService

func NewSlackService(logger *slog.Logger, ms statsd.MemberService, ls statsd.LeaderboardService, signingSecret string, botSigningKey string) (Slacker, error)

NewSlackService creates a new instance of slackService.

Jump to

Keyboard shortcuts

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