mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-13 02:42:14 +01:00
improving Godoc
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package context implements a solution for accessing and setting a request's context values.
|
||||
package context
|
||||
|
||||
import (
|
||||
@@ -7,14 +8,20 @@ import (
|
||||
"github.com/gulien/gotenberg/logger"
|
||||
)
|
||||
|
||||
const transactionIDKey = "TransactionID"
|
||||
// transactionIDCtxKeyType is a basic type for transactionIDCtxKey.
|
||||
type transactionIDCtxKeyType string
|
||||
|
||||
// transactionIDCtxKey is the transactionID accessing key.
|
||||
const transactionIDCtxKey transactionIDCtxKeyType = "transactionID"
|
||||
|
||||
// WithTransactionID populates a context ctx with a transaction ID v.
|
||||
func WithTransactionID(ctx context.Context, v string) context.Context {
|
||||
return context.WithValue(ctx, transactionIDKey, v)
|
||||
return context.WithValue(ctx, transactionIDCtxKey, v)
|
||||
}
|
||||
|
||||
// GetTransactionID returns the transaction ID from the context ctx.
|
||||
func GetTransactionID(ctx context.Context) string {
|
||||
v, ok := ctx.Value(transactionIDKey).(string)
|
||||
v, ok := ctx.Value(transactionIDCtxKey).(string)
|
||||
if !ok {
|
||||
logger.Log.Warn("Unable to retrieve the transaction ID from request context")
|
||||
return ""
|
||||
@@ -22,14 +29,20 @@ func GetTransactionID(ctx context.Context) string {
|
||||
return v
|
||||
}
|
||||
|
||||
const contentTypeKey = "ContentType"
|
||||
// contentTypeCtxKeyType is a basic type for contentTypeCtxKey.
|
||||
type contentTypeCtxKeyType string
|
||||
|
||||
// contentTypeCtxKey is the contentType accessing key.
|
||||
const contentTypeCtxKey contentTypeCtxKeyType = "contentType"
|
||||
|
||||
// WithContentType populates a context ctx with a content type v.
|
||||
func WithContentType(ctx context.Context, v string) context.Context {
|
||||
return context.WithValue(ctx, contentTypeKey, v)
|
||||
return context.WithValue(ctx, contentTypeCtxKey, v)
|
||||
}
|
||||
|
||||
// GetContentType returns the content type from the context ctx.
|
||||
func GetContentType(ctx context.Context) string {
|
||||
v, ok := ctx.Value(contentTypeKey).(string)
|
||||
v, ok := ctx.Value(contentTypeCtxKey).(string)
|
||||
if !ok {
|
||||
logger.Log.Error("Unable to retrieve the content type from request context")
|
||||
return ""
|
||||
@@ -37,14 +50,20 @@ func GetContentType(ctx context.Context) string {
|
||||
return v
|
||||
}
|
||||
|
||||
const resultFilePathKey = "ResultFilePath"
|
||||
// resultFilePathCtxKeyType is a basic type for resultFilePathCtxKey.
|
||||
type resultFilePathCtxKeyType string
|
||||
|
||||
// resultFilePathCtxKey is the resultFilePath accessing key.
|
||||
const resultFilePathCtxKey resultFilePathCtxKeyType = "resultFilePath"
|
||||
|
||||
// WithResultFilePath populates a context ctx with a result file path v.
|
||||
func WithResultFilePath(ctx context.Context, v string) context.Context {
|
||||
return context.WithValue(ctx, resultFilePathKey, v)
|
||||
return context.WithValue(ctx, resultFilePathCtxKey, v)
|
||||
}
|
||||
|
||||
// GetResultFilePath returns the result file path from the context ctx.
|
||||
func GetResultFilePath(ctx context.Context) string {
|
||||
v, ok := ctx.Value(resultFilePathKey).(string)
|
||||
v, ok := ctx.Value(resultFilePathCtxKey).(string)
|
||||
if !ok {
|
||||
logger.Log.Error("Unable to retrieve the result file path from request context")
|
||||
return ""
|
||||
@@ -52,14 +71,20 @@ func GetResultFilePath(ctx context.Context) string {
|
||||
return v
|
||||
}
|
||||
|
||||
const converterKey = "Converter"
|
||||
// converterCtxKeyType is a basic type for converterCtxKey.
|
||||
type converterCtxKeyType string
|
||||
|
||||
// converterCtxKey is the converter accessing key.
|
||||
const converterCtxKey contentTypeCtxKeyType = "converter"
|
||||
|
||||
// WithConverter populates a context ctx with a converter v.
|
||||
func WithConverter(ctx context.Context, v converters.Converter) context.Context {
|
||||
return context.WithValue(ctx, converterKey, v)
|
||||
return context.WithValue(ctx, converterCtxKey, v)
|
||||
}
|
||||
|
||||
// GetConverter returns the converter from the context ctx.
|
||||
func GetConverter(ctx context.Context) converters.Converter {
|
||||
v, ok := ctx.Value(converterKey).(converters.Converter)
|
||||
v, ok := ctx.Value(converterCtxKey).(converters.Converter)
|
||||
if !ok {
|
||||
logger.Log.Warn("Unable to retrieve the converter from request context")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user