Documentation ¶
Index ¶
- Constants
- func Error(w http.ResponseWriter, r *http.Request, err error)
- func ErrorStatusCode(code string) int
- func FromErrorStatusCode(code int) string
- func ListenAndServeDebug() error
- func ListenAndServeTLSRedirect(domain string) error
- func LogError(r *http.Request, err error)
- func SetFlash(w http.ResponseWriter, s string)
- type Client
- type DialService
- func (s *DialService) AverageDialValueReport(ctx context.Context, start, end time.Time, interval time.Duration) (*wtf.DialValueReport, error)
- func (s *DialService) CreateDial(ctx context.Context, dial *wtf.Dial) error
- func (s *DialService) DeleteDial(ctx context.Context, id int) error
- func (s *DialService) FindDialByID(ctx context.Context, id int) (*wtf.Dial, error)
- func (s *DialService) FindDials(ctx context.Context, filter wtf.DialFilter) ([]*wtf.Dial, int, error)
- func (s *DialService) SetDialMembershipValue(ctx context.Context, dialID, value int) error
- func (s *DialService) UpdateDial(ctx context.Context, id int, upd wtf.DialUpdate) (*wtf.Dial, error)
- type ErrorResponse
- type Server
- func (s *Server) Close() error
- func (s *Server) MarshalSession(session Session) (string, error)
- func (s *Server) OAuth2Config() *oauth2.Config
- func (s *Server) Open() (err error)
- func (s *Server) Port() int
- func (s *Server) Scheme() string
- func (s *Server) URL() string
- func (s *Server) UnmarshalSession(data string, session *Session) error
- func (s *Server) UseTLS() bool
- type Session
Constants ¶
const SessionCookieName = "session"
SessionCookieName is the name of the cookie used to store the session.
const ShutdownTimeout = 1 * time.Second
ShutdownTimeout is the time given for outstanding requests to finish before shutdown.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, r *http.Request, err error)
Error prints & optionally logs an error message.
func ErrorStatusCode ¶
ErrorStatusCode returns the associated HTTP status code for a WTF error code.
func FromErrorStatusCode ¶
FromErrorStatusCode returns the associated WTF code for an HTTP status code.
func ListenAndServeDebug ¶
func ListenAndServeDebug() error
ListenAndServeDebug runs an HTTP server with /debug endpoints (e.g. pprof, vars).
func ListenAndServeTLSRedirect ¶
ListenAndServeTLSRedirect runs an HTTP server on port 80 to redirect users to the TLS-enabled port 443 server.
func SetFlash ¶
func SetFlash(w http.ResponseWriter, s string)
SetFlash sets the flash cookie for the next request to read.
Types ¶
type DialService ¶
type DialService struct {
Client *Client
}
DialService implements the wtf.DialService over the HTTP protocol.
func NewDialService ¶
func NewDialService(client *Client) *DialService
NewDialService returns a new instance of DialService.
func (*DialService) AverageDialValueReport ¶
func (s *DialService) AverageDialValueReport(ctx context.Context, start, end time.Time, interval time.Duration) (*wtf.DialValueReport, error)
AverageDialValueReport is not implemented by the HTTP service.
func (*DialService) CreateDial ¶
CreateDial creates a new dial and assigns the current user as the owner. The owner will automatically be added as a member of the new dial.
func (*DialService) DeleteDial ¶
func (s *DialService) DeleteDial(ctx context.Context, id int) error
DeleteDial permanently removes a dial by ID. Only the dial owner may delete a dial. Returns ENOTFOUND if dial does not exist. Returns EUNAUTHORIZED if user is not the dial owner.
func (*DialService) FindDialByID ¶
FindDialByID retrieves a single dial by ID along with associated memberships. Only the dial owner & members can see a dial. Returns ENOTFOUND if dial does not exist or user does not have permission to view it.
func (*DialService) FindDials ¶
func (s *DialService) FindDials(ctx context.Context, filter wtf.DialFilter) ([]*wtf.Dial, int, error)
FindDials retrieves a list of dials based on a filter. Only returns dials that the user owns or is a member of. Also returns a count of total matching dials which may different from the number of returned dials if the "Limit" field is set.
func (*DialService) SetDialMembershipValue ¶ added in v0.1.1
func (s *DialService) SetDialMembershipValue(ctx context.Context, dialID, value int) error
SetDialMembershipValue sets the value of the user's membership in a dial. This works the same as calling UpdateDialMembership() although it doesn't require that the user know their membership ID. Only the dial ID.
Returns ENOTFOUND if the membership does not exist.
func (*DialService) UpdateDial ¶
func (s *DialService) UpdateDial(ctx context.Context, id int, upd wtf.DialUpdate) (*wtf.Dial, error)
UpdateDial is not implemented by the HTTP service.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse represents a JSON structure for error output.
type Server ¶
type Server struct { // Bind address & domain for the server's listener. // If domain is specified, server is run on TLS using acme/autocert. Addr string Domain string // Keys used for secure cookie encryption. HashKey string BlockKey string // GitHub OAuth settings. GitHubClientID string GitHubClientSecret string // Servics used by the various HTTP routes. AuthService wtf.AuthService DialService wtf.DialService DialMembershipService wtf.DialMembershipService EventService wtf.EventService UserService wtf.UserService // 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/wtfd) do not need to reference the "net/http" package at all.
func (*Server) MarshalSession ¶
MarshalSession encodes session data to string. This is exported to allow the unit tests to generate fake sessions.
func (*Server) OAuth2Config ¶
OAuth2Config returns the GitHub OAuth2 configuration.
func (*Server) Port ¶
Port returns the TCP port for the running server. This is useful in tests where we allocate a random port by using ":0".
func (*Server) UnmarshalSession ¶
UnmarshalSession decodes session data into a Session object. This is exported to allow the unit tests to generate fake sessions.