types

package module
v0.0.0-...-d71dbf0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT-0 Imports: 5 Imported by: 0

Documentation

Overview

Package types defines generic type entity structures as they might be stored in a Google Datastore or represented in JSON

Package types defines generic type entity structures as they might be stored in a Google Datastore or represented in JSON

Package types defines generic type entity structures as they might be stored in a Google Datastore or represented in JSON

Index

Constants

View Source
const (
	// KeyPrefixOrder may be combined with an order's UUID ID to form the datastore key name for an order entity
	KeyPrefixOrder = "order:"

	// KeyPrefixOrderItem may be combined with an order item's UUID ID to form the datastore key name for an order item entity
	KeyPrefixOrderItem = "orderitem:"
)
View Source
const (
	// KeyPrefixPerson may be combined with a person's UUID ID to form the datastore key name for a person entity
	KeyPrefixPerson = "person:"
)
View Source
const (
	// KeyPrefixPostalAddress may be combined with a postal address's UUID ID to form the datastore key name for a postal address entity
	KeyPrefixPostalAddress = "postaladdress:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Money

type Money struct {

	// The three-letter currency code defined in ISO 4217.
	CurrencyCode string `datastore:"currencyCode,omitempty" json:"currencyCode,omitempty"`

	// The whole units of the amount.
	// For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar.
	Units int64 `datastore:"units,omitempty" json:"units,omitempty"`

	// Number of nano (10^-9) units of the amount.
	// The value must be between -999,999,999 and +999,999,999 inclusive.
	// If `units` is positive, `nanos` must be positive or zero.
	// If `units` is zero, `nanos` can be positive, zero, or negative.
	// If `units` is negative, `nanos` must be negative or zero.
	// For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
	Nanos int32 `datastore:"nanos,omitempty" json:"nanos,omitempty"`
}

Money is a representation of a currency value that can be directly mapped to the Google APIs protocol buffer representation of money.

Why not use the Google APIs Money structure directly? Well, it includes a mutex which makes it difficult / dangerous to copy and gives rise to compiler warnings. It also lacks the manipulation methods that we might want to add at some point (e.g. like those offered by https://github.com/Rhymond/go-money).

And finally, we want control over how the structure might be stored in a Google Cloud Datastore and JSON.

func MoneyFromPB

func MoneyFromPB(pbm *pbmoney.Money) *Money

MoneyFromPB is a factory method that generates a Money structure from its Protocol Buffer equivalent

If nil is passed in then nil will be returned. This saves the caller from having to check an error that can only occur if the caller is an idiot. Moral: do not pass in nil :-)

func (*Money) AsPBMoney

func (m *Money) AsPBMoney() *pbmoney.Money

AsPBMoney returns the protocol buffer representation of this Money.

type Order

type Order struct {
	// A UUID ID in hexadecimal string form - a unique ID for this order.
	Id string `datastore:"id,noindex" json:"id,omitempty"`

	// SubmissionTime is the time at which cart checkout was completed and the order was submitted for payment
	SubmissionTime Timestamp `datastore:"submissionTime" json:"submissionTime"`

	// Status describes the overall status of the order, summarizing or
	// overriding the status of the individual order items.
	Status OrderStatus `datastore:"status" json:"status"`

	// OrderedBy identifies the person who submitted the order
	OrderedBy *Person `datastore:"orderedBy" json:"orderedBy"`

	// DeliveryAddress is the postal address to which any physical items in the order
	// are to be delivered.
	//
	// NOTE: delivery address is stored as a separate entity in the Google Datastore with
	// the order key as their key ancestor.
	DeliveryAddress *PostalAddress `datastore:"-" json:"deliveryAddress"`

	// OrderItems is the list of one to many items that make up the order.
	//
	// NOTE: order items are stored as separate entities in the Google Datastore with
	// the order key as their key ancestor.
	OrderItems []*OrderItem `datastore:"-" json:"orderItems"`
}

Order is generated by the shopping cart service on checkout. Posted to the event bus by the cart service, it will trigger the payment and/or fulfillment phase.

type OrderItem

type OrderItem struct {
	// Id is a UUID ID in hexadecimal string form - a unique ID for this order item.
	Id string `datastore:"id,noindex" json:"id,omitempty"`

	// OrderId UUID ID in hexadecimal string form - a unique ID for this item's parent order
	OrderId string `datastore:"orderId,noindex" json:"orderId,omitempty"`

	// ProductCode is the equivalent of a SKU code identifying the type of
	// product or service being ordered.
	ProductCode string `datastore:"productCode" json:"productCode"`

	// Quantity is the number of this item type that is being ordered.
	Quantity int32 `datastore:"quantity" json:"quantity"`

	// UnitPrice is the price that the customer was shown for a single item
	// when they selected the item for their cart
	UnitPrice money.Money `datastore:"unitPrice" json:"unitPrice"`

	// The fulfillment state of the oder item as an enumerated value
	Status OrderItemStatus `datastore:"status" json:"status"`
}

OrderItem represents a single entry in an order. An order will contain one to many order items.

type OrderItemStatus

type OrderItemStatus int

OrderItemStatus is an enumeration type defining the status of a single order item

const (
	OisUnspecified   OrderItemStatus = 0
	OisPending       OrderItemStatus = 1
	OisCompleted     OrderItemStatus = 2
	OisRefundPending OrderItemStatus = 3
	OisRefunded      OrderItemStatus = 4
)

type OrderStatus

type OrderStatus int

OrderStatus is an enumeration type defining the overall status of an order

const (
	OsUnspecified        OrderStatus = 0
	OsPending            OrderStatus = 1
	OsCompleted          OrderStatus = 2
	OsCancelled          OrderStatus = 3
	OsPartiallyCancelled OrderStatus = 4
)

type Person

type Person struct {
	Id               string `datastore:"id,omitempty" json:"id,omitempty"`
	FamilyName       string `datastore:"familyName,omitempty" json:"familyName,omitempty"`
	GivenName        string `datastore:"givenName,omitempty" json:"givenName,omitempty"`
	MiddleName       string `datastore:"middleName,omitempty" json:"middleName,omitempty"`
	DisplayName      string `datastore:"displayName,omitempty" json:"displayName,omitempty"`
	DisplayLastFirst string `datastore:"displayNameLastFirst,omitempty" json:"displayNameLastFirst,omitempty"`
}

Person describes a huma individual within the social graph

See https://developers.google.com/people/api/rest/v1/people#Person.Name as field naming reference.

func PersonFromPB

func PersonFromPB(pbPerson *pb.Person) *Person

PersonFromPB is a factory method that generates a Person structure from its Protocol Buffer equivalent

If nil is passed in then nil will be returned. This saves the caller from having to check an error that can only occur if the caller is an idiot. Moral: do not pass in nil :-)

func (*Person) AsPBPerson

func (p *Person) AsPBPerson() *pb.Person

AsPBPerson returns the protocol buffer representation of this Person.

type PostalAddress

type PostalAddress struct {
	// RegionCode (Required) id the  CLDR region code of the country/region of the
	// address. This is never inferred and it is up to the user to ensure the value
	// is correct. See http://cldr.unicode.org/ and
	// http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html
	// for details. Example: "CH" for Switzerland.
	RegionCode string `datastore:"regionCode,omitempty" json:"regionCode,omitempty"`

	// LanguageCode (Optional) is BCP-47 language code of the contents of this address
	// (if known). This is often the UI language of the input form or is expected
	// to match one of the languages used in the address' country/region, or their
	// transliterated equivalents.
	// This can affect formatting in certain countries, but is not critical
	// to the correctness of the data and will never affect any validation or
	// other non-formatting related operations.
	//
	// If this value is not known, it should be omitted (rather than specifying a
	// possibly incorrect default).
	//
	// Examples: "zh-Hant", "ja", "ja-Latn", "en".
	LanguageCode string `datastore:"languageCode,omitempty" json:"languageCode,omitempty"`

	// PostalCode (Optional) is the postal code of the address. Not all countries use or
	// require postal codes to be present, but where they are used, they may trigger
	// additional validation with other parts of the address (e.g. state/zip
	// validation in the U.S.A.).
	PostalCode string `datastore:"postalCode,omitempty" json:"postalCode,omitempty"`

	// SortingCode (Optional) is additional, country-specific, sorting code. This is not
	// used in most regions. Where it is used, the value is either a string like
	// "CEDEX", optionally followed by a number (e.g. "CEDEX 7"), or just a number
	// alone, representing the "sector code" (Jamaica), "delivery area indicator"
	// (Malawi) or "post office indicator" (e.g. Côte d'Ivoire).
	SortingCode string `datastore:"sortingCode,omitempty" json:"sortingCode,omitempty"`

	// AdministrativeArea (Optional) is the highest administrative subdivision which
	//  is used for postal addresses of a country or region.
	// For example, this can be a state, a province, an oblast, or a prefecture.
	// Specifically, for Spain this is the province and not the autonomous
	// community (e.g. "Barcelona" and not "Catalonia").
	// Many countries don't use an administrative area in postal addresses. E.g.
	// in Switzerland this should be left unpopulated.
	AdministrativeArea string `datastore:"administrativeArea,omitempty" json:"administrativeArea,omitempty"`

	// Locality (Optional) generally refers to the city/town portion of the address.
	// Examples: US city, IT comune, UK post town.
	// In regions of the world where localities are not well defined or do not fit
	// into this structure well, leave locality empty and use address_lines.
	Locality string `datastore:"locality,omitempty" json:"locality,omitempty"`

	// Sublocality (Optional) is a subdivision of the locality of the address.
	// For example, this can be neighborhoods, boroughs, districts.
	Sublocality string `datastore:"sublocality,omitempty" json:"sublocality,omitempty"`

	// AddressLines (Optional) are unstructured address lines describing the lower
	// levels of an address.
	//
	// Because values in address_lines do not have type information and may
	// sometimes contain multiple values in a single field (e.g.
	// "Austin, TX"), it is important that the line order is clear. The order of
	// address lines should be "envelope order" for the country/region of the
	// address. In places where this can vary (e.g. Japan), address_language is
	// used to make it explicit (e.g. "ja" for large-to-small ordering and
	// "ja-Latn" or "en" for small-to-large). This way, the most specific line of
	// an address can be selected based on the language.
	//
	// The minimum permitted structural representation of an address consists
	// of a region_code with all remaining information placed in the
	// address_lines. It would be possible to format such an address very
	// approximately without geocoding, but no semantic reasoning could be
	// made about any of the address components until it was at least
	// partially resolved.
	//
	// Creating an address only containing a region_code and address_lines, and
	// then geocoding is the recommended way to handle completely unstructured
	// addresses (as opposed to guessing which parts of the address should be
	// localities or administrative areas).
	AddressLines []string `datastore:"addressLines,omitempty" json:"addressLines,omitempty"`

	// Recipients (Optional) are the recipients at the address.
	// This field may, under certain circumstances, contain multiline information.
	// For example, it might contain "care of" information.
	Recipients []string `datastore:"recipients,omitempty" json:"recipients,omitempty"`

	// Organization (Optional) is the name of the organization (e.g. business) at
	// the address.
	Organization string `datastore:"organization,omitempty" json:"organization,omitempty"`

	// MailboxId (Optional) is the identifier of a mailbox at this address. Used in the
	// case where multiple entities may be registered at the same address, divided
	// by per entity delivery boxes.
	//
	// Some address values might specify the mailbox as an address line but this field
	// allows for a mailbox to be explicitly labeled in the data.
	MailboxId string `datastore:"mailboxId,omitempty" json:"mailboxId,omitempty"`
}

PostalAddress represents a postal address, e.g. for postal delivery or payments addresses. Given a postal address, a postal service can deliver items to a premise, P.O. Box or similar. It is not intended to model geographical locations (roads, towns, mountains).

In typical usage an address would be created via user input or from importing existing data, depending on the type of process.

Advice on address input / editing:

For more guidance on how to use this schema, please see: https://support.google.com/business/answer/6397478

func PostalAddressFromPB

func PostalAddressFromPB(p *pb.PostalAddress) *PostalAddress

PostalAddressFromPB is a factory method that generates a PostalAddress structure from its Protocol Buffer equivalent

If nil is passed in then nil will be returned. This saves the caller from having to check an error that can only occur if the caller is an idiot. Moral: do not pass in nil :-)

func (*PostalAddress) AsPBPostalAddress

func (p *PostalAddress) AsPBPostalAddress() *pb.PostalAddress

AsPBPostalAddress returns the protocol buffer representation of this Person.

type Timestamp

type Timestamp interface {

	// GetTime returns the underlying time.Time value.
	GetTime() time.Time

	// GetPBTimestamp returns the time value as a google.protobuf.Timestamp protocol
	// buffer value.
	GetPBTimestamp() *timestamppb.Timestamp

	// String returns the time value as an RFC 3339 UTC string value to nanosecond accuracy.
	String() string
}

Timestamp defines the interface for a time structure capable of capturing a time as either an RFC 3339 UTC string or a google.protobuf.Timestamp protocol buffer value.

func NewTimestamp

func NewTimestamp(t time.Time) Timestamp

NewTimestamp is a factory method returning a Timestamp value reference for a given time.

func TimestampFromPBTimestamp

func TimestampFromPBTimestamp(timepb *timestamppb.Timestamp) (Timestamp, error)

TimestampFromPBTimestamp is a factory method returning a Timestamp value reference set to translation of a Google protocol buffer timestamp value. If the value cannot be translated (i.e. if the input is not a valid time representation) then an error is returned.

func TimestampFromRFC3339Nano

func TimestampFromRFC3339Nano(timeStr string) (Timestamp, error)

TimestampFromRFC3339Nano is a factory method returning a Timestamp value reference set to parsed value of an UTC RFC 3339 string accurate to a nanosecond. If the supplied time cannot be parsed, an error is returned.

func TimestampNow

func TimestampNow() Timestamp

TimestampNow is a factory method returning a Timestamp value reference to the time right now.

Jump to

Keyboard shortcuts

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