V2 is compliant with api.openshift.com design guidelines. Errors are predefined, have codes, and are queryable. All requests have an operationId set: a unique identifier which is sortable by time. This is added to the response in case of an error. All returned objects have the href, id, and kind field set.
22 lines
507 B
Go
22 lines
507 B
Go
package common
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/segmentio/ksuid"
|
|
)
|
|
|
|
const OperationIDKey string = "operationID"
|
|
|
|
// Adds a time-sortable globally unique identifier to an echo.Context if not already set
|
|
func OperationIDMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
if c.Get(OperationIDKey) == nil {
|
|
c.Set(OperationIDKey, GenerateOperationID())
|
|
}
|
|
return next(c)
|
|
}
|
|
}
|
|
|
|
func GenerateOperationID() string {
|
|
return ksuid.New().String()
|
|
}
|