Documentation ¶
Overview ¶
Package xlist defines an API to implement RBL services.
This package is a work in progress and makes no API stability promises.
Index ¶
Constants ¶
const NeverCache = -1
NeverCache is a special value for TTL. If TTLs has this value, caches should not store the response.
Variables ¶
var ( ErrCanceledRequest = errors.New("xlist: canceled request") ErrBadRequest = errors.New("xlist: bad request") ErrNotSupported = errors.New("xlist: resource not supported") ErrInternal = errors.New("xlist: internal error") )
Some standard errors returned by interfaces.
Resources is an ordered vector that constains all valid resource values. Warning: It's a variable for simplicity, Do not modify the value!.
Functions ¶
func Canonicalize ¶
Canonicalize returns true if the name is of the resource type and returns a string with name canonicalized to the resource type.
func DoValidation ¶
func DoValidation(ctx context.Context, name string, resource Resource, force bool) (string, context.Context, error)
DoValidation validates the name and the resource type, and canonicalizes de name. If the resource is valid, it will return a context with a flag that indicates that future calls to the function should not validate the resource again, avoiding redundant validations. A validation can be forced if the force flag is set. If the validation is not successful, and error will be returned. This function must be used by the components that implement the interface Check and it should not be used outside of this context. To validate in any other use case, the function ValidResource must be used.
func ValidResource ¶
ValidResource returns true if the name is of the resource type.
Types ¶
type Checker ¶
type Checker interface { // Check method checks if the value encoded as string is in the list Check(ctx context.Context, name string, r Resource) (Response, error) // Resources returns an array with the resource types supported by the RBL service Resources(ctx context.Context) ([]Resource, error) }
Checker is the interface for check lists.
type Resource ¶
type Resource int
Resource stores the type of resource used by the RBLs.
List of valid resources at the current time.
func ClearResourceDups ¶
ClearResourceDups returns an ordered array (if doShort) with duplicate and invalid resource items removed.
func ResourceType ¶
ResourceType tries to guess the resource type of the string passed. Returns an error if the type can't be guessed.
func ToResource ¶
ToResource returns the resource type from its string representation.
func (Resource) InArray ¶
InArray returns true if the resource value exists in the array passed as parameter.
func (Resource) MarshalJSON ¶
MarshalJSON implements interface for struct marshalling.
func (*Resource) UnmarshalJSON ¶
UnmarshalJSON implements interface for struct unmarshalling.
type Response ¶
type Response struct { // Result is true if the value is in the list Result bool `json:"result"` // Reason stores the reason why it is the list (or not if you want) Reason string `json:"reason,omitempty"` // TTL is a number in seconds used for caching TTL int `json:"ttl"` }
Response stores information about the service's responses.
Directories ¶
Path | Synopsis |
---|---|
grpc
|
|
check
Package check implements a xlist.Checker client and a ready to use service component.
|
Package check implements a xlist.Checker client and a ready to use service component. |
Package parallel allows multiple checks in paralell using xlist.Check interface.
|
Package parallel allows multiple checks in paralell using xlist.Check interface. |