util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextKey is used as key to set/get context.
	ContextKey = "context"

	// ContentTypeJSON : json
	ContentTypeJSON = "application/json"

	// ContentTypeOctetStream: octet stream
	ContentTypeOctetStream = "application/octet-stream"

	// HeaderTraceID is header name for trace id.
	HeaderTraceID = "x-fc-trace-id"

	HeaderContentType = "content-Type"

	HeaderContentLength = "content-Length"

	// HeaderClientIP is the real IP of the remote client
	HeaderClientIP = "clientIP"
)

Header Keys

View Source
const (
	// RESTful API paths
	RootPath               = "/api"
	EnvironmentPath        = "/envs"
	ApplicationPath        = "/apps"
	WorkloadDefinitionPath = "/workloads"
	ScopeDefinitionPath    = "/scopes"
	TraitDefinitionPath    = "/traits"
	CapabilityPath         = "/capabilities"
	CapabilityCenterPath   = "/capability-centers"
	VersionPath            = "/version"
)

Variables

View Source
var DefaultDashboardPort = ":38081"

Functions

func AssembleResponse

func AssembleResponse(c *gin.Context, data interface{}, err error)

func ConstructError

func ConstructError(ec Code, a ...interface{}) error

ConstructError returns a new OpError.

func GetContext

func GetContext(c *gin.Context) context.Context

get the context from the gin context

func HandleError

func HandleError(c *gin.Context, code Code, msg ...interface{})

func NoRoute

func NoRoute() gin.HandlerFunc

NoRoute is a handler which is invoked when there is no route matches.

func SetContext

func SetContext() gin.HandlerFunc

SetContext :Set context metadata for request Before get request

func SetErrorAndAbort

func SetErrorAndAbort(c *gin.Context, code Code, msg ...interface{})

- use setErrorAndAbort to abort the rest of the handlers, mostly called in middleware

func SetRequestID

func SetRequestID() gin.HandlerFunc

SetRequestID ...

func StoreClient

func StoreClient(kubeClient client.Client) gin.HandlerFunc

func URL

func URL(url string) string

func ValidateHeaders

func ValidateHeaders() gin.HandlerFunc

ValidateHeaders validates the common headers.

It reports one problem at a time.

Types

type Code

type Code int

Code defines the error code type.

const (
	PathNotSupported Code = iota
	InvalidArgument
	UnsupportedMediaType
	StatusInternalServerError
)

Be careful, below constants must be added to the errorDetails map. All code should be defined between StartMarker and EndMarker

func (Code) ID

func (c Code) ID() string

ID returns the error ID.

func (Code) Message

func (c Code) Message() string

Message returns the detailed error message.

func (Code) StatusCode

func (c Code) StatusCode() int

StatusCode returns the http status code.

type ContextKeyType

type ContextKeyType string
const (
	// ServiceLogFields shared key service log fields
	ServiceLogFields ContextKeyType = "ServiceLogFields"

	// HeaderRequestID is used as key to set/get request id.
	HeaderRequestID ContextKeyType = "x-fc-request-id"
)

Jump to

Keyboard shortcuts

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