Documentation ¶
Index ¶
- Constants
- func AuthToken(header http.Header) string
- func ContentEncoding(header http.Header) string
- func ContentType(header http.Header) string
- func Error(uid uuid.UUID, w http.ResponseWriter, err error, code int)
- func GetSortedCompactJSON(data []byte) ([]byte, error)
- func GetUUID(r *http.Request) (uuid.UUID, error)
- func Health(server string) http.HandlerFunc
- func HttpFailed(StatusCode int) bool
- func HttpSuccess(StatusCode int) bool
- func IsHashRequest(r *http.Request) bool
- func NewRouter() *chi.Mux
- func Ok(w http.ResponseWriter, rsp string)
- func ReadBody(r *http.Request) ([]byte, error)
- func Respond400(w http.ResponseWriter, detail string)
- func Respond406(w http.ResponseWriter, detail string)
- func Respond409(w http.ResponseWriter, detail string)
- func RespondProblem(w http.ResponseWriter, pi HttpProblemInstance)
- func SendResponse(w http.ResponseWriter, resp HTTPResponse)
- type CheckIdentityExists
- type HTTPRequest
- type HTTPResponse
- type HTTPServer
- type HttpProblem
- type HttpProblemInstance
- type IdentityCreator
- type IdentityPayload
- type ServerEndpoint
- type Service
- type Sha256Sum
- type StoreIdentity
Constants ¶
const ( BackendRequestTimeout = 15 * time.Second // time after which requests to the ubirch backend will be canceled GatewayTimeout = 90 * time.Second // time after which a 504 response will be sent if no timely response could be produced ShutdownTimeout = 25 * time.Second // time after which the server will be shut down forcefully if graceful shutdown did not happen before ReadTimeout = 1 * time.Second // maximum duration for reading the entire request -> low since we only expect requests with small content WriteTimeout = 99 * time.Second // time after which the connection will be closed if response was not written -> this should never happen IdleTimeout = 60 * time.Second // time to wait for the next request when keep-alives are enabled UUIDKey = "uuid" OperationKey = "operation" VerifyPath = "verify" HashEndpoint = "hash" RegisterEndpoint = "register" BinType = "application/octet-stream" TextType = "text/plain" JSONType = "application/json" HexEncoding = "hex" HashLen = 32 )
const ( XAuthHeader string = "x-auth-token" MimeTextPlain string = "text/plain" MimeApplicationProblem string = "application/problem+json" HeaderContentType string = "Content-Type" )
Variables ¶
This section is empty.
Functions ¶
func ContentEncoding ¶
helper function to get "Content-Transfer-Encoding" from request header
func ContentType ¶
helper function to get "Content-Type" from request header
func GetSortedCompactJSON ¶
func Health ¶
func Health(server string) http.HandlerFunc
func HttpFailed ¶
func HttpSuccess ¶
func IsHashRequest ¶
func Ok ¶
func Ok(w http.ResponseWriter, rsp string)
func Respond400 ¶
func Respond400(w http.ResponseWriter, detail string)
Respond400 sends a HTTP status 400 response to the provided HTTP response writer using application/problem+json media type and constructs the details property from the supplied error
func Respond406 ¶
func Respond406(w http.ResponseWriter, detail string)
Respond406 sends a HTTP status 406 response to the provided HTTP response writer using application/problem+json media type and constructs the details property from the supplied problem
func Respond409 ¶
func Respond409(w http.ResponseWriter, detail string)
Respond409 sends a HTTP status 409 response to the provided HTTP response writer using application/problem+json media type and constructs the details property from the supplied conflict
func RespondProblem ¶
func RespondProblem(w http.ResponseWriter, pi HttpProblemInstance)
RespondProblem sends an application/problem+json response to the HTTP writer. The response is based on the provided problem instance
func SendResponse ¶
func SendResponse(w http.ResponseWriter, resp HTTPResponse)
forwards response to sender
Types ¶
type HTTPResponse ¶
type HTTPServer ¶
func (*HTTPServer) AddServiceEndpoint ¶
func (srv *HTTPServer) AddServiceEndpoint(endpoint ServerEndpoint)
func (*HTTPServer) Serve ¶
func (srv *HTTPServer) Serve(cancelCtx context.Context, serverReady context.CancelFunc) error
func (*HTTPServer) SetUpCORS ¶
func (srv *HTTPServer) SetUpCORS(allowedOrigins []string, debug bool)
type HttpProblem ¶
type HttpProblem struct { Type string `json:"type"` Title string `json:"title"` Status int `json:"status,omitempty"` }
HttpProblem is an implementation of https://tools.ietf.org/html/rfc7807. It should be used to define once in your program the problems in use. HttpProblemInstances should then be used to create individual instances of the problems.
type HttpProblemInstance ¶
type HttpProblemInstance struct { HttpProblem Detail string `json:"detail,omitempty"` Instance string `json:"instance,omitempty"` }
HttpProblemInstance implements individual instances of defined-once HttpProblems.
type IdentityCreator ¶
type IdentityCreator struct {
// contains filtered or unexported fields
}
func NewIdentityCreator ¶
func NewIdentityCreator(auth string) IdentityCreator
func (*IdentityCreator) Put ¶
func (i *IdentityCreator) Put(storeId StoreIdentity, idExists CheckIdentityExists) http.HandlerFunc
type IdentityPayload ¶
func IdentityFromBody ¶
func IdentityFromBody(r *http.Request) (IdentityPayload, error)
type ServerEndpoint ¶
func (*ServerEndpoint) HandleOptions ¶
func (*ServerEndpoint) HandleOptions(http.ResponseWriter, *http.Request)