Skip to content

Repository files navigation

What is this?

If you want to know if "Hello" is included in "Hello, World!", Use string.Contains("Hello, World!","Hello").
If you want to know whether "1" is included in []string{"1", "2", "3"}, you have to implement it yourself.
At that time, I made something that was put together and can be used even a little.

Installation

go get -u github.com/go-utils/cont

Usage

import (
"fmt""time""github.com/go-utils/cont"
)
funcmain() {
ifcont.Contains([]string{"1", "2", "3"}, "1") {
fmt.Println("ex1: OK!")
}
ifcont.Contains([]int{1, 2, 3}, 1) {
fmt.Println("ex2: OK!")
}
ifcont.Contains("123", "1") {
fmt.Println("ex3: OK!")
}
now:=time.Now()
mp:=map[string]interface{}{"a": "1", "b": 2, "c": "3", "d": now}
ifcont.Contains(mp, now) {
fmt.Println("ex4: OK!")
}
ifcont.Contains(mp, 2) {
fmt.Println("ex5: OK!")
}
ifcont.Contains(mp, "c") {
fmt.Println("ex6: OK!")
}
}

Result

ex1: OK!
ex2: OK!
ex3: OK!
ex4: OK!
ex5: OK!
ex6: OK!

Check Go Playground

Support

string, slice, array, map

License

MIT

About

Easy contains

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages