Skip to content

CyrivlClth/go-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Tools

Build Status

中文文档

The awesome tool kit for Golang.

Waiting for generic type of golang.

Contents

Overview

  • ID generator

    • snowflake

    • serial no

  • Container tools

    • Slice

      • type []int method: Distinct, Merge, Sort, Filter

      • type interface

    • Map tools

    • JSON Object

  • Bean

    • Copy

Getting Started

go get -u github.com/CyrivlClth/go-tools

If you just want one of them, you can do like this:

go get -u github.com/CyrivlClth/go-tools/jsonobj

Examples

ID generator

ID generator contains:

  • snowflake

  • simple serial no

Snowflake ID Generator

...
func main() {
    generator, _ := snowflake.New(0, 0)
    id, _ := generator.NextID()
    fmt.Println(id)
}
...

more detail for package github.com/CyrivlClth/go-tools/idgen/snowflake/cmd

Serial Number Generator

serialnum.New(9).GetID()

Slice Tools

Integer Slice

package main

import (
 "github.com/CyrivlClth/go-tools/container/set"
 "github.com/CyrivlClth/go-tools/container/slice"
)

func main(){
    slice.Integer([]int{3, 2, 5, 2}).Distinct()
    // [3,2,5]
    slice.Integer([]int{3, 2, 5, 2}).Contains(2)
    // true
    slice.Integer([]int{3, 2, 5, 2}).Sort()
    // [2,2,3,5]
    slice.Integer([]int{3, 2, 5, 2}).Filter(func(x int) bool {return x%2==0})
    // [2,2]
    int1 := slice.Integer([]int{3, 2, 5, 2})
    int2 := slice.Integer([]int{4, 2, 5, 2})
    set.NewIntegerSet(int1).Merge(int2)
    // [3,2,5,4]
}

Contributing

You can just create a new issues and commit your code

License

©CyrivlClth, 2019-time.Now()

Released under the MIT License