ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - gookit/filter: ⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤,净化,转换。
⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤,净化,转换。 - gookit/filter
Visit Site

GitHub - gookit/filter: ⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤,净化,转换。

GitHub - gookit/filter: ⏳ Provide filtering, sanitizing, and conversion of Golang data. 提供对Golang数据的过滤,净化,转换。

Filter

GitHub tag (latest SemVer) Actions Status Coverage Status Go Report Card Go Reference

filter - provide filtering, sanitizing, and conversion of Golang data.

中文说明请查看 README.zh-CN

GoDoc

NOTE: To filter and validate Map, Struct data. Please use gookit/validate

Install

go get github.com/gookit/filter

Func Usage

Quick usage:

str := filter.MustString(23) // "23"

intVal, err := filter.Int("20") // int(20)
strings := filter.Str2Slice("a,b, c", ",") // []string{"a", "b", "c"}

Filtration

Filtering data:

data := map[string]any{
    "name":     " inhere ",
    "age":      "50",
    "money":    "50.34",
    // 
    "remember": "yes",
    //
    "sub1": []string{"1", "2"},
    "tags": "go;lib",
    "str1": " word ",
    "ids":  []int{1, 2, 2, 1},
}
f := filter.New(data)
f.AddRule("money", "float")
f.AddRule("remember", "bool")
f.AddRule("sub1", "strings2ints")
f.AddRule("tags", "str2arr:;")
f.AddRule("ids", "unique")
f.AddRule("str1", "ltrim|rtrim")
f.AddRule("not-exist", "unique")
// add multi
f.AddRules(map[string]string{
    "age": "trim|int",
    "name": "trim|ucFirst",
})

// apply all added rules for data.
f.Filtering() 

// get filtered data
newData := f.CleanData()
fmt.Printf("%#v\n", newData)
// f.BindStruct(&user)

Output:

map[string]interface {}{
    "remember":true, 
    "sub1":[]int{1, 2}, 
    "tags":[]string{"go", "lib"}, 
    "ids":[]int{2, 1}, 
    "str1":"word", 
    "name":"INHERE", 
    "age":50, 
    "money":50.34
}

Filters & Converters

  • ToBool/Bool(s string) (bool, error)
  • ToFloat/Float(v interface{}) (float64, error)
  • ToInt/Int(v interface{}) (int, error)
  • ToUint/Uint(v interface{}) (uint64, error)
  • ToInt64/Int64(v interface{}) (int64, error)
  • ToString/String(v interface{}) (string, error)
  • MustBool(s string) bool
  • MustFloat(s string) float64
  • MustInt(s string) int
  • MustInt64(s string) int64
  • MustUint(s string) uint64
  • MustString(v interface{}) string
  • Trim(s string, cutSet ...string) string
  • TrimLeft(s string, cutSet ...string) string
  • TrimRight(s string, cutSet ...string) string
  • TrimStrings(ss []string, cutSet ...string) (ns []string)
  • Substr(s string, pos, length int) string
  • Lower/Lowercase(s string) string
  • Upper/Uppercase(s string) string
  • LowerFirst(s string) string
  • UpperFirst(s string) string
  • UpperWord(s string) string
  • Camel/CamelCase(s string, sep ...string) string
  • Snake/SnakeCase(s string, sep ...string) string
  • Email(s string) string
  • URLDecode(s string) string
  • URLEncode(s string) string
  • EscapeJS(s string) string
  • EscapeHTML(s string) string
  • Unique(val interface{}) interface{} Will remove duplicate values, use for []int []int64 []string
  • StrToSlice(s string, sep ...string) []string
  • StrToInts(s string, sep ...string) (ints []int, err error)
  • StrToTime(s string, layouts ...string) (t time.Time, err error)
  • StringsToInts(ss []string) (ints []int, err error)

License

MIT

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory