New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/imshealth/go-decorator

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/imshealth/go-decorator

  • v0.0.0-20160517182429-93dc1eabb7ee
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go-Decorator

go-decorator creates an implementation of an interface suitable for the decorator pattern.

Motivation

Rather than adding logging to every method of an api, write one logging method and add it to every method of an interface. This could also be used for

Using go-decorator

Generate the decorator

$ go-decorator -type MyApi myapi.go > myapi_decorator.go

Go-decorator will include the necessary imports, and place the resulting structure in the same package.

If the generated import list is missing a library, use the -import flag to add it.

$ go-decorator -type MyApi -import github.com/... myapi.go

In code

    logMethod := func(name string, call func() error) {
        err := call()
        log.Infof("Called Method %s, error? %v", name, err)
        return err
    }

    api := &MyApi{}
    api = MyApiDecorator{Inner: api, Decorator: logMethod}

    // use API as before, it implements the same interface!
    ...

Contributing

Missing a feature? Open an issue or fork and send over a pull request.

License

This work is published under the MIT license.

Please see the LICENSE file for details.

FAQs

Package last updated on 17 May 2016

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