Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sendgrid/sendgrid-go
- Loading branch information
Showing
48 changed files
with
981 additions
and
816 deletions.
There are no files selected for viewing
Empty file.
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,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. |
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,4 @@ | ||
.DS_Store | ||
temp.go | ||
*.swp | ||
.env |
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
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,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"] |
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,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 | ||
``` |
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,10 @@ | ||
version: '3' | ||
|
||
services: | ||
mock-server: | ||
build: . | ||
environment: | ||
SENDGRID_API_KEY: JUST_A_TEST_KEY | ||
volumes: | ||
- ./src:/data | ||
|
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,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 |
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,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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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,10 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/sendgrid/sendgrid-go" | ||
) | ||
|
||
func main() { | ||
fmt.Println(sendgrid.Version) | ||
} |
Empty file.
Oops, something went wrong.