chainofresponsibility

package
v0.0.0-...-7dcde51 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Example (One)
package main

import "fmt"

func main() {
	wallet := NewWallet("Wechat Pay", 100)
	wallet.Chain(
		NewWallet("Alipay", 80)).Chain(
		NewWallet("Bank Card", 200))

	outputFailedPayment(wallet.Pay(50), 50)
	outputFailedPayment(wallet.Pay(100), 100)
	outputFailedPayment(wallet.Pay(60), 60)
	outputFailedPayment(wallet.Pay(150), 150)

}

func outputFailedPayment(ok bool, amount int) {
	if !ok {
		fmt.Printf("error: wallet balance less then %d$\n", amount)
	}
}
Output:

Wechat Pay: succeed to deduct 50$
Bank Card: succeed to deduct 100$
Alipay: succeed to deduct 60$
error: wallet balance less then 150$

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliPay

type AliPay struct {
	// contains filtered or unexported fields
}

func (*AliPay) Balance

func (p *AliPay) Balance() int

func (*AliPay) Chain

func (p *AliPay) Chain(wallet Wallet) Wallet

func (*AliPay) Pay

func (p *AliPay) Pay(amount int) bool

type BankCardPay

type BankCardPay struct {
	// contains filtered or unexported fields
}

func (*BankCardPay) Balance

func (p *BankCardPay) Balance() int

func (*BankCardPay) Chain

func (p *BankCardPay) Chain(wallet Wallet) Wallet

func (*BankCardPay) Pay

func (p *BankCardPay) Pay(amount int) bool

type Wallet

type Wallet interface {
	Balance() int
	Pay(amount int) bool
	Chain(wallet Wallet) Wallet
}

func NewWallet

func NewWallet(wallet string, balance int) Wallet

type WechatPay

type WechatPay struct {
	// contains filtered or unexported fields
}

func (*WechatPay) Balance

func (p *WechatPay) Balance() int

func (*WechatPay) Chain

func (p *WechatPay) Chain(wallet Wallet) Wallet

func (*WechatPay) Pay

func (p *WechatPay) Pay(amount int) bool

Jump to

Keyboard shortcuts

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