pb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

Object Data Transfer Tool

The pb/converter.go contains a tool to transfer data from service/API (pb generated) objects to ORM compatible objects, because PB generated objects do not follow golint case requirements (i.e. Ip or Id instead of IP and ID), and have special handling for nullable values (Well-Known-Types wrappers).

The generated nature also prevents any custom ORM or SQL level tags from being added to the Protocol Buffer objects.

This tool uses reflection to transfer between fields of the same name, case insensitively, and for the WKTs from wrappers.StringValue to *string, and wrappers.UInt32Value to *uint32.

More complicated PB behavior, such as oneof and maps is not currently convertible.

Note that this requires the definition of an ORM compatible object from the Protocol Buffer generated objects with the proper types and foreign keys defined for child objects.

Additional fields desired in the DB, but not exposed in the API, potentially such as create/update times, and any necessary SQL or ORM tags can be defined in this ORMified object.

package pb // import "github.com/infobloxopen/atlas-app-toolkit/pb"

func Convert(source interface{}, dest interface{}) error
    Convert Copies data between fields at ORM and service levels. Works under
    the assumption that any WKT fields in proto map to * fields at ORM.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(source interface{}, dest interface{}) error

Convert Copies data between fields at ORM and service levels. Works under the assumption that any WKT fields in proto map to * fields at ORM.

Types

type Interface

type Interface struct {
	ID        uint
	CreatedAt time.Time
	UpdatedAt time.Time

	WBRID           uint
	Name            string
	IPAddress       string
	Type            string
	GreKey          *string
	LlInterfaceName *string
	TTL             *uint32
}

Interface is the gorm compatible version of InterfaceRsrc from above

func InterfaceRsrcToGORM

func InterfaceRsrcToGORM(iface InterfaceRsrc) *Interface

InterfaceRsrcToGORM ...

type InterfaceRsrc

type InterfaceRsrc struct {
	Name            string                        `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	IpAddress       string                        `protobuf:"bytes,2,opt,name=ip_address,json=ipAddress" json:"ip_address,omitempty"`
	Type            string                        `protobuf:"bytes,3,opt,name=type" json:"type,omitempty"`
	GreKey          *google_protobuf1.StringValue `protobuf:"bytes,4,opt,name=gre_key,json=greKey" json:"gre_key,omitempty"`
	LlInterfaceName *google_protobuf1.StringValue `protobuf:"bytes,5,opt,name=ll_interface_name,json=llInterfaceName" json:"ll_interface_name,omitempty"`
	Ttl             *google_protobuf1.UInt32Value `protobuf:"bytes,6,opt,name=ttl" json:"ttl,omitempty"`
}

InterfaceRsrc pulled from a protobuf generated file

type WBR

type WBR struct {
	ID        uint32
	CreatedAt time.Time
	UpdatedAt time.Time

	OphID          string
	Name           string
	SerialNumber   string
	Location       string
	BgpPassword    *string
	BgpAsn         *uint32
	AggregateRoute *string
	Network        *string
	Description    string
	Interfaces     []Interface
}

WBR is the gorm compatible version of WBRRsrc from above

func WBRRsrcToGORM

func WBRRsrcToGORM(wbr WBRRsrc) *WBR

WBRRsrcToGORM ...

type WBRRsrc

type WBRRsrc struct {
	Id             uint32                        `protobuf:"varint,11,opt,name=id" json:"id,omitempty"`
	OphId          string                        `protobuf:"bytes,1,opt,name=oph_id,json=ophId" json:"oph_id,omitempty"`
	Name           string                        `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
	SerialNumber   string                        `protobuf:"bytes,3,opt,name=serial_number,json=serialNumber" json:"serial_number,omitempty"`
	Location       string                        `protobuf:"bytes,4,opt,name=location" json:"location,omitempty"`
	BgpPassword    *google_protobuf1.StringValue `protobuf:"bytes,5,opt,name=bgp_password,json=bgpPassword" json:"bgp_password,omitempty"`
	BgpAsn         *google_protobuf1.UInt32Value `protobuf:"bytes,6,opt,name=bgp_asn,json=bgpAsn" json:"bgp_asn,omitempty"`
	AggregateRoute *google_protobuf1.StringValue `protobuf:"bytes,7,opt,name=aggregate_route,json=aggregateRoute" json:"aggregate_route,omitempty"`
	Network        *google_protobuf1.StringValue `protobuf:"bytes,8,opt,name=network" json:"network,omitempty"`
	Description    string                        `protobuf:"bytes,9,opt,name=description" json:"description,omitempty"`
	Interfaces     []*InterfaceRsrc              `protobuf:"bytes,10,rep,name=interfaces" json:"interfaces,omitempty"`
}

WBRRsrc pulled from a protobuf generated file

type WBRWithBloat

type WBRWithBloat struct {
	ID        uint32
	CreatedAt time.Time
	UpdatedAt time.Time

	Name           string
	SerialNumber   string
	Location       string
	BgpPassword    *string
	BgpAsn         *uint32
	AggregateRoute *string
	Network        *string
	Description    string
	Interfaces     []Interface

	Bloat1  string
	Bloat2  string
	Bloat3  string
	Bloat4  string
	Bloat5  string
	Bloat6  string
	Bloat7  string
	Bloat8  string
	Bloat9  string
	Bloat10 string
	Bloat11 string
	Bloat12 string

	OphID string
}

WBRWithBloat also has a number of unused fields before the last case mismatch

Jump to

Keyboard shortcuts

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