2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2020-06-10 19:47:25 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with gm file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gset_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/container/gset"
|
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleStrSet_Contains() {
|
|
|
|
var set gset.StrSet
|
|
|
|
set.Add("a")
|
|
|
|
fmt.Println(set.Contains("a"))
|
|
|
|
fmt.Println(set.Contains("A"))
|
|
|
|
fmt.Println(set.ContainsI("A"))
|
|
|
|
|
|
|
|
// Output:
|
|
|
|
// true
|
|
|
|
// false
|
|
|
|
// true
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleStrSet_Walk() {
|
|
|
|
var (
|
|
|
|
set gset.StrSet
|
|
|
|
names = g.SliceStr{"user", "user_detail"}
|
|
|
|
prefix = "gf_"
|
|
|
|
)
|
|
|
|
set.Add(names...)
|
|
|
|
// Add prefix for given table names.
|
|
|
|
set.Walk(func(item string) string {
|
|
|
|
return prefix + item
|
|
|
|
})
|
|
|
|
fmt.Println(set.Slice())
|
|
|
|
|
|
|
|
// May Output:
|
|
|
|
// [gf_user gf_user_detail]
|
|
|
|
}
|