api

package
v0.0.0-...-9ea7be0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

api - package for containing "core" API things, which are reusable in building any API for our platform. These should not contain specific PIXLISE API business logic

api - package for containing "core" API things, which are reusable in building any API for our platform. These should not contain specific PIXLISE API business logic

api - package for containing "core" API things, which are reusable in building any API for our platform. These should not contain specific PIXLISE API business logic

api - package for containing "core" API things, which are reusable in building any API for our platform. These should not contain specific PIXLISE API business logic

api - package for containing "core" API things, which are reusable in building any API for our platform. These should not contain specific PIXLISE API business logic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadPermissions

func ReadPermissions(claims map[string]interface{}) (map[string]bool, error)

func ToJSON

func ToJSON(w http.ResponseWriter, v interface{})

Types

type Error

type Error interface {
	error
	Status() int
}

Error represents a handler error. It provides methods for a HTTP status code and embeds the built-in error interface.

type JWTInterface

type JWTInterface interface {
	ValidateRequest(r *http.Request) (*jwt.JSONWebToken, error)
	Claims(r *http.Request, token *jwt.JSONWebToken, values ...interface{}) error
}

type MockJWTValidator

type MockJWTValidator struct {
}

func (*MockJWTValidator) Claims

func (v *MockJWTValidator) Claims(r *http.Request, token *jwt.JSONWebToken, values ...interface{}) error

func (*MockJWTValidator) ValidateRequest

func (v *MockJWTValidator) ValidateRequest(r *http.Request) (*jwt.JSONWebToken, error)

type RealJWTReader

type RealJWTReader struct {
	Validator JWTInterface
}

RealJWTReader - Reader

func (RealJWTReader) GetSimpleUserInfo

func (j RealJWTReader) GetSimpleUserInfo(r *http.Request) (pixlUser.UserInfo, error)

GetSimpleUserInfo - Get Simple User Info

func (RealJWTReader) GetUserInfo

func (j RealJWTReader) GetUserInfo(r *http.Request) (pixlUser.UserInfo, error)

GetUserInfo - Get User Info

type ResponseWriterWithCopy

type ResponseWriterWithCopy struct {
	RealWriter http.ResponseWriter
	Body       *bytes.Buffer
	Status     int
}

ResponseWriterWithCopy - Acts like a normal http response writer but stores a copy of the written bytes/status, so it can be logged/monitored by a middleware component

func (*ResponseWriterWithCopy) Header

func (w *ResponseWriterWithCopy) Header() http.Header

func (*ResponseWriterWithCopy) StatusText

func (w *ResponseWriterWithCopy) StatusText() string

func (*ResponseWriterWithCopy) Write

func (w *ResponseWriterWithCopy) Write(p []byte) (int, error)

func (*ResponseWriterWithCopy) WriteHeader

func (w *ResponseWriterWithCopy) WriteHeader(statusCode int)

type StatusError

type StatusError struct {
	Code int
	Err  error
}

api.StatusError represents an error with an associated HTTP status code.

func MakeBadRequestError

func MakeBadRequestError(err error) StatusError

func MakeNotFoundError

func MakeNotFoundError(ID string) StatusError

Some common errors

func MakeStatusError

func MakeStatusError(code int, err error) StatusError

Mainly so we don't get a bunch of errors for not using field names in StatusError{}

func (StatusError) Error

func (se StatusError) Error() string

Allows api.StatusError to satisfy the error interface.

func (StatusError) Status

func (se StatusError) Status() int

Status - Returns our HTTP status code.

Jump to

Keyboard shortcuts

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