requestinfo

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

README

Request Info

Request Info contains following information about the request:

   ApplicationName string
   ResourceType    string
   ResourceId      string
   OperationType   int //Constant 

This package provide annotator witch extracts information from request and return it as metadata.

Adding support for Request Info

You can enable support for Request Info in your gRPC-Server by adding the annotator to the middleware chain.

import (
  ...
  ...
  "github.com/infobloxopen/atlas-app-toolkit/requestinfo"
)
func main() {
    server := grpc.NewServer(
      grpc.UnaryInterceptor(
        runtime.WithMetadata(requestinfo.MetadataAnnotator)
      )
    ...
}

Extracting the Request Info

Once the middleware is included, the function below can be used to extract the Request Info anywhere it is needed.

requestInfo, err := requestinfo.FromContext(ctx)

The err represent error if something went wrong.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHTTPRequestIsMissing   = fmt.Errorf("request is missing")
	ErrInvalidHTTPRequestPath = fmt.Errorf("invalid HTTP request path")
	ErrAppNameIsMissing       = fmt.Errorf("application name is missing in the context object")
	ErrResourceTypeIsMissing  = fmt.Errorf("resource type is missing in the context object")
)

Functions

func MetadataAnnotator

func MetadataAnnotator(ctx context.Context, r *http.Request) metadata.MD

Types

type OperationType

type OperationType int
const (
	CreateOperation OperationType = iota
	ReplaceOperation
	UpdateOperation
	DeleteOperation
	ReadOperation
	ListOperation
	UnknownOperation
)

func GetOperationTypeFromRequest

func GetOperationTypeFromRequest(r *http.Request, hasIdentifier bool) OperationType

func (OperationType) String

func (o OperationType) String() string

type RequestInfo

type RequestInfo struct {
	Identifier    resource.Identifier
	OperationType OperationType
}

func FromContext

func FromContext(ctx context.Context) (RequestInfo, error)

func NewRequestInfo

func NewRequestInfo(r *http.Request) (RequestInfo, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL