Skip to content

Commit 254aeab

Browse files
committed
Update lol
1 parent dfe92c9 commit 254aeab

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

README.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
### Pre-Requisites
2-
3-
For this hack, we're going to use Reddit's API, SendGrid's API, and our Golang library for said API. You can find the relevant libraries you require below:
4-
5-
* <a href="https://github.com/sendgrid/sendgrid-go">Go SendGrid Lib</a>
6-
7-
Other than those, we will be sticking to the excellent native libs from Go.
8-
9-
10-
### Let's get started!
11-
12-
If you haven't already, head over to <a href="http://hack.sendgrid.com">hack.sendgrid.com</a>, register an account and hit me up on Twitter, @rbin, or by email [email protected] to get your account provisioned to send emails!
13-
14-
Once you've done that, use <i>Go Get</i> to install the dependencies above. I.E.
15-
16-
go get github.com/sendgrid/sendgrid-go
17-
18-
19-
Now, go ahead and create a workspace / project for your hack. Personally, I setup the namespace of <i>sg_news</i>, but you can use anything you like. (Just make sure you alter the code I provide accordingly!) So, we've installed our Dependencies, created a Project namespace and directory, so let's dive in a write some code!
1+
Go ahead and create a workspace / project for your hack. Personally, I setup the namespace of <i>sg_news</i>, but you can use anything you like. (Just make sure you alter the code I provide accordingly!) So, we've installed our Dependencies, created a Project namespace and directory, so let's dive in a write some code!
202

213
Inside your News Reader namespace, create a file called ***main.go*** Open it up in your choice of IDE and input the following:
224

main.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/sendgrid/sendgrid-go"
99
"log"
1010
"net/http"
11+
"os"
1112
)
1213

1314
type Item struct {
@@ -48,7 +49,6 @@ func Get(reddit string) ([]Item, error) {
4849
items[i] = child.Data
4950
}
5051
return items, nil
51-
5252
}
5353

5454
func (i Item) String() string {
@@ -67,14 +67,13 @@ func (i Item) String() string {
6767
}
6868

6969
func Email() string {
70-
7170
var buffer bytes.Buffer
7271

7372
items, err := Get("golang")
7473
if err != nil {
7574
log.Fatal(err)
7675
}
77-
// Need to build strings from items
76+
7877
for _, item := range items {
7978
buffer.WriteString(item.String())
8079
}
@@ -84,21 +83,20 @@ func Email() string {
8483

8584
func main() {
8685

87-
sg := sendgrid.NewSendGridClient("sendgrid_user", "sendgrid_key")
88-
message := sendgrid.NewMail()
86+
sg := sendgrid.NewSendGridClient(os.Getenv("SENDGRID_USERNAME"), os.Getenv("SENDGRID_PASSWORD"))
87+
mail := sendgrid.NewMail()
8988

90-
message.AddTo("myemail@me.com")
91-
message.AddToName("Robin Johnson")
92-
message.AddSubject("Your Daily Golang Breakfast News!")
93-
message.AddFrom("[email protected]")
89+
mail.AddTo("rbin@sendgrid.com")
90+
mail.AddToName("Robin Johnson")
91+
mail.SetSubject("Your Daily Golang News")
92+
mail.SetFrom("[email protected]")
9493

95-
message.AddHTML(Email())
94+
mail.SetHTML(Email())
9695

97-
if rep := sg.Send(message); rep == nil {
98-
fmt.Println("Email sent!")
96+
if rep := sg.Send(mail); rep == nil {
97+
fmt.Println("email Sent!")
9998
fmt.Println("Closing...")
10099
} else {
101100
fmt.Println(rep)
102101
}
103-
104102
}

sg_news

1.03 MB
Binary file not shown.

0 commit comments

Comments
 (0)