server

package
v0.0.0-...-36a0286 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAuthorization = fmt.Errorf("no authorization token")

Functions

func IsAdmin

func IsAdmin(token *auth.Token) bool

func Token

func Token(ctx context.Context) *auth.Token

Token pulls the auth.Token out of the context.

func WithToken

func WithToken(ctx context.Context, token *auth.Token) context.Context

WithToken takes a token and sticks it in the context.

Types

type Affiliate

type Affiliate struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	URL   string `json:"url"`
	Image string `json:"image"`
}

type Authorizer

type Authorizer interface {
	VerifyIDToken(ctx context.Context, idToken string) (*auth.Token, error)
	SessionCookie(ctx context.Context, idToken string, expiresIn time.Duration) (string, error)
	VerifySessionCookieAndCheckRevoked(ctx context.Context, idToken string) (*auth.Token, error)
}

type Base

type Base struct {
	Local           bool
	EnableAds       bool
	EnableAnalytics bool
	RollbarToken    string
	Admin           bool
}

type Config

type Config struct {
	AuthClient    Authorizer
	HumanDAO      *humandao.DAO
	UserDAO       *userdao.DAO
	Logger        zerolog.Logger
	Version       string
	OpenAIClient  *openai.Client
	StorageClient *storage.Client
	Local         bool
}

type ErrorResponse

type ErrorResponse struct {
	Status int
	Err    error
}

func NewBadRequestError

func NewBadRequestError(err error) ErrorResponse

func NewForbiddenError

func NewForbiddenError(err error) ErrorResponse

func NewInternalServerError

func NewInternalServerError(err error) ErrorResponse

func NewNotFoundError

func NewNotFoundError(err error) ErrorResponse

func NewTooManyRequestsError

func NewTooManyRequestsError(err error) ErrorResponse

func NewUnauthorizedError

func NewUnauthorizedError(err error) ErrorResponse

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type HTMLResponseAdmin

type HTMLResponseAdmin struct {
	Base
	AdminName       string
	Drafts          []humandao.Human
	HumanFormFields HumanFormFields
	Human           humandao.Human
}

type HTMLResponseHuman

type HTMLResponseHuman struct {
	Base
	Human humandao.Human
}

type HTMLResponseHumans

type HTMLResponseHumans struct {
	Base
	Humans      []humandao.Human
	Count       int
	Ethnicities []ethnicity.Ethnicity
	Tags        []string
}

type HTMLResponseLogin

type HTMLResponseLogin struct {
	Base
}

type Handler

type Handler func(w http.ResponseWriter, r *http.Request) error

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpHandler

type HttpHandler func(http.ResponseWriter, *http.Request) error

func (HttpHandler) Serve

func (h HttpHandler) Serve(errorHandler func(w http.ResponseWriter, r *http.Request, e ErrorResponse) error) func(http.ResponseWriter, *http.Request)

type Human

type Human struct {
	ID            string                 `json:"id,omitempty"`
	Name          string                 `json:"name,omitempty"`
	Gender        humandao.Gender        `json:"gender,omitempty"`
	Path          string                 `json:"path,omitempty"`
	ReactionCount humandao.ReactionCount `json:"reactionCount,omitempty"`
	DOB           string                 `json:"dob,omitempty"`
	DOD           string                 `json:"dod,omitempty"`
	Tags          []string               `json:"tags,omitempty"`
	Ethnicity     []string               `json:"ethnicity,omitempty"`
	BirthLocation string                 `json:"birthLocation,omitempty"`
	Location      []string               `json:"location,omitempty"`
	InfluencedBy  []string               `json:"influencedBy,omitempty"`
	FeaturedImage string                 `json:"featuredImage,omitempty"`
	Draft         bool                   `json:"draft,omitempty"`
	AIGenerated   bool                   `json:"ai_generated,omitempty"`
	Description   string                 `json:"description,omitempty"`
	CreatedAt     time.Time              `json:"createdAt"`
	UpdatedAt     time.Time              `json:"updatedAt"`
	Affiliates    []Affiliate            `json:"affiliates"`
	Socials       Socials                `json:"socials"`
}

type HumanCreateRequest

type HumanCreateRequest struct {
	Name        string   `json:"name,omitempty"`
	Gender      string   `json:"gender,omitempty"`
	DOB         string   `json:"dob,omitempty"`
	DOD         string   `json:"dod,omitempty"`
	Ethnicity   []string `json:"ethnicity,omitempty"`
	Description string   `json:"description,omitempty"`
	Location    []string `json:"location,omitempty"`
	Website     string   `json:"website,omitempty"`
	Twitter     string   `json:"twitter,omitempty"`
	IMDB        string   `json:"imdb,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	ImagePath   string   `json:"image_path,omitempty"`
}

type HumanCreateResponse

type HumanCreateResponse struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Path      string `json:"path"`
	SignedURL string `json:"signedUrl,omitempty"`
}

type HumanFormFields

type HumanFormFields struct {
	Source      string
	Ethnicities []ethnicity.Ethnicity
	Tags        []string
}

HumanFormFields holds helper data to populate the form to add a new human.

type NoOpAuthorizer

type NoOpAuthorizer struct{}

func (NoOpAuthorizer) SessionCookie

func (n NoOpAuthorizer) SessionCookie(ctx context.Context, idToken string, expiresIn time.Duration) (string, error)

func (NoOpAuthorizer) VerifyIDToken

func (n NoOpAuthorizer) VerifyIDToken(ctx context.Context, idToken string) (*auth.Token, error)

func (NoOpAuthorizer) VerifySessionCookieAndCheckRevoked

func (n NoOpAuthorizer) VerifySessionCookieAndCheckRevoked(ctx context.Context, idToken string) (*auth.Token, error)

type ReactionResponse

type ReactionResponse struct {
	ID           string    `json:"id,omitempty"`
	UserID       string    `json:"user_id,omitempty"`
	HumanID      string    `json:"human_id,omitempty"`
	ReactionKind string    `json:"reaction_kind,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
}

type RecentlyViewed

type RecentlyViewed struct {
	HumanID  string    `json:"human_id"`
	ViewedAt time.Time `json:"viewed_at"`
}

type Saved

type Saved struct {
	HumanID string    `json:"human_id"`
	SavedAt time.Time `json:"saved_at"`
}

type Server

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

func NewServer

func NewServer(config Config) *Server

func (*Server) AdminMiddleware

func (s *Server) AdminMiddleware(next http.Handler) http.Handler

func (*Server) AuthMiddleware

func (s *Server) AuthMiddleware(next http.Handler) http.Handler

func (*Server) DeleteReaction

func (s *Server) DeleteReaction(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) GetHumanFromCache

func (s *Server) GetHumanFromCache(ctx context.Context, humanID string) (human humandao.Human, err error)

func (*Server) GetHumansFromCache

func (s *Server) GetHumansFromCache(ctx context.Context, humanIDs ...string) ([]humandao.Human, error)

func (*Server) GetReactions

func (s *Server) GetReactions(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) HumanCreate

func (s *Server) HumanCreate(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) HumanGet

func (s *Server) HumanGet(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) HumansByID

func (s *Server) HumansByID(w http.ResponseWriter, r *http.Request) (err error)

HumansByID finds all humans given a list of IDs, preserves order. All IDs must be valid, or a HTTP 404 will be returned.

func (*Server) HumansDraft

func (s *Server) HumansDraft(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) HumansList

func (s *Server) HumansList(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) HumansReview

func (s *Server) HumansReview(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) OptionalAuthMiddleware

func (s *Server) OptionalAuthMiddleware(next http.Handler) http.Handler

func (*Server) PostReaction

func (s *Server) PostReaction(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) RateLimitMiddleware

func (s *Server) RateLimitMiddleware(next http.Handler) http.Handler

func (*Server) ReactionsForHuman

func (s *Server) ReactionsForHuman(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) SaveHuman

func (s *Server) SaveHuman(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Server) UnsaveHuman

func (s *Server) UnsaveHuman(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) User

func (s *Server) User(w http.ResponseWriter, r *http.Request) (err error)

func (*Server) Version

func (s *Server) Version(w http.ResponseWriter, r *http.Request) error

func (*Server) ViewHuman

func (s *Server) ViewHuman(w http.ResponseWriter, r *http.Request) (err error)

type ServerHTML

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

func NewServerHTML

func NewServerHTML(conf ServerHTMLConfig) *ServerHTML

func (*ServerHTML) HandlerAbout

func (s *ServerHTML) HandlerAbout(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerAdmin

func (s *ServerHTML) HandlerAdmin(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerError

func (s *ServerHTML) HandlerError(w http.ResponseWriter, r *http.Request, e ErrorResponse) error

func (*ServerHTML) HandlerGenerate

func (s *ServerHTML) HandlerGenerate(w http.ResponseWriter, r *http.Request) error

HandlerGenerate takes in the form, and populates it based on the data in the 'source' field.

func (*ServerHTML) HandlerHuman

func (s *ServerHTML) HandlerHuman(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerHumanAdd

func (s *ServerHTML) HandlerHumanAdd(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerHumanEdit

func (s *ServerHTML) HandlerHumanEdit(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerHumanUpdate

func (s *ServerHTML) HandlerHumanUpdate(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerHumans

func (s *ServerHTML) HandlerHumans(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerIndex

func (s *ServerHTML) HandlerIndex(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerLogin

func (s *ServerHTML) HandlerLogin(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) HandlerPublish

func (s *ServerHTML) HandlerPublish(w http.ResponseWriter, r *http.Request) error

func (*ServerHTML) Register

func (s *ServerHTML) Register(router chi.Router) error

func (*ServerHTML) WrapFileServer

func (s *ServerHTML) WrapFileServer(fileSystem fs.FS) http.Handler

type ServerHTMLConfig

type ServerHTMLConfig struct {
	Local         bool
	HumanDAO      *humandao.DAO
	Logger        zerolog.Logger
	AuthClient    Authorizer
	StorageClient *storage.Client
	OpenaiClient  *openai.Client
	RollbarToken  string
}

type Socials

type Socials struct {
	IMDB    string `json:"imdb,omitempty"`
	X       string `json:"x,omitempty"`
	Website string `json:"website,omitempty"`
}

type User

type User struct {
	ID             string           `json:"id"`
	Saved          []Saved          `json:"saved"`
	RecentlyViewed []RecentlyViewed `json:"recently_viewed"`
}

Jump to

Keyboard shortcuts

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