本文整理汇总了Golang中github.com/corestoreio/csfw/util.StringSlice类的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice类的具体用法?Golang StringSlice怎么用?Golang StringSlice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringSlice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStringSliceReduce
func TestStringSliceReduce(t *testing.T) {
l := util.StringSlice{"Maybe", "GoLang", "should"}
assert.EqualValues(t, []string{"GoLang"}, l.Reduce(func(s string) bool {
return s == "GoLang"
}).ToString())
assert.Len(t, l, 1)
}
示例2: BenchmarkStringSliceUnique
// BenchmarkStringSliceUnique 2000000 612 ns/op 160 B/op 2 allocs/op <- Go 1.4.2
// BenchmarkStringSliceUnique 10000000 179 ns/op 128 B/op 1 allocs/op <- Go 1.5
func BenchmarkStringSliceUnique(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
l := util.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
l.Unique()
benchStringSliceUnique = l
}
}
示例3: TestStringSliceAny
func TestStringSliceAny(t *testing.T) {
l := util.StringSlice{"c", "a", "z", "b"}
assert.True(t, l.Any(func(s string) bool {
return s == "z"
}))
assert.False(t, l.Any(func(s string) bool {
return s == "zx"
}))
}
示例4: defaultIsCountryAllowed
func defaultIsCountryAllowed(_ *store.Store, c *IPCountry, allowedCountries util.StringSlice, r *http.Request) bool {
if false == allowedCountries.Include(c.Country.Country.IsoCode) {
if PkgLog.IsInfo() {
PkgLog.Info("geoip.checkAllow", "IPCountry", c, "allowedCountries", allowedCountries, "request", r)
}
return false
}
return true
}
示例5: Human
// Human readable representation of the permissions
func (bits Perm) Human() util.StringSlice {
var ret util.StringSlice
for i := uint(0); i < 64; i++ {
bit := ((bits & (1 << i)) != 0)
if bit {
ret.Append(Scope(i).String())
}
}
return ret
}
示例6: TestStringSliceFilter
func TestStringSliceFilter(t *testing.T) {
l := util.StringSlice{"All", "Go", "Code", "is"}
rl := l.Filter(func(s string) bool {
return s == "Go"
}).ToString()
assert.EqualValues(t, []string{"Go"}, rl)
assert.Len(t, l, 4)
l.Append("incredible", "easy", ",", "sometimes")
assert.Len(t, l, 8)
assert.EqualValues(t, []string{"Go"}, rl)
}
示例7: Codes
// Codes returns a StringSlice with all store codes
func (ss StoreSlice) Codes() util.StringSlice {
if len(ss) == 0 {
return nil
}
var c util.StringSlice
for _, st := range ss {
if st != nil {
c.Append(st.Data.Code.String)
}
}
return c
}
示例8: Codes
// Codes returns a StringSlice with all website codes
func (ws WebsiteSlice) Codes() util.StringSlice {
if len(ws) == 0 {
return nil
}
var c util.StringSlice
for _, w := range ws {
if w != nil {
c.Append(w.Data.Code.String)
}
}
return c
}
示例9: BenchmarkStringSliceReduceContains
// BenchmarkStringSliceReduceContains 1000000 1841 ns/op 96 B/op 2 allocs/op <- Go 1.4.2
// BenchmarkStringSliceReduceContains-4 1000000 1250 ns/op 64 B/op 1 allocs/op <- Go 1.5
func BenchmarkStringSliceReduceContains(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
l := util.StringSlice{
"IFNULL(`scope_table`.`is_visible`, `additional_table`.`is_visible`) AS `is_visible`",
"IFNULL(`scope_table`.`is_required`, `main_table`.`is_required`) AS `is_required`",
"IFNULL(`scope_table`.`default_value`, `main_table`.`default_value`) AS `default_value`",
"IFNULL(`scope_table`.`multiline_count`, `additional_table`.`multiline_count`) AS `multiline_count`",
}
l.ReduceContains(benchStringSliceReduceContainsData...)
benchStringSliceReduceContains = l
}
}
示例10: getImportPaths
func getImportPaths() []string {
var paths util.StringSlice
var getPath = func(s string) string {
ps, err := codegen.ExtractImportPath(s)
codegen.LogFatal(err)
return ps
}
for _, et := range codegen.ConfigEntityType {
paths.Append(
getPath(et.EntityModel),
getPath(et.AttributeModel),
getPath(et.EntityTable),
getPath(et.IncrementModel),
getPath(et.AdditionalAttributeTable),
getPath(et.EntityAttributeCollection),
)
}
return paths.Unique().ToString()
}
示例11: TestStringSliceAll
func TestStringSliceAll(t *testing.T) {
l := util.StringSlice{"c", "a", "z", "b"}
assert.True(t, l.All(func(s string) bool {
return len(s) == 1
}))
l.Append("xx")
assert.False(t, l.All(func(s string) bool {
return len(s) == 1
}))
}
示例12: TestStringSliceSplitStringer8
func TestStringSliceSplitStringer8(t *testing.T) {
tests := []struct {
haveName string
haveIndex []uint8
want util.StringSlice
}{
{
"ScopeAbsentScopeDefaultScopeWebsiteScopeGroupScopeStore",
[]uint8{0, 11, 23, 35, 45, 55},
util.StringSlice{"ScopeAbsent", "ScopeDefault", "ScopeWebsite", "ScopeGroup", "ScopeStore"},
},
{
"TypeCustomTypeHiddenTypeObscureTypeMultiselectTypeSelectTypeTextTypeTime",
[]uint8{10, 20, 31, 46, 56, 64, 72},
util.StringSlice{"TypeHidden", "TypeObscure", "TypeMultiselect", "TypeSelect", "TypeText", "TypeTime"},
},
}
for _, test := range tests {
var a util.StringSlice
have := a.SplitStringer8(test.haveName, test.haveIndex...)
assert.Exactly(t, test.want, have)
}
}
示例13: TestStringSliceSort
func TestStringSliceSort(t *testing.T) {
l := util.StringSlice{"c", "a", "z", "b"}
assert.Equal(t, "a,b,c,z", l.Sort().Join(","))
}
示例14: TestStringSliceDelete
func TestStringSliceDelete(t *testing.T) {
l := util.StringSlice{"Maybe", "GoLang", "should"}
assert.NoError(t, l.Delete(1))
assert.Equal(t, []string{"Maybe", "should"}, l.ToString())
assert.NoError(t, l.Delete(1))
assert.Equal(t, []string{"Maybe"}, l.ToString())
assert.EqualError(t, l.Delete(1), util.ErrOutOfRange.Error())
}
示例15: TestStringSliceUnique
func TestStringSliceUnique(t *testing.T) {
l := util.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
assert.Equal(t, []string{"Maybe", "GoLang", "or", "RostLang"}, l.Unique().ToString())
}