Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sendgrid/sendgrid-go
Browse files Browse the repository at this point in the history
  • Loading branch information
dmowcomber committed Feb 6, 2018
2 parents 775cc0e + 0337b42 commit 3e597c3
Show file tree
Hide file tree
Showing 48 changed files with 981 additions and 816 deletions.
Empty file added .env_sample
Empty file.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
@@ -0,0 +1,24 @@
<!--
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below.


Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->
# Fixes #

### Checklist
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
- [ ] I have read the [Contribution Guide] and my PR follows them.
- [ ] I updated my branch with the master branch.
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added necessary documentation about the functionality in the appropriate .md file
- [ ] I have added in line documentation to the code I modified

### Short description of what this PR does:
-
-

If you have questions, please send an email to [Sendgrid](mailto:dx@sendgrid.com), or file a Github Issue in this repository.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
temp.go
*.swp
.env
15 changes: 15 additions & 0 deletions .travis.yml
Expand Up @@ -6,7 +6,22 @@ go:
- '1.9'
- 'tip'
before_script:
- go get -u github.com/alecthomas/gometalinter
- gometalinter --install
- $HOME/gopath/src/github.com/sendgrid/sendgrid-go/prism.sh

before_install:
- go get -t -v ./...

script:
- ./go.test.sh
- gometalinter --disable-all --enable=errcheck --enable=vet --enable=vetshadow --enable=megacheck --exclude=S1024 # TODO: remove exclude when we stop support Go 1.7 and lower
- gometalinter --disable-all --enable=errcheck --enable=vet --enable=vetshadow --enable=megacheck helpers/...
- go test -cover -v -race ./...

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
hipchat:
rooms:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2016 SendGrid, Inc.
Copyright (c) 2013-2018 SendGrid, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 22 additions & 2 deletions README.md
@@ -1,4 +1,4 @@
[![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

[![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-go.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-go)
[![Email Notifications Badge](https://dx.sendgrid.com/badge/go)](https://dx.sendgrid.com/newsletter/go)
Expand Down Expand Up @@ -60,6 +60,24 @@ source ./sendgrid.env

- [rest](https://github.com/sendgrid/rest)

## Setup Environment Variables

### Initial Setup

```bash
cp .env_sample .env
```

### Environment Variable

Update the development environment with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys), for example:

```bash
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
```

<a name="quick-start"></a>
# Quick Start

Expand Down Expand Up @@ -201,6 +219,8 @@ Please see [our helper](https://github.com/sendgrid/sendgrid-go/tree/master/help
<a name="announcements"></a>
# Announcements

Join an experienced and passionate team that focuses on making an impact. Opportunities abound to grow the product - and grow your career! Check out our [Software Engineer- Delivery role](http://grnh.se/mg6dr31)

Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-go/issues/81). Your support is appreciated!

All updates to this library are documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-go/blob/master/CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-go/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/go) for releases and breaking changes.
Expand Down Expand Up @@ -235,4 +255,4 @@ sendgrid-go is guided and supported by the SendGrid [Developer Experience Team](
sendgrid-go is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-go are trademarks of SendGrid, Inc.

# License
[The MIT License (MIT)](LICENSE.txt)
[The MIT License (MIT)](LICENSE.txt)
6 changes: 3 additions & 3 deletions USAGE.md
Expand Up @@ -5857,7 +5857,7 @@ if err != nil {

A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.

Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools.

For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)

Expand Down Expand Up @@ -5887,7 +5887,7 @@ if err != nil {

A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.

Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools.

For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)

Expand Down Expand Up @@ -5991,7 +5991,7 @@ if err != nil {

A domain whitelabel allows you to remove the via or sent on behalf of message that your recipients see when they read your emails. Whitelabeling a domain allows you to replace sendgrid.net with your personal sending domain. You will be required to create a subdomain so that SendGrid can generate the DNS records which you must give to your host provider. If you choose to use Automated Security, SendGrid will provide you with 3 CNAME records. If you turn Automated Security off, you will be given 2 TXT records and 1 MX record.

Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The the parent may then associate the whitelabel via the subuser management tools.
Domain whitelabels can be associated with (i.e. assigned to) subusers from a parent account. This functionality allows subusers to send mail using their parent's whitelabels. To associate a whitelabel with a subuser, the parent account must first create the whitelabel and validate it. The parent may then associate the whitelabel via the subuser management tools.

For more information on whitelabeling, please see our [User Guide](https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html)

Expand Down
23 changes: 23 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,23 @@
FROM golang:1.9.1

ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"
WORKDIR /root

# Install Prism
ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh
RUN sh ./install.sh && \
rm ./install.sh

# Get sendgrid-go
RUN mkdir -p /go/src/github.com/sendgrid && \
cd /go/src/github.com/sendgrid && \
git clone https://www.github.com/sendgrid/sendgrid-go && \
cd sendgrid-go && \
go get

COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh

COPY get-version.go get-version.go

ENTRYPOINT ["./entrypoint.sh"]
61 changes: 61 additions & 0 deletions docker/README.md
@@ -0,0 +1,61 @@
You can use Docker to easily try out or test sendgrid-go.

# Quickstart
1. Install Docker and docker-compose in your machine
2. Change into the docker directory, `cd docker`
3. run `docker-compose build`
4. run `docker-compose up`
5. Put the script you want to test in `./src`
6. Run `docker-compose run mock-server`, this will open a terminal on the container
7. Run your code with `go run your-code.go` once inside container

# Examples
You can use this as an example to show how this works.

1. Copy and save in `./src/test.go`, e.g. `test.go`.
```
package main
import (
"os"
"fmt"
"github.com/sendgrid/sendgrid-go"
"log"
)
func main() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "http://localhost:4010"
request := sendgrid.GetRequest(apiKey, "/v3/api_keys", host)
request.Method = "GET"
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
```
2. Run `docker-compose run mock-server`.
3. In container, run `go run test.go`

More sample codes on [Docker Examples](/docker/examples).


# Options
## Specifying specific versions
To use different version of sendgrid-go, mount them with `-v <host_dir>:<container_dir>` options. When you put either repository under `/mnt`, the container will automatically detect it and make the proper symlinks. You can edit these files from the host machine while the container is running.

For instance, to use sendgrid-go v3.0.6:
```
$ git clone https://github.com/sendgrid/sendgrid-go --branch v3.0.6
$ realpath sendgrid-go
/path/to/sendgrid-go
$ docker run -it -v /path/to/sendgrid-go:/mnt/sendgrid-go \
> -v /path/to/your-code:/data \
> dhoeric/sendgrid-go
$ (in container) go run your-code.go
```
10 changes: 10 additions & 0 deletions docker/docker-compose.yml
@@ -0,0 +1,10 @@
version: '3'

services:
mock-server:
build: .
environment:
SENDGRID_API_KEY: JUST_A_TEST_KEY
volumes:
- ./src:/data

33 changes: 33 additions & 0 deletions docker/entrypoint.sh
@@ -0,0 +1,33 @@
#!/bin/bash
clear

# check for + link mounted libraries:
if [ -d /mnt/sendgrid-go ]; then
rm -rf /go/src/github.com/sendgrid/sendgrid-go
`cd /go/src/github.com/sendgrid/ && ln -s /mnt/sendgrid-go && cd sendgrid-go && go get -v -d`
echo "Linked mounted sendgrid-go's code to /go/src/github.com/sendgrid/sendgrid-go"
fi

SENDGRID_GO_VERSION=$(go run get-version.go)
echo "Welcome to sendgrid-go docker v${SENDGRID_GO_VERSION}."
echo

if [ "$1" != "--no-mock" ]
then
echo "Starting Prism in mock mode. Calls made to Prism will not actually send emails."
echo "Disable this by running this container with --no-mock."
prism run --mock --spec $OAI_SPEC_URL 2> /dev/null &
else
echo "Starting Prism in live (--no-mock) mode. Calls made to Prism will send emails."
prism run --spec $OAI_SPEC_URL 2> /dev/null &
fi
echo "To use Prism, make API calls to localhost:4010."
echo "To stop Prism, run \"kill $!\" from the shell."

echo
echo "To test with sendgrid-go."
echo "Put your file in ./src, which mounted to /data in container, and run with \"go run [file].go\"."
echo

cd /data
bash
28 changes: 28 additions & 0 deletions docker/examples/apikey/apikey.go
@@ -0,0 +1,28 @@
package main

import (
"os"
"fmt"
"github.com/sendgrid/sendgrid-go"
"log"
)

func GetAPIKey() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "http://localhost:4010"
request := sendgrid.GetRequest(apiKey, "/v3/api_keys", host)
request.Method = "GET"

response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}

func main() {
// add your function calls here
}
49 changes: 49 additions & 0 deletions docker/examples/mail/mail.go
@@ -0,0 +1,49 @@
package main

import (
"os"
"fmt"
"github.com/sendgrid/sendgrid-go"
"log"
)

func SendSampleHelloMail() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "http://localhost:4010"
request := sendgrid.GetRequest(apiKey, "/v3/mail/send", host)
request.Method = "POST"
request.Body = []byte(` {
"personalizations": [
{
"to": [
{
"email": "test@example.com"
}
],
"subject": "Sending with SendGrid is Fun"
}
],
"from": {
"email": "test@example.com"
},
"subject": "Hello SendGrid",
"content": [
{
"type": "text/plain",
"value": "and easy to do anywhere, even with Go"
}
]
}`)
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}

func main() {
// add your function calls here
}
38 changes: 38 additions & 0 deletions docker/examples/stats/stats.go
@@ -0,0 +1,38 @@
package main

import (
"os"
"fmt"
"github.com/sendgrid/sendgrid-go"
"log"
)

///////////////////////////////////////////////////
// Retrieve global email statistics
// GET /stats

func Retrieveglobalemailstatistics() {
apiKey := os.Getenv("SENDGRID_API_KEY")
host := "http://localhost:4010"
request := sendgrid.GetRequest(apiKey, "/v3/stats", host)
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["aggregated_by"] = "day"
queryParams["limit"] = "1"
queryParams["start_date"] = "2016-01-01"
queryParams["end_date"] = "2016-04-01"
queryParams["offset"] = "1"
request.QueryParams = queryParams
response, err := sendgrid.API(request)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}

func main() {
// add your function calls here
}
10 changes: 10 additions & 0 deletions docker/get-version.go
@@ -0,0 +1,10 @@
package main

import (
"fmt"
"github.com/sendgrid/sendgrid-go"
)

func main() {
fmt.Println(sendgrid.Version)
}
Empty file added docker/src/.gitkeep
Empty file.

0 comments on commit 3e597c3

Please sign in to comment.