本文整理匯總了Golang中github.com/corestoreio/csfw/store.TableWebsiteSlice.FindByCode方法的典型用法代碼示例。如果您正苦於以下問題:Golang TableWebsiteSlice.FindByCode方法的具體用法?Golang TableWebsiteSlice.FindByCode怎麽用?Golang TableWebsiteSlice.FindByCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/corestoreio/csfw/store.TableWebsiteSlice
的用法示例。
在下文中一共展示了TableWebsiteSlice.FindByCode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestTableWebsiteSlice
func TestTableWebsiteSlice(t *testing.T) {
websites := store.TableWebsiteSlice{
&store.TableWebsite{WebsiteID: 0, Code: dbr.NewNullString("admin"), Name: dbr.NewNullString("Admin"), SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NewNullBool(false)},
&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
nil,
&store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)},
}
assert.True(t, websites.Len() == 4)
w1, err := websites.FindByWebsiteID(999)
assert.Nil(t, w1)
assert.EqualError(t, store.ErrIDNotFoundTableWebsiteSlice, err.Error())
w2, err := websites.FindByWebsiteID(2)
assert.NotNil(t, w2)
assert.NoError(t, err)
assert.Equal(t, int64(2), w2.WebsiteID)
w3, err := websites.FindByCode("euro")
assert.NotNil(t, w3)
assert.NoError(t, err)
assert.Equal(t, "euro", w3.Code.String)
w4, err := websites.FindByCode("corestore")
assert.Nil(t, w4)
assert.EqualError(t, store.ErrIDNotFoundTableWebsiteSlice, err.Error())
wf1 := websites.Filter(func(w *store.TableWebsite) bool {
return w != nil && w.WebsiteID == 1
})
assert.EqualValues(t, "Europe", wf1[0].Name.String)
}
示例2: TestTableWebsiteSlice
func TestTableWebsiteSlice(t *testing.T) {
websites := store.TableWebsiteSlice{
&store.TableWebsite{WebsiteID: 0, Code: dbr.NullString{NullString: sql.NullString{String: "admin", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Admin", Valid: true}}, SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: true}}},
&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}},
nil,
&store.TableWebsite{WebsiteID: 2, Code: dbr.NullString{NullString: sql.NullString{String: "oz", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "OZ", Valid: true}}, SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: true}}},
}
assert.True(t, websites.Len() == 4)
w1, err := websites.FindByID(999)
assert.Nil(t, w1)
assert.EqualError(t, store.ErrWebsiteNotFound, err.Error())
w2, err := websites.FindByID(2)
assert.NotNil(t, w2)
assert.NoError(t, err)
assert.Equal(t, int64(2), w2.WebsiteID)
w3, err := websites.FindByCode("euro")
assert.NotNil(t, w3)
assert.NoError(t, err)
assert.Equal(t, "euro", w3.Code.String)
w4, err := websites.FindByCode("corestore")
assert.Nil(t, w4)
assert.EqualError(t, store.ErrWebsiteNotFound, err.Error())
wf1 := websites.Filter(func(w *store.TableWebsite) bool {
return w.WebsiteID == 1
})
assert.EqualValues(t, "Europe", wf1[0].Name.String)
}