From 700f88b14e622d7a0a100cf2a7e461e6fd48aa9a Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Fri, 30 Mar 2018 17:23:56 +0200 Subject: [PATCH] godoc for context package --- app/handlers/context/context.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/handlers/context/context.go b/app/handlers/context/context.go index e0b6d55d..f9036b73 100644 --- a/app/handlers/context/context.go +++ b/app/handlers/context/context.go @@ -1,3 +1,5 @@ +// Package context provides functions for setting and getting values from +// a request's context. package context import ( @@ -17,6 +19,8 @@ const ( resultFilePathKey ) +// WithContentType populates a request's context with the given content type +// and returns the updated request. func WithContentType(r *http.Request, contentType ghttp.ContentType) *http.Request { ctx := r.Context() ctx = context.WithValue(ctx, contentTypeKey, contentType) @@ -31,6 +35,8 @@ func (e *contentTypeNotFoundError) Error() string { return "The 'Content-Type' was not found in request context" } +// GetContentType returns the content type if found in +// the request's context. Otherwise throws an error. func GetContentType(r *http.Request) (ghttp.ContentType, error) { ct, ok := r.Context().Value(contentTypeKey).(ghttp.ContentType) if !ok { @@ -40,6 +46,8 @@ func GetContentType(r *http.Request) (ghttp.ContentType, error) { return ct, nil } +// WithConverter populates a request's context with the given converter +// and returns the updated request. func WithConverter(r *http.Request, converter *converter.Converter) *http.Request { ctx := r.Context() ctx = context.WithValue(ctx, converterKey, converter) @@ -54,6 +62,8 @@ func (e *converterNotFoundError) Error() string { return "The converter was not found in request context" } +// GetConverter returns the converter if found in +// the request's context. Otherwise throws an error. func GetConverter(r *http.Request) (*converter.Converter, error) { c, ok := r.Context().Value(converterKey).(*converter.Converter) if !ok { @@ -63,6 +73,8 @@ func GetConverter(r *http.Request) (*converter.Converter, error) { return c, nil } +// WithResultFilePath populates a request's context with the given result file path +// and returns the updated request. func WithResultFilePath(r *http.Request, resultFilePath string) *http.Request { ctx := r.Context() ctx = context.WithValue(ctx, resultFilePathKey, resultFilePath) @@ -77,6 +89,8 @@ func (e *resultFilePathNotFoundError) Error() string { return "The result file path was not found in request context" } +// GetResultFilePath returns the result file path if found in +// the request's context. Otherwise throws an error. func GetResultFilePath(r *http.Request) (string, error) { path, ok := r.Context().Value(resultFilePathKey).(string) if !ok {