Documentation ¶
Index ¶
- Constants
- func EncodeResponse(response interface{}) []byte
- func EncodeResponseNoHeader(response interface{}) []byte
- func EncodeToResponse(w http.ResponseWriter, response interface{}) error
- func EncodeToResponseNoHeader(w http.ResponseWriter, response interface{}) error
- func GetAuthHeaders(ctx context.Context) (*auth.AuthHeader, error)
- func GetBoxData(ctx context.Context) (*accessbox.Box, error)
- func GetClientTime(ctx context.Context) (time.Time, error)
- func GetReqLog(ctx context.Context) *zap.Logger
- func GetRequestID(v interface{}) string
- func SetAuthHeaders(ctx context.Context, header *auth.AuthHeader) context.Context
- func SetBoxData(ctx context.Context, box *accessbox.Box) context.Context
- func SetClientTime(ctx context.Context, newTime time.Time) context.Context
- func SetReqInfo(ctx context.Context, req *ReqInfo) context.Context
- func SetReqLogger(ctx context.Context, log *zap.Logger) context.Context
- func StartHTTPServerSpan(r *http.Request, operationName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) int
- func WriteErrorResponseNoHeader(w http.ResponseWriter, reqInfo *ReqInfo, err error)
- func WriteResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType)
- func WriteResponseBody(w http.ResponseWriter, response []byte)
- func WriteSuccessResponseHeadersOnly(w http.ResponseWriter)
- type BucketResolveFunc
- type ErrorResponse
- type Func
- func AddBucketName(l *zap.Logger) Func
- func AddObjectName(l *zap.Logger) Func
- func Auth(center auth.Center, log *zap.Logger) Func
- func LogSuccessResponse(l *zap.Logger) Func
- func Metrics(log *zap.Logger, resolveBucket BucketResolveFunc, ...) Func
- func Request(log *zap.Logger) Func
- func Tracing() Func
- func WrapHandler(handler http.HandlerFunc) Func
- type KeyVal
- type ObjectRequest
- type ReqInfo
- type UsersStat
Constants ¶
const ( // MimeNone means no response type. MimeNone mimeType = "" // MimeXML means response type is XML. MimeXML mimeType = "application/xml" )
const (
BucketURLPrm = "bucket"
)
const HdrAmzRequestID = "x-amz-request-id"
Variables ¶
This section is empty.
Functions ¶
func EncodeResponse ¶
func EncodeResponse(response interface{}) []byte
EncodeResponse encodes the response headers into XML format.
func EncodeResponseNoHeader ¶
func EncodeResponseNoHeader(response interface{}) []byte
EncodeResponseNoHeader encodes response without setting xml.Header. Should be used with periodicXMLWriter which sends xml.Header to the client with whitespaces to keep connection alive.
func EncodeToResponse ¶
func EncodeToResponse(w http.ResponseWriter, response interface{}) error
EncodeToResponse encodes the response into ResponseWriter.
func EncodeToResponseNoHeader ¶
func EncodeToResponseNoHeader(w http.ResponseWriter, response interface{}) error
EncodeToResponseNoHeader encodes the response into ResponseWriter without header status.
func GetAuthHeaders ¶
func GetAuthHeaders(ctx context.Context) (*auth.AuthHeader, error)
GetAuthHeaders extracts auth.AuthHeader from context.
func GetBoxData ¶
GetBoxData extracts accessbox.Box from context.
func GetClientTime ¶
GetClientTime extracts time.Time from context.
func GetRequestID ¶
func GetRequestID(v interface{}) string
GetRequestID returns the request ID from the response writer or the context.
func SetAuthHeaders ¶
SetAuthHeaders sets auth.AuthHeader in the context.
func SetBoxData ¶
SetBoxData sets accessbox.Box in the context.
func SetClientTime ¶
SetClientTime sets time.Time in the context.
func SetReqInfo ¶
SetReqInfo sets ReqInfo in the context.
func SetReqLogger ¶
SetReqLogger sets child zap.Logger in the context.
func StartHTTPServerSpan ¶
func StartHTTPServerSpan(r *http.Request, operationName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartHTTPServerSpan starts root HTTP server span.
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) int
WriteErrorResponse writes error headers.
func WriteErrorResponseNoHeader ¶
func WriteErrorResponseNoHeader(w http.ResponseWriter, reqInfo *ReqInfo, err error)
WriteErrorResponseNoHeader writes XML encoded error to the response body.
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType)
WriteResponse writes given statusCode and response into w (with mType header if set).
func WriteResponseBody ¶
func WriteResponseBody(w http.ResponseWriter, response []byte)
WriteResponseBody writes response into w.
func WriteSuccessResponseHeadersOnly ¶
func WriteSuccessResponseHeadersOnly(w http.ResponseWriter)
WriteSuccessResponseHeadersOnly writes HTTP (200) OK response with no data to the client.
Types ¶
type BucketResolveFunc ¶
BucketResolveFunc is a func to resolve bucket info by name.
type ErrorResponse ¶
type ErrorResponse struct { XMLName xml.Name `xml:"Error" json:"-"` Code string Message string Key string `xml:"Key,omitempty" json:"Key,omitempty"` BucketName string `xml:"BucketName,omitempty" json:"BucketName,omitempty"` Resource string RequestID string `xml:"RequestId" json:"RequestId"` HostID string `xml:"HostId" json:"HostId"` // The region where the bucket is located. This header is returned // only in HEAD bucket and ListObjects response. Region string `xml:"Region,omitempty" json:"Region,omitempty"` // Captures the server string returned in response header. Server string `xml:"-" json:"-"` // Underlying HTTP status code for the returned error. StatusCode int `xml:"-" json:"-"` }
ErrorResponse -- error response format.
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
Error -- Returns S3 error string.
type Func ¶
func AddBucketName ¶
AddBucketName adds bucket name to ReqInfo from context.
func AddObjectName ¶
AddObjectName adds objects name to ReqInfo from context.
func LogSuccessResponse ¶
func Metrics ¶
func Metrics(log *zap.Logger, resolveBucket BucketResolveFunc, appMetrics *metrics.AppMetrics) Func
Metrics wraps http handler for api with basic statistics collection.
func Tracing ¶
func Tracing() Func
Tracing adds tracing support for requests. Must be placed after prepareRequest middleware.
func WrapHandler ¶
func WrapHandler(handler http.HandlerFunc) Func
type ObjectRequest ¶
ObjectRequest represents object request data.
type ReqInfo ¶
type ReqInfo struct { sync.RWMutex RemoteHost string // Client Host/IP Host string // Node Host/IP UserAgent string // User Agent DeploymentID string // random generated s3-deployment-id RequestID string // x-amz-request-id API string // API name -- GetObject PutObject NewMultipartUpload etc. BucketName string // Bucket name ObjectName string // Object name TraceID string // Trace ID URL *url.URL // Request url // contains filtered or unexported fields }
ReqInfo stores the request info.
func GetReqInfo ¶
GetReqInfo returns ReqInfo if set. If ReqInfo isn't set returns new empty ReqInfo.
func NewReqInfo ¶
func NewReqInfo(w http.ResponseWriter, r *http.Request, req ObjectRequest) *ReqInfo
NewReqInfo returns new ReqInfo based on parameters.
func (*ReqInfo) AppendTags ¶
AppendTags -- appends key/val to ReqInfo.tags.