server

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrBadRequest          = 400
	ErrForbidden           = 403
	ErrNotFound            = 404
	ErrMethodNotAllowed    = 405
	ErrTooManyRequests     = 429
	ErrInternalServerError = 500 // catch-all code for unknown errors

	// Login/authorize error codes
	ErrInvalidState        = 1001
	ErrInvalidOAuthCode    = 1002
	ErrInvalidToken        = 1003 // a token was supplied, but it is invalid
	ErrInviteRequired      = 1004
	ErrInvalidTicket       = 1005 // invalid signup ticket
	ErrInvalidUsername     = 1006 // invalid username (when signing up)
	ErrUsernameTaken       = 1007 // username taken (when signing up)
	ErrInvitesDisabled     = 1008 // invites are disabled (unneeded)
	ErrInviteLimitReached  = 1009 // invite limit reached (when creating invites)
	ErrInviteAlreadyUsed   = 1010 // invite already used (when signing up)
	ErrDeletionPending     = 1011 // own user deletion pending, returned with undo code
	ErrRecentExport        = 1012 // latest export is too recent
	ErrUnsupportedInstance = 1013 // unsupported fediverse software
	ErrAlreadyLinked       = 1014 // user already has linked account of the same type
	ErrNotLinked           = 1015 // user already doesn't have a linked account
	ErrLastProvider        = 1016 // unlinking provider would leave account with no authentication method
	ErrInvalidCaptcha      = 1017 // invalid or missing captcha response

	// User-related error codes
	ErrUserNotFound        = 2001
	ErrMemberListPrivate   = 2002
	ErrFlagLimitReached    = 2003
	ErrRerollingTooQuickly = 2004

	// Member-related error codes
	ErrMemberNotFound     = 3001
	ErrMemberLimitReached = 3002
	ErrMemberNameInUse    = 3003
	ErrNotOwnMember       = 3004

	// General request error codes
	ErrRequestTooBig      = 4001
	ErrMissingPermissions = 4002

	// Moderation related error codes
	ErrReportAlreadyHandled = 5001
	ErrNotSelfDelete        = 5002
)

Error code constants

View Source
const Repository = "https://codeberg.org/pronounscc/pronouns.cc"

Repository is the URL of the git repository

Variables

View Source
var (
	Revision = "[unknown]"
	Tag      = "[unknown]"
)

Revision is the git commit, filled at build time

Functions

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) (auth.Claims, bool)

ClaimsFromContext returns the auth.Claims in the context, if any.

func MustAuth

func MustAuth(next http.Handler) http.Handler

MustAuth makes a valid token required

func WrapHandler

func WrapHandler(hn func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

WrapHandler wraps a modified http.HandlerFunc into a stdlib-compatible one. The inner HandlerFunc additionally returns an error.

Types

type APIError

type APIError struct {
	Code    int             `json:"code"`
	ID      *sentry.EventID `json:"id,omitempty"`
	Message string          `json:"message,omitempty"`
	Details string          `json:"details,omitempty"`

	RatelimitReset *int `json:"ratelimit_reset,omitempty"`

	// Status is set as the HTTP status code.
	Status int `json:"-"`
}

APIError is an object returned by the API when an error occurs. It implements the error interface and can be returned by handlers.

func (APIError) Error

func (e APIError) Error() string

type Server

type Server struct {
	Router *chi.Mux

	DB   *db.DB
	Auth *auth.Verifier
}

func New

func New() (*Server, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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