impl

package
v0.0.0-...-77bbea8 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package impl contains the business logic of the DownToMeet server. It is separated from the restapi package as a way to better delineate between handwritten files and automatically generated ones: this package contains all handwritten code, while the majority of restapi is generated from the Swagger API definitions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestFromContext

func RequestFromContext(ctx context.Context) *http.Request

RequestFromContext retrieves the request previously stored in ctx with WithRequest. If no such request exists, RequestFromContext returns nil.

func RequestMiddleware

func RequestMiddleware(h http.Handler) http.Handler

RequestMiddleware returns a handler that ensures that the request's context has the request attached, so that it can later be retrieved using RequestFromContext.

func SessionFromContext

func SessionFromContext(ctx context.Context) *sessions.Session

SessionFromContext retrieves the session previously stored in ctx with WithSession. If no such session exists, SessionFromContext returns nil.

func WithRequest

func WithRequest(ctx context.Context, r *http.Request) context.Context

WithRequest returns a new context with the given request attached, that can later be retrieved using RequestFromContext. The following is guaranteed to hold:

RequestFromContext(WithRequest(ctx, r)) == r

func WithSession

func WithSession(ctx context.Context, session *sessions.Session) context.Context

WithSession returns a new context with the session attached, that can later be retrieved using SessionFromContext. The following is guaranteed to hold:

SessionFromContext(WithSession(ctx, s)) == s

Types

type Implementation

type Implementation struct {
	Options struct {
		Production bool   `long:"production" description:"Run in production mode"`
		Database   string `long:"database" description:"URL of Postgres DB" default:"postgresql://localhost:5432/downtomeet"`
		Frontend   string `long:"frontend" description:"Base URL of frontend" default:"http://localhost:3000/"`
	}
	// contains filtered or unexported fields
}

An Implementation provides all server endpoints for the app.

func NewImplementation

func NewImplementation() *Implementation

NewImplementation returns a new Implementation intended for production, with a sessions.CookieStore as the internal session store.

func NewMockImplementation

func NewMockImplementation(store sessions.Store, randSrc rand.Source) *Implementation

NewMockImplementation returns a new Implementation with the provided parameters.

func (*Implementation) DB

func (i *Implementation) DB() *gorm.DB

DB returns the database associated with the Implementation. If an error occurred when connecting to the database, DB panics.

func (*Implementation) DeleteMeetupID

func (i *Implementation) DeleteMeetupID(params operations.DeleteMeetupIDParams, _ interface{}) middleware.Responder

DeleteMeetupID implements the DELETE /meetup/:id endpoint.

func (*Implementation) GetMeetup

GetMeetup implements the GET /meetup endpoint.

func (*Implementation) GetMeetupID

GetMeetupID implements the GET /meetup/:id endpoint.

func (*Implementation) GetMeetupIDAttendee

func (i *Implementation) GetMeetupIDAttendee(params operations.GetMeetupIDAttendeeParams, _ interface{}) middleware.Responder

GetMeetupIDAttendee implements the GET /meetup/:id/attendee endpoint.

func (*Implementation) GetMeetupRemote

GetMeetupRemote implements the /meetup/remote

func (*Implementation) GetUserFacebookAuth

GetUserFacebookAuth implements the GET /user/facebook/auth endpoint

func (*Implementation) GetUserFacebookRedirect

GetUserFacebookRedirect implements the GET /user/facebook/redirect endpoint

func (*Implementation) GetUserGoogleAuth

GetUserGoogleAuth implements the GET /user/google/auth endpoint

func (*Implementation) GetUserGoogleRedirect

GetUserGoogleRedirect implements the GET /user/google/redirect endpoint

func (*Implementation) GetUserID

GetUserID implements the GET /user/:id endpoint.

func (*Implementation) GetUserLogout

GetUserLogout implements the GET /user/logout endpoint.

func (*Implementation) GetUserMe

func (i *Implementation) GetUserMe(params operations.GetUserMeParams, _ interface{}) middleware.Responder

GetUserMe implements the GET /user/me endpoint.

func (*Implementation) NewOAuthState

func (i *Implementation) NewOAuthState() OAuthState

NewOAuthState returns a fresh OAuthState. The State field is set to a randomly generated 30-character ASCII string. The returned state is set to expire after 30 minutes.

func (*Implementation) PatchMeetupID

func (i *Implementation) PatchMeetupID(params operations.PatchMeetupIDParams, _ interface{}) middleware.Responder

PatchMeetupID implements the PATCH /meetup/:id endpoint.

func (*Implementation) PatchMeetupIDAttendee

func (i *Implementation) PatchMeetupIDAttendee(params operations.PatchMeetupIDAttendeeParams, _ interface{}) middleware.Responder

PatchMeetupIDAttendee implements the PATCH /meetup/:id/attendee endpoint.

func (*Implementation) PatchUserID

func (i *Implementation) PatchUserID(params operations.PatchUserIDParams, _ interface{}) middleware.Responder

PatchUserID implements the PATCH /user/:id endpoint.

func (*Implementation) PostMeetup

func (i *Implementation) PostMeetup(params operations.PostMeetupParams, _ interface{}) middleware.Responder

PostMeetup implements the POST /meetup endpoint.

func (*Implementation) PostMeetupIDAttendee

func (i *Implementation) PostMeetupIDAttendee(params operations.PostMeetupIDAttendeeParams, _ interface{}) middleware.Responder

PostMeetupIDAttendee implements the POST /meetup/:id/attendee endpoint.

func (*Implementation) SessionMiddleware

func (i *Implementation) SessionMiddleware(handler http.Handler) http.Handler

SessionMiddleware augments the request's context with a session that can be fetched using SessionFromContext(r.Context()). Additionally, if the handler wrote values into the session or if there was a preexisting session, the updated cookie added to the response.

func (*Implementation) SessionStore

func (i *Implementation) SessionStore() sessions.Store

SessionStore returns the internal session store.

type OAuthState

type OAuthState struct {
	State     string // a nonce used as the OAuth "state" parameter
	ExpiresAt time.Time
}

OAuthState represents the current OAuth 2.0 login session. In an OAuth login flow, this structure would be created upon user commencing a login, with the State field used as the "state" URL parameter and the entire structure saved to the user's cookie. Later, when the user redirects back to the server, the server would validate the validity of the state by comparing the received "state" parameter against the State field.

func (OAuthState) Validate

func (s OAuthState) Validate(state string) bool

Validate returns true if s is not expired, and the given string matches s.State.

type RequestLogHook

type RequestLogHook struct{}

RequestLogHook is a log.Hook implementation that adds to the log.Entry information gleaned from the entry context, such as the HTTP request (using RequestFromContext) and the user session (using SessionFromContext).

func (RequestLogHook) Fire

func (r RequestLogHook) Fire(entry *log.Entry) error

Fire implements log.Hook.

func (RequestLogHook) Levels

func (r RequestLogHook) Levels() []log.Level

Levels returns log.AllLevels and implements log.Hook.

type SessionKey

type SessionKey int

SessionKey is the type used to key session.Values.

const (
	UserID        SessionKey = 0 // session.Values[UserID] is a string
	FacebookState SessionKey = 1 // session.Values[FacebookState] is an OAuthState
	GoogleState   SessionKey = 2 // session.Values[GoogleState] is an OAuthState
)

Pre-defined session value keys:

func (SessionKey) String

func (i SessionKey) String() string

Directories

Path Synopsis
Package nonce implements a simple ASCII nonce generator, as well as some randomization utilities.
Package nonce implements a simple ASCII nonce generator, as well as some randomization utilities.
Package responders contains implementations of middleware.Responder that can be useful for any endpoint.
Package responders contains implementations of middleware.Responder that can be useful for any endpoint.

Jump to

Keyboard shortcuts

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