util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 11 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 (
	RootPath                = "/api"
	EnvironmentPath         = "/envs"
	ApplicationPath         = "/apps"
	WorkloadDefinitionPath  = "/workloads"
	ComponentDefinitionPath = "/components"
	ScopeDefinitionPath     = "/scopes"
	TraitDefinitionPath     = "/traits"
	CapabilityPath          = "/capabilities"
	CapabilityCenterPath    = "/capability-centers"
	VersionPath             = "/version"
	Definition              = "/definitions"
)

RESTful API paths

View Source
const DefaultAPIServerPort = ":38081"

DefaultAPIServerPort refers to the default port number of APIServer

Variables

View Source
var DefaultDashboardPort = ":38081"

DefaultDashboardPort refers to the default port number of dashboard

Functions

func AssembleResponse

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

AssembleResponse assembles response data to return

func ConstructError

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

ConstructError returns a new OpError.

func GetContext

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

GetContext get the context from the gin context

func HandleError

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

HandleError will handle error

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{})

SetErrorAndAbort is used to abort the rest of the handlers, mostly called in middleware

func SetRequestID

func SetRequestID() gin.HandlerFunc

SetRequestID ...

func URL

func URL(url string) string

URL returns the URL of Dashboard based on default port

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

ContextKeyType defining the context key type for the middleware

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