本文整理汇总了Golang中github.com/SparkPost/gosparkpost.Client.Templates方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Templates方法的具体用法?Golang Client.Templates怎么用?Golang Client.Templates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/SparkPost/gosparkpost.Client
的用法示例。
在下文中一共展示了Client.Templates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTemplates
func TestTemplates(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
tlist, _, err := client.Templates()
if err != nil {
t.Error(err)
return
}
t.Error(fmt.Errorf("%s", tlist))
return
content := sp.Content{
Subject: "this is a test template",
// NB: deliberate syntax error
//Text: "text part of the test template {{a}",
Text: "text part of the test template",
From: map[string]string{
"name": "test name",
"email": "[email protected]",
},
}
template := &sp.Template{Content: content, Name: "test template"}
id, _, err := client.TemplateCreate(template)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Created Template with id=%s\n", id)
_, err = client.TemplateDelete(id)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Deleted Template with id=%s\n", id)
}
示例2: TestTemplates
func TestTemplates(t *testing.T) {
if true {
// Temporarily disable test so TravisCI reports build success instead of test failure.
// NOTE: need travis to set sparkpost base urls etc, or mock http request
return
}
cfgMap, err := test.LoadConfig()
if err != nil {
t.Error(err)
return
}
cfg, err := sp.NewConfig(cfgMap)
if err != nil {
t.Error(err)
return
}
var client sp.Client
err = client.Init(cfg)
if err != nil {
t.Error(err)
return
}
tlist, _, err := client.Templates()
if err != nil {
t.Error(err)
return
}
t.Logf("templates listed: %+v", tlist)
content := sp.Content{
Subject: "this is a test template",
// NB: deliberate syntax error
//Text: "text part of the test template {{a}",
Text: "text part of the test template",
From: map[string]string{
"name": "test name",
"email": "[email protected]",
},
}
template := &sp.Template{Content: content, Name: "test template"}
id, _, err := client.TemplateCreate(template)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Created Template with id=%s\n", id)
d := map[string]interface{}{}
res, err := client.TemplatePreview(id, &sp.PreviewOptions{d})
if err != nil {
t.Error(err)
return
}
fmt.Printf("Preview Template with id=%s and response %+v\n", id, res)
_, err = client.TemplateDelete(id)
if err != nil {
t.Error(err)
return
}
fmt.Printf("Deleted Template with id=%s\n", id)
}