-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05da947
commit 1c73e84
Showing
7 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# If this config is confusing, have a look here, it is documented from A-Z https://golangci-lint.run/usage/linters | ||
linters-settings: | ||
revive: | ||
max-open-files: 2048 # Maximum number of open files at the same time. | ||
ignore-generated-header: false # When set to false, ignores files with "GENERATED" header, similar to golint. | ||
severity: warning # Sets the default severity. | ||
enable-all-rules: false # Enable all available rules. | ||
confidence: 0.8 # This means that linting errors with less than 0.8 confidence will be ignored. | ||
rules: | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported | ||
- name: exported | ||
severity: warning | ||
disabled: false | ||
arguments: | ||
- "checkPrivateReceivers" | ||
- "sayRepetitiveInsteadOfStutters" | ||
interfacebloat: | ||
max: 5 # The maximum number of methods allowed for an interface. | ||
goconst: | ||
min-len: 3 # Minimal length of string constant. | ||
min-occurrences: 3 # Minimum occurrences of constant string count to trigger issue. | ||
ignore-tests: true | ||
gci: | ||
custom-order: true | ||
sections: | ||
- standard # Standard section: captures all standard packages. | ||
- default # Default section: contains all imports that could not be matched to another section type. | ||
- prefix(github.com/mrwormhole/emailer) # Custom section: groups all imports with the specified Prefix. | ||
skip-generated: false | ||
nolintlint: | ||
allow-unused: false # report any unused nolint directives | ||
require-explanation: false # don't require an explanation for nolint directives | ||
require-specific: true # require nolint directives to be specific about which linter is being skipped | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
# common mistakes | ||
- govet | ||
- staticcheck | ||
- gosec | ||
- bodyclose | ||
- ineffassign | ||
- errcheck | ||
- typecheck | ||
- durationcheck | ||
- nilerr | ||
- nilnil | ||
- nolintlint | ||
- wrapcheck | ||
- sloglint | ||
- noctx | ||
- interfacebloat | ||
|
||
# common styling | ||
- gofmt | ||
- goimports | ||
- gci | ||
- goconst | ||
- gosimple | ||
- dogsled | ||
- errname | ||
- forcetypeassert | ||
- predeclared | ||
- tenv | ||
- unconvert | ||
- unparam | ||
- unused | ||
- usestdlibvars | ||
- whitespace | ||
- stylecheck | ||
- revive | ||
|
||
issues: | ||
exclude-use-default: false | ||
|
||
run: | ||
tests: true | ||
timeout: 30s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
// Package brevo makes it easy to send emails via brevo provider. This package follows [brevo spec] strictly. | ||
// | ||
// Example usage: | ||
// | ||
// email := emailer.Email{ | ||
// From: "[email protected]", | ||
// To: []string{"[email protected]"}, | ||
// Subject: "peace", | ||
// TextContent: "peace was never an option", | ||
// } | ||
// c, err := New("api-key", &http.Client{}) | ||
// if err != nil { | ||
// //check err | ||
// } | ||
// c.Send(ctx, email) | ||
// | ||
// [brevo spec]: https://developers.brevo.com/reference/sendtransacemail | ||
package brevo | ||
|
||
import ( | ||
|
@@ -16,11 +33,13 @@ import ( | |
|
||
const endpoint = "https://api.brevo.com/v3/smtp/email" | ||
|
||
// EmailClient is brevo email client to interact with emails | ||
type EmailClient struct { | ||
key string | ||
client *http.Client | ||
} | ||
|
||
// New creates a new brevo email client with given API key and http.Client | ||
func New(key string, client *http.Client) (*EmailClient, error) { | ||
if strings.TrimSpace(key) == "" { | ||
return nil, errors.New("brevo API key is blank") | ||
|
@@ -32,10 +51,12 @@ func New(key string, client *http.Client) (*EmailClient, error) { | |
}, nil | ||
} | ||
|
||
// Detail is additional info about the person such as email and name | ||
type Detail struct { | ||
Email string `json:"email"` | ||
} | ||
|
||
// Payload is a request that brevo uses to send email | ||
type Payload struct { | ||
Sender Detail `json:"sender"` | ||
To []Detail `json:"to"` | ||
|
@@ -46,11 +67,13 @@ type Payload struct { | |
TextContent string `json:"textContent,omitempty"` | ||
} | ||
|
||
// CodeMessage is a response when brevo encounters a problem while sending email | ||
type CodeMessage struct { | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Send sends a given email | ||
func (c *EmailClient) Send(ctx context.Context, email emailer.Email) error { | ||
var p Payload | ||
p.Sender.Email = email.From | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters