acmeserverless

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 4 Imported by: 30

README

ACME Serverless Fitness Shop

Serverless and Fitness, because combining two amazing things can only lead to more amazing things

Getting Started

These instructions will allow you to run entire ACME Serverless Fitness Shop

The ACME Serverless Fitness Shop contains seven different domains of service:

To get started you'll need:

Supported AWS Services

Data Store

The ACME Serverless Fitness Shop needs to store data. In the list below you can find the supported data store services with a link to the deployment instructions.

Eventing

Wherever possible, the ACME Serverless Fitness Shop uses event-driven communication. In the list below you can find the supported eventing solutions with a link to the deployment instructions.

APIs

All APIs will be accessible through Amazon API Gateway

Hosting

The Point-of-Sales app can be hosted on Amazon S3.

Overview

architecture

The diagram shows how the services in the different domains work together. The architecture above shows the Amazon Simple Queue Service deployment option

Contributing

Pull requests are welcome in their individual repositories. For major changes or questions, please open an issue first to discuss what you would like to change.

License

See the LICENSE file in the repository.

Documentation

Index

Constants

View Source
const (
	// PaymentDomain is the name used for the payment domain
	PaymentDomain = "Payment"

	// CartDomain is the name used for the cart domain
	CartDomain = "Cart"

	// CatalogDomain is the name used for the catalog domain
	CatalogDomain = "Catalog"

	// OrderDomain is the name used for the order domain
	OrderDomain = "Order"

	// ShipmentDomain is the name used for the shipment domain
	ShipmentDomain = "Shipment"

	// CreditCardValidatedEventName is the name used for the CreditCardValidated event
	CreditCardValidatedEventName = "CreditCardValidatedEvent"

	// PaymentRequestedEventName is the name used for the PaymentRequested event
	PaymentRequestedEventName = "PaymentRequestedEvent"

	// ShipmentRequestedEventName is the event name of ShipmentRequested.
	ShipmentRequestedEventName = "ShipmentRequested"

	// ShipmentSentEventName is the event name of ShipmentSent.
	ShipmentSentEventName = "ShipmentSent"

	// ShipmentDeliveredEventName is the event name of ShipmentDelivered.
	ShipmentDeliveredEventName = "ShipmentDelivered"

	// DefaultSuccessStatus is a string representation of the default status for success messages
	DefaultSuccessStatus = "success"

	// DefaultErrorStatus is a string representation of the default status for error messages
	DefaultErrorStatus = "error"
)

Variables

This section is empty.

Functions

func ToSentryMap

func ToSentryMap(i interface{}) map[string]interface{}

ToSentryMap converts the given struct to a map[string]interface{} so it can be sent to Sentry. The keys of the map are the same as the JSON element names. It panics if s's kind is not struct.

Types

type Address

type Address struct {
	// Street is the streetname
	Street *string `json:"street,omitempty"`

	// City is the city name
	City *string `json:"city,omitempty"`

	// Zip is the zip or postal code
	Zip *string `json:"zip,omitempty"`

	// State is the state
	State *string `json:"state,omitempty"`

	// Country is the country where the shipment must be sent
	Country *string `json:"country,omitempty"`
}

Address is an address where the order must be delivered

type AllCatalogItemsResponse

type AllCatalogItemsResponse struct {
	Data []CatalogItem `json:"data"`
}

AllCatalogItemsResponse is the response struct for the reply to the API call to get all products.

func (*AllCatalogItemsResponse) Marshal

func (r *AllCatalogItemsResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of AllCatalogItemsResponse

type AllUsers

type AllUsers struct {
	Data []User `json:"data"`
}

AllUsers is the response struct for the reply to the API call to get all users.

func (*AllUsers) Marshal

func (r *AllUsers) Marshal() ([]byte, error)

Marshal returns the JSON encoding of AllUsers

type Cart

type Cart struct {
	// Items is a slice of Item objects, each being a single object in the cart of the user
	Items []CartItem `json:"cart"`

	// UserID is the unique identifier of the user in the ACME Serverless Fitness Shop
	UserID string `json:"userid"`
}

Cart represents a shoppingcart for a user of the ACME Serverless Fitness Shop

func UnmarshalCart

func UnmarshalCart(data string) (Cart, error)

UnmarshalCart parses the JSON-encoded data and stores the result in a Cart

func (*Cart) Marshal

func (r *Cart) Marshal() ([]byte, error)

Marshal returns the JSON encoding of Cart

type CartItem

type CartItem struct {
	// Description is a description of the items
	Description string `json:"description"`

	// ItemID is the unique identifier of the item
	// This ID is set when the item originates in the cart domain
	ItemID *string `json:"itemid,omitempty"`

	// ID is the unique representation of the item
	// This ID is set when the item originates in the order domain
	ID *string `json:"id,omitempty"`

	// Name is the name of the item
	Name string `json:"name"`

	// Price is the monetairy value of the item
	Price float64 `json:"price"`

	// Quantity is how many of the item the user has in their cart
	Quantity int64 `json:"quantity"`
}

CartItem represents the items that the ACME Serverless Fitness Shop user has in their shopping cart

func UnmarshalItem

func UnmarshalItem(data []byte) (CartItem, error)

UnmarshalItem parses the JSON-encoded data and stores the result in an Item

func (*CartItem) Marshal

func (r *CartItem) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CartItem

type CartItemTotal

type CartItemTotal struct {
	// CartItemTotal is the number of items
	CartItemTotal int64 `json:"cartitemtotal"`

	// UserID is the unique identifier of the user in the ACME Serverless Fitness Shop
	UserID string `json:"userid"`
}

CartItemTotal represents how many items the user currently has in their cart

func (*CartItemTotal) Marshal

func (r *CartItemTotal) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CartTotal

type CartItems

type CartItems []CartItem

Items is a slice of Item objects

func UnmarshalItems

func UnmarshalItems(data string) (CartItems, error)

UnmarshalItems parses the JSON-encoded data and stores the result in an CartItems object

func (*CartItems) Marshal

func (r *CartItems) Marshal() ([]byte, error)

Marshal returns the JSON encoding of Items

type CartValueTotal

type CartValueTotal struct {
	// CartTotal is the value of items
	CartTotal float64 `json:"carttotal"`

	// UserID is the unique identifier of the user in the
	// ACME Serverless Fitness Shop
	UserID string `json:"userid"`
}

CartValueTotal represents the total value of all items currently in the cart of the iser

func (*CartValueTotal) Marshal

func (r *CartValueTotal) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CartValue

type Carts

type Carts []Cart

Carts is a slice of Cart objects

func (*Carts) Marshal

func (r *Carts) Marshal() ([]byte, error)

Marshal returns the JSON encoding of Carts

type CatalogItem

type CatalogItem struct {
	// ID is the unique identifier of the product
	ID string `json:"id"`

	// Name is the name of the product
	Name string `json:"name"`

	// ShortDescription is a short description of the product suited for Point of Sales or mobile apps
	ShortDescription string `json:"shortDescription"`

	// Description is a longer description of the product suited for websites
	Description string `json:"description"`

	// ImageURL1 is the location of the first image
	ImageURL1 string `json:"imageUrl1"`

	// ImageURL2 is the location of the second image
	ImageURL2 string `json:"imageUrl2"`

	// ImageURL3 is the location of the third image
	ImageURL3 string `json:"imageUrl3"`

	// Price is the monetary value of the product
	Price float32 `json:"price"`

	// Tags are keys that represent additional sorting information for front-end displays
	Tags []string `json:"tags"`
}

CatalogItem represents the products as they are stored in the data store

func UnmarshalCatalogItem

func UnmarshalCatalogItem(data string) (CatalogItem, error)

UnmarshalCatalogItem parses the JSON-encoded data and stores the result in a CatalogItem

func (*CatalogItem) Marshal

func (r *CatalogItem) Marshal() ([]byte, error)

Marshal returns the JSON encoding of Product

type CreateCatalogItemResponse

type CreateCatalogItemResponse struct {
	// Message is a status message indicating success or failure
	Message string `json:"message"`

	// ResourceID represents the product that has been created
	// together with the new product ID
	ResourceID CatalogItem `json:"resourceId"`

	// Status is the HTTP status code indicating success or failure
	Status int `json:"status"`
}

CreateCatalogItemResponse is the respons that is sent back to the API after a new item has been added to the catalog.

func (*CreateCatalogItemResponse) Marshal

func (r *CreateCatalogItemResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CreateCatalogItemResponse

type CreditCardValidatedEvent

type CreditCardValidatedEvent struct {
	// Metadata for the event.
	Metadata Metadata `json:"metadata"`

	// Data contains the payload data for the event.
	Data CreditCardValidationDetails `json:"data"`
}

CreditCardValidatedEvent is sent by the payment service when the creditcard has been validated.

func UnmarshalCreditCardValidatedEvent

func UnmarshalCreditCardValidatedEvent(data []byte) (CreditCardValidatedEvent, error)

UnmarshalCreditCardValidatedEvent parses the JSON-encoded data and stores the result in a CreditCardValidatedEvent.

func (*CreditCardValidatedEvent) Marshal

func (e *CreditCardValidatedEvent) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CreditCardValidatedEvent.

type CreditCardValidationDetails

type CreditCardValidationDetails struct {
	// Indicates whether the transaction was a success or not.
	Success bool `json:"success"`

	// The HTTP statuscode of the event.
	Status int `json:"status"`

	// A string containing the result of the service.
	Message string `json:"message"`

	// The monetary amount of the transaction.
	Amount string `json:"amount,omitempty"`

	// The unique identifier of the transaction.
	TransactionID string `json:"transactionID"`

	// The unique identifier of the order.
	OrderID string `json:"orderID"`
}

CreditCardValidationDetails contain the details of the validation by the payment service.

func UnmarshalCreditCardValidationDetails

func UnmarshalCreditCardValidationDetails(data []byte) (CreditCardValidationDetails, error)

UnmarshalCreditCardValidationDetails parses the JSON-encoded data and stores the result in a CreditCardValidationDetails.

func (*CreditCardValidationDetails) Marshal

func (e *CreditCardValidationDetails) Marshal() ([]byte, error)

Marshal returns the JSON encoding of CreditCardValidationDetails.

type LoginRequest

type LoginRequest struct {
	// Username is the username of the user
	Username string `json:"username"`

	// Password is the password of the user
	Password string `json:"password"`
}

LoginRequest is the request to log in to be able to buy new products

func UnmarshalLoginRequest

func UnmarshalLoginRequest(data string) (LoginRequest, error)

UnmarshalLoginRequest parses the JSON-encoded data and stores the result in a LoginRequest

func (*LoginRequest) Marshal

func (r *LoginRequest) Marshal() ([]byte, error)

Marshal returns the JSON encoding of AllUsers

type LoginResponse

type LoginResponse struct {
	// Accesstoken is the JWT access token containing information and claims
	AccessToken string `json:"access_token"`

	// RefreshToken is the token needed to refresh the access token
	RefreshToken string `json:"refresh_token"`

	// Status is the HTTP status code indicating success or failure
	Status int64 `json:"status"`
}

LoginResponse is the response sent to the client to indicate whether or not the user has successfully authenticated

func UnmarshalLoginResponse

func UnmarshalLoginResponse(data string) (LoginResponse, error)

UnmarshalLoginResponse parses the JSON-encoded data and stores the result in a LoginResponse

func (*LoginResponse) Marshal

func (r *LoginResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of LoginResponse

type Metadata

type Metadata struct {
	// Domain represents the the event came from
	// like Payment or Order.
	Domain string `json:"domain"`

	// Source represents the function the event came from
	// like ValidateCreditCard or SubmitOrder.
	Source string `json:"source"`

	// Type respresents the type of event this is
	// like CreditCardValidated.
	Type string `json:"type"`

	// Status represents the current status of the event
	// like Success or Failure.
	Status string `json:"status"`
}

Metadata contains information on the domain, source, type, and status of the event.

type Order

type Order struct {
	// OrderID uniquely identifies the order
	OrderID string `json:"_id"`

	// Status represents the current status of the order
	Status *string `json:"status,omitempty"`

	// UserID represents the user who placed the order
	UserID string `json:"userid,omitempty"`

	// Firstname is the firstname of the user who placed the order
	Firstname *string `json:"firstname,omitempty"`

	// Lastname is the lastname of the user who placed the order
	Lastname *string `json:"lastname,omitempty"`

	// Address is an address where the order must be delivered
	Address *Address `json:"address,omitempty"`

	// Email is the email address to send spam to ;-)
	Email *string `json:"email,omitempty"`

	// Delivery is the delivery method the shipment must use
	Delivery string `json:"delivery"`

	// Creditcard isthe creditcard used to pay the order
	Card creditcard.Card `json:"card,omitempty"`

	// Cart contains all items part of the order
	Cart []CartItem `json:"cart"`

	// Total represents the monetary value of the order
	Total string `json:"total,omitempty"`
}

Order represents an order that is made by a user in the ACME Serverless Fitness Shop.

func UnmarshalOrder

func UnmarshalOrder(data string) (Order, error)

UnmarshalOrder parses the JSON-encoded data and stores the result in a Order object.

func (*Order) Marshal

func (r *Order) Marshal() ([]byte, error)

Marshal returns the JSON encoding of an Order

type OrderStatus

type OrderStatus struct {
	// OrderID uniquely represents an order
	OrderID string `json:"order_id"`

	// Payment is the data that is emitted by the payment service
	Payment CreditCardValidationDetails `json:"payment"`

	// UserID is the unique representation of the user
	UserID string `json:"userid"`
}

OrderStatus represents the current status of an order and is sent by the Order service

func (*OrderStatus) Marshal

func (r *OrderStatus) Marshal() ([]byte, error)

Marshal returns the JSON encoding of OrderStatus

type Orders

type Orders []Order

Orders is a slide of Order objects

func (*Orders) Marshal

func (r *Orders) Marshal() ([]byte, error)

Marshal returns the JSON encoding of Orders.

type PaymentRequestDetails

type PaymentRequestDetails struct {
	// The unique identifier of the order.
	OrderID string `json:"orderID"`

	// Card used for the transaction.
	Card creditcard.Card `json:"card"`

	// Total monetary value of the transaction.
	Total string `json:"total"`
}

PaymentRequestDetails contains the data that is needed to validate the payment.

func UnmarshalPaymentRequestDetails

func UnmarshalPaymentRequestDetails(data []byte) (PaymentRequestDetails, error)

UnmarshalPaymentRequestDetails parses the JSON-encoded data and stores the result in a PaymentRequestDetails.

func (*PaymentRequestDetails) Marshal

func (e *PaymentRequestDetails) Marshal() ([]byte, error)

Marshal returns the JSON encoding of PaymentRequestDetails.

type PaymentRequestedEvent

type PaymentRequestedEvent struct {
	// Metadata for the event.
	Metadata Metadata `json:"metadata"`

	// Data contains the payload data for the event.
	Data PaymentRequestDetails `json:"data"`
}

PaymentRequestedEvent is sent by the Order service when the creditcard for the order should be validated and charged.

func UnmarshalPaymentRequestedEvent

func UnmarshalPaymentRequestedEvent(data []byte) (PaymentRequestedEvent, error)

UnmarshalPaymentRequestedEvent parses the JSON-encoded data and stores the result in a PaymentRequestedEvent.

func (*PaymentRequestedEvent) Marshal

func (e *PaymentRequestedEvent) Marshal() ([]byte, error)

Marshal returns the JSON encoding of PaymentRequestedEvent.

type RegisterUserResponse

type RegisterUserResponse struct {
	// Message is a status message indicating success or failure
	Message string `json:"message"`

	// ResourceID represents the user that has been created together with the new user ID
	ResourceID string `json:"resourceId"`

	// Status is the HTTP status code indicating success or failure
	Status int64 `json:"status"`
}

RegisterUserResponse is sent back to the front-end service after a new user tries to register for the ACME Serverless Fitness Shop

func UnmarshalRegisterUserResponse

func UnmarshalRegisterUserResponse(data string) (RegisterUserResponse, error)

UnmarshalRegisterUserResponse parses the JSON-encoded data and stores the result in a RegisterUserResponse

func (*RegisterUserResponse) Marshal

func (r *RegisterUserResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of RegisterUserResponse

type ShipmentData

type ShipmentData struct {
	// The tracking number generated by the shipper.
	TrackingNumber string `json:"trackingNumber"`

	// The unique identifier of the order.
	OrderNumber string `json:"orderNumber"`

	// The current status of the shipment
	Status string `json:"status"`
}

ShipmentData is the data the shipment service emits when the shipment is sent.

type ShipmentRequest

type ShipmentRequest struct {
	// The unique identifier of the order.
	OrderID string `json:"_id"`

	// Delivery is the delivery method that should be used for the shipment.
	Delivery string `json:"delivery"`
}

ShipmentRequest is the data that the order service emits.

type ShipmentRequested

type ShipmentRequested struct {
	// Metadata for the event.
	Metadata Metadata `json:"metadata"`

	// Data contains the payload data for the event.
	Data ShipmentRequest `json:"data"`
}

ShipmentRequested is the event sent by the Order service when the order is finalized and paid and thus ready to be shipped to the customer

func UnmarshalShipmentRequested

func UnmarshalShipmentRequested(data []byte) (ShipmentRequested, error)

UnmarshalShipmentRequested parses the JSON-encoded data and stores the result in a ShipmentRequestedEvent.

func (*ShipmentRequested) Marshal

func (e *ShipmentRequested) Marshal() ([]byte, error)

Marshal returns the JSON encoding of ShipmentRequested.

type ShipmentSent

type ShipmentSent struct {
	// Metadata for the event.
	Metadata Metadata `json:"metadata"`

	// Data contains the payload data for the event.
	Data ShipmentData `json:"data"`
}

ShipmentSent is the event sent by the Shipment service when the order is shipped to the customer.

func UnmarshalShipmentSent

func UnmarshalShipmentSent(data []byte) (ShipmentSent, error)

UnmarshalShipmentSent parses the JSON-encoded data and stores the result in a ShipmentSent.

func (*ShipmentSent) Marshal

func (e *ShipmentSent) Marshal() ([]byte, error)

Marshal returns the JSON encoding of ShipmentSent.

type ShopCard

type ShopCard struct {
	Number   string `json:"number"`
	ExpYear  string `json:"expYear"`
	ExpMonth string `json:"expMonth"`
	Ccv      string `json:"ccv"`
}

ShopCard allows for backward compatibility between the serverless version and the containerized version of the ACME Fitness Shop. This format should only be used for HTTP based interactions.

func (*ShopCard) ToCreditCard

func (s *ShopCard) ToCreditCard() creditcard.Card

ToCreditCard maps the old shopcard data to the new creditcard and allows for backward compatibility between the serverless version and the containerized version of the ACME Fitness Shop. This format should only be used for HTTP based interactions.

type ShopPayment

type ShopPayment struct {
	Card  ShopCard `json:"card"`
	Total string   `json:"total"`
}

ShopPayment allows for backward compatibility between the serverless version and the containerized version of the ACME Fitness Shop. This format should only be used for HTTP based interactions.

func UnmarshalShopPayment

func UnmarshalShopPayment(data []byte) (ShopPayment, error)

UnmarshalShopPayment parses the JSON-encoded data and stores the result in a ShopPayment.

func (*ShopPayment) Marshal

func (r *ShopPayment) Marshal() ([]byte, error)

Marshal returns the JSON encoding of ShopPayment.

type User

type User struct {
	// ID is the unique identifier of the user in the shop
	ID string `json:"id"`

	// Username is the username of the user
	Username string `json:"username"`

	// Password is the password of the user
	Password string `json:"password"`

	// Firstname is the firstname of the user
	Firstname string `json:"firstname"`

	// Lastname is the lastname of the user
	Lastname string `json:"lastname"`

	// Email is where we need to send spam ;-)
	Email string `json:"email"`
}

User is a single user in the ACME Serverless Fitness Shop

func UnmarshalUser

func UnmarshalUser(data string) (User, error)

UnmarshalUser parses the JSON-encoded data and stores the result in a User

func (*User) Marshal

func (r *User) Marshal() ([]byte, error)

Marshal returns the JSON encoding of User

type UserDetailsResponse

type UserDetailsResponse struct {
	// User are the details about the user
	User User `json:"data"`

	// Status is the HTTP status code indicating success or failure
	Status int `json:"status"`
}

UserDetailsResponse is sent back to the user with details about that specific user

func (*UserDetailsResponse) Marshal

func (r *UserDetailsResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of UserDetailsResponse

type UserIDResponse

type UserIDResponse struct {
	// UserID is the unique identifier of the user in the ACME Serverless Fitness Shop
	UserID string `json:"userid"`
}

UserIDResponse returns the UserID

func (*UserIDResponse) Marshal

func (r *UserIDResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding on UserIDResponse

type VerifyTokenResponse

type VerifyTokenResponse struct {
	// Message is a status message indicating success or failure
	Message string `json:"message"`

	// Status is the HTTP status code indicating success or failure
	Status int `json:"status"`
}

VerifyTokenResponse is sent to the service requesting a validation of the access token

func UnmarshalVerifyTokenResponse

func UnmarshalVerifyTokenResponse(data string) (VerifyTokenResponse, error)

UnmarshalVerifyTokenResponse parses the JSON-encoded data and stores the result in a VerifyTokenResponse

func (*VerifyTokenResponse) Marshal

func (r *VerifyTokenResponse) Marshal() ([]byte, error)

Marshal returns the JSON encoding of VerifyTokenResponse

Directories

Path Synopsis
dynamodb
sqs

Jump to

Keyboard shortcuts

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