resource

package
Version: v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Resource

A number of application services require a mechanism to encode the identity of a particular resource across applications. The resource identifiers consist of the application ID, an application-defined resource type, and an application-defined ID for that resource. The reference format captures the same information as the three-tuple format, in a single string delimited by /:

<app_id>/<resource_type>/<resource_id>

Defining your proto

The common representation of resource identifiers defined in Protocol Buffer format you could find in resource.proto file. The message Identifier implements jsonpb.JSONPBMarshaler and jsonpb.JSONPBUnmarshaler interfaces so that it renders itself in JSON as a string in a single string delimited by /.

You could use it to define identifiers in your proto messages, e.g.

syntax = "proto3";

import "github.com/infobloxopen/atlas-app-toolkit/rpc/resource/resource.proto";

message MyMessage {
    atlas.rpc.Identifier id = 1;
    string some_data = 2;
    atlas.rpc.Identifier reference_on_external_resource = 3;
    atlas.rpc.Identifier foreign_id_of_internal_resource = 4;
}

Please give a read to README of gorm/resource package to see how it could be used with gorm and protoc-gen-gorm generated code.

Utility functions

Package provides several utility functions to operate with resource identifier.

Check that an Identifier is nil

In order to check that an identifier is nil use resource.Nil function.

package main

import (
	"fmt"
	
	"github.com/infobloxopen/atlas-app-toolkit/rpc/resource"
)

func main() {
    var id *resource.Identifier
	
    if resource.Nil(id) {
    	fmt.Println("resource is nil identifier")
    }
}

See unit test for more details.

Documentation

Index

Constants

View Source
const (
	// Delimiter of Resource Reference according to Atlas Reference format
	Delimiter = "/"
)

Variables

This section is empty.

Functions

func BuildString

func BuildString(aname, rtype, rid string) string

BuildString builds string id according to Atlas Reference format:

<application_name>/<resource_type>/<resource_id>

func Nil added in v0.10.0

func Nil(id *Identifier) (ok bool)

Nil reports whether id is empty identifier or not. The id is empty if it is either nil or could be converted to the empty string by its String method.

func ParseString

func ParseString(id string) (aname, rtype, rid string)

ParseString parses id according to Atlas Reference format:

<application_name>/<resource_type>/<resource_id>

All leading and trailing Delimiter are removed. The resource_id is parsed first, then resource type and last application name. The id "/a/b/c/" will be converted to "a/b/c" and returned as (a, b, c). The id "b/c/" will be converted to "b/c" and returned as ("", b, c).

Types

type Identifier

type Identifier struct {
	// An application identifier that will be used among
	// other infrastructure services to identify the application
	ApplicationName string `protobuf:"bytes,1,opt,name=application_name,json=applicationName" json:"application_name,omitempty"`
	// An application specific type name of a resource
	ResourceType string `protobuf:"bytes,2,opt,name=resource_type,json=resourceType" json:"resource_type,omitempty"`
	// An application specific resource identity of a resource
	ResourceId           string   `protobuf:"bytes,3,opt,name=resource_id,json=resourceId" json:"resource_id,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

A number of application services require a mechanism to encode the identity of a particular resource across applications. The resource identifiers consist of the application ID, an application-defined resource type, and an application-defined ID for that resource

func (*Identifier) Descriptor

func (*Identifier) Descriptor() ([]byte, []int)

func (*Identifier) GetApplicationName

func (m *Identifier) GetApplicationName() string

func (*Identifier) GetResourceId

func (m *Identifier) GetResourceId() string

func (*Identifier) GetResourceType

func (m *Identifier) GetResourceType() string

func (Identifier) MarshalJSONPB

func (m Identifier) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error)

MarshalJSONPB implements jsonpb.JSONPBMarshaler interface by marshal Identifier from a JSON string in accordance with Atlas Reference format

<application_name>/<resource_type>/<resource_id>

Support "null" value.

func (Identifier) MarshalText added in v0.7.0

func (m Identifier) MarshalText() (text []byte, err error)

func (*Identifier) ProtoMessage

func (*Identifier) ProtoMessage()

func (*Identifier) Reset

func (m *Identifier) Reset()

func (*Identifier) String

func (m *Identifier) String() string

func (*Identifier) UnmarshalJSONPB

func (m *Identifier) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error

UnmarshalJSONPB implements jsonpb.JSONPBUnmarshaler interface by unmarshal Identifier to a JSON string in accordance with Atlas Reference format

<application_name>/<resource_type>/<resource_id>

Support "null" value.

func (*Identifier) XXX_DiscardUnknown

func (m *Identifier) XXX_DiscardUnknown()

func (*Identifier) XXX_Marshal

func (m *Identifier) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Identifier) XXX_Merge

func (dst *Identifier) XXX_Merge(src proto.Message)

func (*Identifier) XXX_Size

func (m *Identifier) XXX_Size() int

func (*Identifier) XXX_Unmarshal

func (m *Identifier) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL