Skip to content

go-utils/count

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

Easy counter

Installation

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

Usage

import (
	"fmt"

	"github.com/go-utils/count"
)

func main() {
	if cnt, err := count.Do("something", "a"); err == nil {
		fmt.Println(cnt) // cnt = 0
	}

	if cnt, err := count.Do([]string{"1", "2", "3"}, "1"); err == nil {
		fmt.Println(cnt) // cnt = 1
	}

	if cnt, err := count.Do([]int{1, 2, 3}, 1); err == nil {
		fmt.Println(cnt) // cnt = 1
	}

	if cnt, err := count.Do("12321", "1"); err == nil {
		fmt.Println(cnt) // cnt = 2
	}

	if cnt, err := count.Do([]interface{}{1, "2", 3, "4", nil, nil}, nil); err == nil {
		fmt.Println(cnt) // cnt = 2
	}
}

Check Go Playground

Support

string, slice, array

License

MIT