2020-08-02 15:59:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2021-01-31 20:36:04 -05:00
|
|
|
"github.com/vartanbeno/go-reddit/v2/reddit"
|
2020-08-02 15:59:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var ctx = context.Background()
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() (err error) {
|
2020-08-29 02:48:22 -04:00
|
|
|
client, err := reddit.NewReadonlyClient()
|
2020-08-02 15:59:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
client.OnRequestCompleted(logResponse)
|
|
|
|
|
2020-08-05 13:25:09 -04:00
|
|
|
client.Subreddit.Search(ctx, "programming", nil)
|
2020-08-02 15:59:25 -04:00
|
|
|
client.Subreddit.SearchNames(ctx, "monitor")
|
2020-08-05 13:25:09 -04:00
|
|
|
client.Subreddit.SearchPosts(ctx, "react", "webdev", nil)
|
2020-08-29 02:48:22 -04:00
|
|
|
client.Subreddit.HotPosts(ctx, "golang", &reddit.ListOptions{Limit: 5})
|
2020-08-02 15:59:25 -04:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func logResponse(req *http.Request, res *http.Response) {
|
|
|
|
fmt.Printf("%s %s %s\n", req.Method, req.URL, res.Status)
|
|
|
|
}
|