mirror of https://github.com/statping/statping
unique permalink, utils.replacer test
parent
94485e3a9e
commit
6cfb9feb84
|
@ -38,7 +38,7 @@ type Service struct {
|
|||
Public null.NullBool `gorm:"default:true;column:public" json:"public" yaml:"public"`
|
||||
GroupId int `gorm:"default:0;column:group_id" json:"group_id" yaml:"group_id"`
|
||||
Headers null.NullString `gorm:"column:headers" json:"headers" scope:"user,admin" yaml:"headers"`
|
||||
Permalink null.NullString `gorm:"column:permalink" json:"permalink" yaml:"permalink"`
|
||||
Permalink null.NullString `gorm:"column:permalink;unique;" json:"permalink" yaml:"permalink"`
|
||||
Redirect null.NullBool `gorm:"default:false;column:redirect" json:"redirect" scope:"user,admin" yaml:"redirect"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" yaml:"-"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"-"`
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
func ReplaceTemplate(tmpl string, data interface{}) string {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
slackTemp, err := template.New("replacement").Parse(tmpl)
|
||||
tmp, err := template.New("replacement").Parse(tmpl)
|
||||
if err != nil {
|
||||
Log.Error(err)
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
err = slackTemp.Execute(buf, data)
|
||||
err = tmp.Execute(buf, data)
|
||||
if err != nil {
|
||||
Log.Error(err)
|
||||
return err.Error()
|
||||
|
|
|
@ -41,18 +41,16 @@ func TestCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReplaceTemplate(t *testing.T) {
|
||||
|
||||
type Object struct {
|
||||
Id int64
|
||||
String string
|
||||
Online bool
|
||||
Example string
|
||||
}
|
||||
example := &Object{
|
||||
ex := &Object{
|
||||
1, "this is an example", true, "it should work",
|
||||
}
|
||||
|
||||
result := ReplaceTemplate(`{"id": {{.Object.Id}} }`, example)
|
||||
result := ReplaceTemplate(`{"id": {{.Id}} }`, ex)
|
||||
assert.Equal(t, "{\"id\": 1 }", result)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue