Documentation ¶
Index ¶
- Constants
- Variables
- func GetBearerToken(ctx context.Context) string
- func GetHeaderFromContext(ctx context.Context, key string) (string, bool)
- func GetHeaderValue(headers metadata.MD, key string) (string, bool)
- func GetListenPort(v uint16) string
- func NewClientTLSFromBase64(certB64, serverNameOverride string) (credentials.TransportCredentials, error)
- func OverrideMessage(message string) errx.SetOptionFn
- func SetSubject(ctx context.Context, id, fullName, role string) context.Context
- func WithStatus(status codes.Code) errx.SetOptionFn
- func X509KeyPairFromBase64(certB64, keyB64 string) (*tls.Certificate, error)
- type BasicAuth
- type ContextKey
- type ErrorDetails
- func (*ErrorDetails) Descriptor() ([]byte, []int)deprecated
- func (x *ErrorDetails) GetCode() string
- func (x *ErrorDetails) GetMessage() string
- func (x *ErrorDetails) GetSource() *ErrorDetails_Source
- func (*ErrorDetails) ProtoMessage()
- func (x *ErrorDetails) ProtoReflect() protoreflect.Message
- func (x *ErrorDetails) Reset()
- func (x *ErrorDetails) String() string
- type ErrorDetails_Source
- func (*ErrorDetails_Source) Descriptor() ([]byte, []int)deprecated
- func (x *ErrorDetails_Source) GetMessage() string
- func (x *ErrorDetails_Source) GetMetadata() map[string]string
- func (x *ErrorDetails_Source) GetTraces() []string
- func (*ErrorDetails_Source) ProtoMessage()
- func (x *ErrorDetails_Source) ProtoReflect() protoreflect.Message
- func (x *ErrorDetails_Source) Reset()
- func (x *ErrorDetails_Source) String() string
- type RequestHandler
- type RequestMetadata
- type Subject
Constants ¶
const ( HeaderRealIP = "x-real-ip" HeaderForwardedFor = "x-forwarded-for" HeaderSubjectId = "x-subject-id" HeaderSubjectFullName = "x-subject-name" HeaderSubjectRole = "x-subject-role" HeaderGatewayUserAgent = "x-gateway-user-agent" HeaderRequestId = "x-request-id" HeaderHttpStatus = "x-http-status" HeaderUserAgent = "user-agent" HeaderContentType = "Content-Type" )
const ( KeyGrpcStatus = "grpcStatus" KeyOverrideMessage = "message" KeyErrorMetadata = "errorMetadata" )
const ( ResponseCodeSuccess = "OK" ResponseMessageSuccess = "Success" )
const ( GrpcMetadataHttpStatus = "Grpc-Metadata-X-Http-Status" GrpcMetadataContentType = "Grpc-Metadata-Content-Type" GrpcMetadataRequestId = "Grpc-Metadata-X-Request-Id" )
Variables ¶
var AnonymousUser = Subject{
Id: "ANON",
FullName: "Anonymous User",
Role: "USER",
}
var BadRequestError = b.NewError("400", "Bad Request", WithStatus(codes.InvalidArgument), )
var CancelError = b.NewError("408", "Request Canceled", WithStatus(codes.Canceled), )
var File_error_details_proto protoreflect.FileDescriptor
var ForbiddenError = b.NewError("403", "Forbidden", WithStatus(codes.PermissionDenied), )
var InternalError = b.NewError("500", "Internal Error", WithStatus(codes.Internal), )
var NotFoundError = b.NewError("404", "Not Found", WithStatus(codes.NotFound), )
Functions ¶
func GetBearerToken ¶
func GetHeaderFromContext ¶
func GetListenPort ¶
func NewClientTLSFromBase64 ¶
func NewClientTLSFromBase64(certB64, serverNameOverride string) (credentials.TransportCredentials, error)
NewClientTLSFromBase64 constructs TLS credentials from the provided root certificate authority certificate file(s) to validate server connections. If certificates to establish the identity of the client need to be included in the credentials (eg: for mTLS), use NewTLS instead, where a complete tls.Config can be specified. serverNameOverride is for testing only. If set to a non-empty string, it will override the virtual host name of authority (e.g. :authority header field) in requests.
func OverrideMessage ¶
func OverrideMessage(message string) errx.SetOptionFn
func WithStatus ¶
func WithStatus(status codes.Code) errx.SetOptionFn
func X509KeyPairFromBase64 ¶
func X509KeyPairFromBase64(certB64, keyB64 string) (*tls.Certificate, error)
X509KeyPairFromBase64 parses a public/private key pair from a pair of PEM encoded data. On successful return, Certificate. Leaf will be nil because the parsed form of the certificate is not retained.
Encoded certificate and key is base64 encoded string
Types ¶
type BasicAuth ¶
func GetBasicAuth ¶
type ContextKey ¶
type ContextKey string
const ( ContextKeyBasicAuth ContextKey = "basic-auth" ContextKeyBearerToken ContextKey = "bearer-token" ContextKeyRequestMetadata ContextKey = "request-metadata" ContextKeySubject ContextKey = "subject" )
type ErrorDetails ¶
type ErrorDetails struct { Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` Source *ErrorDetails_Source `protobuf:"bytes,3,opt,name=source,proto3" json:"source,omitempty"` // contains filtered or unexported fields }
func NewErrorDetails ¶
func NewErrorDetails(err error, withSource bool) (codes.Code, *ErrorDetails)
func (*ErrorDetails) Descriptor
deprecated
func (*ErrorDetails) Descriptor() ([]byte, []int)
Deprecated: Use ErrorDetails.ProtoReflect.Descriptor instead.
func (*ErrorDetails) GetCode ¶
func (x *ErrorDetails) GetCode() string
func (*ErrorDetails) GetMessage ¶
func (x *ErrorDetails) GetMessage() string
func (*ErrorDetails) GetSource ¶
func (x *ErrorDetails) GetSource() *ErrorDetails_Source
func (*ErrorDetails) ProtoMessage ¶
func (*ErrorDetails) ProtoMessage()
func (*ErrorDetails) ProtoReflect ¶
func (x *ErrorDetails) ProtoReflect() protoreflect.Message
func (*ErrorDetails) Reset ¶
func (x *ErrorDetails) Reset()
func (*ErrorDetails) String ¶
func (x *ErrorDetails) String() string
type ErrorDetails_Source ¶
type ErrorDetails_Source struct { Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` Traces []string `protobuf:"bytes,2,rep,name=traces,proto3" json:"traces,omitempty"` Metadata map[string]string `` /* 157-byte string literal not displayed */ // contains filtered or unexported fields }
func (*ErrorDetails_Source) Descriptor
deprecated
func (*ErrorDetails_Source) Descriptor() ([]byte, []int)
Deprecated: Use ErrorDetails_Source.ProtoReflect.Descriptor instead.
func (*ErrorDetails_Source) GetMessage ¶
func (x *ErrorDetails_Source) GetMessage() string
func (*ErrorDetails_Source) GetMetadata ¶
func (x *ErrorDetails_Source) GetMetadata() map[string]string
func (*ErrorDetails_Source) GetTraces ¶
func (x *ErrorDetails_Source) GetTraces() []string
func (*ErrorDetails_Source) ProtoMessage ¶
func (*ErrorDetails_Source) ProtoMessage()
func (*ErrorDetails_Source) ProtoReflect ¶
func (x *ErrorDetails_Source) ProtoReflect() protoreflect.Message
func (*ErrorDetails_Source) Reset ¶
func (x *ErrorDetails_Source) Reset()
func (*ErrorDetails_Source) String ¶
func (x *ErrorDetails_Source) String() string
type RequestHandler ¶
type RequestMetadata ¶
type RequestMetadata struct { RequestId string `json:"requestId"` ClientIP string `json:"clientIP"` UserAgent string `json:"userAgent"` StartedAt time.Time `json:"startedAt"` }
func GetRequestMetadata ¶
func GetRequestMetadata(ctx context.Context) *RequestMetadata
func NewRequestMetadata ¶
func NewRequestMetadata(ctx context.Context, trustProxy string) RequestMetadata