matroskin13 / grizzly Goto Github PK
View Code? Open in Web Editor NEWCollections generator for Golang
License: MIT License
Collections generator for Golang
License: MIT License
Negative indexes are not supported in go array. You have to check passed index on negative value
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
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)
λ 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"), ":")
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 grizzly main.go
//grizzly:generate
type User struct {
Id int
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.