Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/furkanadiiguzel/go-decorator

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/furkanadiiguzel/go-decorator

  • v0.0.0-20231215113652-7ea1551dc7ab
  • Source
  • Go
  • Socket score

Version published
Created
Source

Decorator Pattern Examples in Go

This repository showcases examples of the decorator pattern implemented in the Go programming language. The decorator pattern is a structural design pattern that allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.

Middleware Example

Files:

  • middleware.go: Illustrates the decorator pattern in the context of HTTP middleware. It includes a basic HTTP server with logging and authentication middlewares.

Usage:

  1. Uncomment the main function in middleware.go.
  2. Run the program to start the HTTP server.
  3. Open your web browser and navigate to http://localhost:8080.
  4. Check the console for request logging.

Order Processing Example

Files:

  • orderprocess.go: Demonstrates the decorator pattern for processing orders. It includes a base order processor, gift wrap decorator, and discount decorator.

Usage:

  1. Run the main function in orderprocess.go.
  2. See how decorators are applied to the base order processor.
  3. Observe the total cost of the decorated order printed to the console.

Pizza Topping Example

Files:

  • pizza.go: Shows the decorator pattern applied to a pizza ordering scenario. It includes an interface IPizza and toppings like TomatoTopping and CheeseTopping.

Usage:

  1. Uncomment the main function in pizza.go.
  2. Run the program to see how toppings are added to a base pizza to calculate the total cost.

Taxi Trip Example

Files:

  • taxi.go: Applies the decorator pattern to a taxi trip scenario with a base taxi and long/short trip decorators.

Usage:

  1. Uncomment the main function in taxi.go.
  2. Run the program to observe how long and short trip decorators modify the base taxi price.

Feel free to explore, modify, and experiment with these examples to deepen your understanding of the decorator pattern in Go.

FAQs

Package last updated on 15 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc