示例#1
0
	"os"
	"safely"
	"util"
)

type Any interface{}

const (
	MaxAttachmentSize = 10485760
	Subject           = "convert"
	Endpoint          = "https://api.postmarkapp.com/email"
	AuthHeader        = "X-Postmark-Server-Token"
	FriendlyMessage   = "Sorry, email sending failed."
)

var from = env.Get("FROM")
var token = env.Get("POSTMARK_TOKEN")
var logger = log.New(os.Stdout, "[postmark] ", log.LstdFlags|log.Lmicroseconds)
var client http.Client

func readFile(path string) []byte {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		logger.Panicf("Failed reading file: %s", err.Error())
	}
	return data
}

func setupHeaders(req *http.Request) {
	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")
示例#2
0
	"net/url"
	"os"
	"regexp"
	"safely"
	"sync"
	"util"
)

const (
	Readability     = "https://readability.com/api/content/v1/parser"
	FriendlyMessage = "Sorry, extraction failed."
)

type JSON map[string]interface{}

var token = env.Get("READABILITY_TOKEN")
var notParsed = regexp.MustCompile("(?i:Article Could not be Parsed)")
var logger = log.New(os.Stdout, "[extractor] ", log.LstdFlags|log.Lmicroseconds)

func buildReadabilityUrl(u string) string {
	return fmt.Sprintf("%s?url=%s&token=%s", Readability, url.QueryEscape(u), url.QueryEscape(token))
}

func downloadAndParse(j *job.Job) JSON {
	resp, err := http.Get(buildReadabilityUrl(j.Url.String()))
	if err != nil {
		logger.Panicf("Readability Error: %s", err.Error())
	}
	defer resp.Body.Close()
	return util.ParseJSON(resp.Body, func(err error) {
		logger.Panicf("JSON Parsing Error: %s", err.Error())