Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): add package-level functions #208

Merged
merged 4 commits into from
Feb 9, 2022
Merged

Conversation

nikoksr
Copy link
Owner

@nikoksr nikoksr commented Feb 8, 2022

Description

Similar to some packages of the standard libarary (e.g. log) Notify now has a global but private standard instance that gets created on initialization. This is more of a convenience feature as it potentially saves a single step when interacting with Notify. Functions like UseServices and Send are now usable directly from the package. Think of how you can use log.Print(...) directly but can also create and use a logger instance with log.New(...).

In the following we assume that s is a fully initialized Notify service.

Example(old):

  n := notify.New()
  n.UseServices(s)
  n.Send(...)

Example(new):

  notify.UseServices(s)
  notify.Send(...)

Of course the function New still exists! This is a non-breaking change that, in a sense, just adds some syntactic-sugar.

Motivation and Context

Make the interaction with Notify optionally easier and more intuitiv.

How Has This Been Tested?

Wrote a small tool that uses my local version of Notify, created some services and send messages through them.

Screenshots / Output (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Turning the receiver into a pointer for conistency. I've tested this,
it should not be a breaking change!
Similar to some packages of the standard libarary (e.g. log) Notify now
has a global but private standard instance that gets created on initialization.
This is more of a convenience feature as it potentially saves a single
step when interacting with Notify. Functions like 'UseServices' and
'Send' are now usable directly from the package.

In the following we assume 's' is a fully initialized Notify service.

Example(old):

  n := notify.New()
  n.UseServices(s)
  n.Send(...)

Example(new):

  notify.UseServices(s)
  notify.Send(...)

Of course the New function still exists! This is a non-breaking change
that, in a sense, just adds some syntactic-sugar.
@nikoksr nikoksr added the type/feature New feature or request label Feb 8, 2022
@nikoksr nikoksr merged commit f7144f6 into main Feb 9, 2022
@nikoksr nikoksr deleted the feat/package-level-functions branch February 9, 2022 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M type/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant