Documentation
¶
Index ¶
- Constants
- func BadRequest(w http.ResponseWriter, err messages.APIError) (interface{}, error)
- func CredentialCtx(s *Server) func(http.Handler) http.Handler
- func Forbidden(w http.ResponseWriter) (interface{}, error)
- func Health(w http.ResponseWriter, r *http.Request)
- func NewAuthContext(ctx context.Context, info *AuthInfo) context.Context
- func NoContent(w http.ResponseWriter) (interface{}, error)
- func NotFound(w http.ResponseWriter) (interface{}, error)
- func ReadBody(r *http.Request, limit64 uint64) ([]byte, error)
- func SimpleHandler(inner SimpleHandlerFunc) http.HandlerFunc
- func Unmarshal(r io.ReadCloser, v interface{}) error
- type AuthInfo
- type Config
- type Server
- type SimpleHandlerFunc
Constants ¶
const ( TestEmail = "test@example.com" TestName = "Test User" TestToken = "test-token" TestTherapistID = 2345 TestProfileID = 6789 TestImageID = 997 TestImageExtension = "jpg" TestSession = "test-session" )
Test setup constants.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, err messages.APIError) (interface{}, error)
BadRequest sets up an HTTP 400 Bad Request with a given error message and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.
func CredentialCtx ¶
CredentialCtx extracts credential information from the request (either via a session cookie or an API key), looks up the corresponding user information and injects the resulting authorisation information into the request context as a chassis.AuthInfo value.
func Forbidden ¶
func Forbidden(w http.ResponseWriter) (interface{}, error)
Forbidden sets up an HTTP 403 Forbidden and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.
func Health ¶
func Health(w http.ResponseWriter, r *http.Request)
Health is a common handler for REST service health checking. TODO: DO THIS BETTER - CHECK DB CONNECTION, ETC.
func NewAuthContext ¶
NewAuthContext returns a new Context that carries authentication information.
func NoContent ¶
func NoContent(w http.ResponseWriter) (interface{}, error)
NoContent sets up an HTTP 204 No Content and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.
func NotFound ¶
func NotFound(w http.ResponseWriter) (interface{}, error)
NotFound sets up an HTTP 404 Not Found and returns the (nil, nil) pair used by SimpleHandler to signal that the response has been dealt with.
func SimpleHandler ¶
func SimpleHandler(inner SimpleHandlerFunc) http.HandlerFunc
SimpleHandler wraps a simpleHandler-style HTTP handler function to turn it into a normal HTTP handler function. Go errors from the inner handler are returned to the caller as "500 Internal Server Error" responses. Returns from successful processing by the inner handler and marshalled into a JSON response body.
func Unmarshal ¶
func Unmarshal(r io.ReadCloser, v interface{}) error
Unmarshal does JSON unmarshalling disallowing unknown fields and limiting the permitted body size.
Types ¶
type AuthInfo ¶
type AuthInfo struct { // Is the request authenticated? Authenticated bool // User ID for the authenticated therapist user making the request // (will be zero for an unauthenticated request or a request from a // patient). TherapistID int }
AuthInfo carries authentication information derived from the session. This provides enough information to do authentication and authorisation checking.
func AuthInfoFromContext ¶
AuthInfoFromContext returns the authentication information in a context, if any.
type Config ¶
type Config struct { DevMode bool `env:"DEV_MODE,default=false"` DBURL string `env:"DATABASE_URL,required"` Port int `env:"PORT,default=8080"` CSRFSecret string `env:"CSRF_SECRET"` CORSOrigins string `env:"CORS_ORIGINS"` MJPublicKey string `env:"MAILJET_API_KEY_PUBLIC"` MJPrivateKey string `env:"MAILJET_API_KEY_PRIVATE"` SimultaneousEmails int `env:"SIMULTANEOUS_EMAILS,default=10"` }
Config contains the configuration information needed to start the user service.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the server structure for the TTAT API service.
type SimpleHandlerFunc ¶
type SimpleHandlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)
SimpleHandlerFunc is a HTTP handler function that signals internal errors by returning a normal Go error, and when successful returns a response body to be marshalled to JSON. It can be wrapped in the SimpleHandler middleware to produce a normal HTTP handler function.