Giter Club home page Giter Club logo

grizzly's Issues

add groupBy method

For each type you need to generate the groupBy method.

example:

grizzly.json

{
  "collections": [
    {
      "name": "user",
      "types": {
        "id": "int",
        "name": "string"
      },
      "methods": ["group"]
    }  
  ]
}

collections/user.go

type SearchCallbackUser func(item *User) bool

type User struct {
    Id   int
    Name string
}

type UserCollection struct {
    Items []*Users
}

func NewUserCollection(items []*User) *UserCollection

func GroupByInt(callback func(model *User) int) map[int]*UserCollection
func GroupByString(callback func(model *User) string) map[string]*UserCollection

go get failed

D:\Temp
λ go get github.com/matroskin13/grizzly
# github.com/matroskin13/grizzly/cmd
D:\gopath\src\github.com\matroskin13\grizzly\cmd\cmd.go:17:15: cannot use []cli.Command literal (type []cli.Command) as type []*cli.Command in assignment

go generate

//go:generate grizzly main.go

//grizzly:generate
type User struct {
    Id int
}

failed on Windows

λ grizzly generate main.go
open D\src\github.com\matroskin13\grizzly\collection\collection.go: The system cannot find the path specified.
λ echo %GOPATH%
D:\gopath

Because GOPATH is splitted with ':' which is wrong on Windows:

func GetCollectionDir(isDev bool) (string, error) {
	goPaths := strings.Split(os.Getenv("GOPATH"), ":")

add Sort method

At the moment we have the SortBy* methods, but we need to add a Sort method.

example:

grizzly.json

{
  "collections": [
    {
      "name": "user",
      "types": {
        "id": "int",
        "name": "string"
      },
      "methods": ["sort"]
    }  
  ]
}

collections/user.go

type SearchCallbackUser func(item *User) bool

type User struct {
    Id   int
    Name string
}

type UserCollection struct {
    Items []*Users
}

func NewUserCollection(items []*User) *UserCollection

func GroupByInt(callback func(model *User) int) map[int]*UserCollection
func GroupByString(callback func(model *User) string) map[string]*UserCollection

func (c *UserCollection) SortById(mode string) *UserCollection
func (c *UserCollection) SortByName(mode string) *UserCollection

func (c *UserCollection) Sort (callback func(item *User) int) *UserCollection

Sort callback return int(-1, 0, 1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.