add container set method

This commit is contained in:
Jay 2019-01-24 11:44:34 +08:00
parent b2a6f95229
commit 9aadc7c1d0
4 changed files with 38 additions and 2 deletions

1
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
github.com/stretchr/testify v1.2.2 // indirect github.com/stretchr/testify v1.2.2 // indirect
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 // indirect
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 // indirect golang.org/x/net v0.0.0-20181220203305-927f97764cc3 // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 // indirect golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 // indirect

2
go.sum
View File

@ -32,6 +32,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 h1:EICbibRW4JNKMcY+LsWmuwob+CRS1BmdRdjphAm9mH4= github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 h1:EICbibRW4JNKMcY+LsWmuwob+CRS1BmdRdjphAm9mH4=
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 h1:Pn8fQdvx+z1avAi7fdM2kRYWQNxGlavNDSyzrQg2SsU=
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=

View File

@ -85,3 +85,22 @@ type TextComponent struct {
Color NullString `json:"color,omitempty"` Color NullString `json:"color,omitempty"`
Action interface{} `json:"action,omitempty"` Action interface{} `json:"action,omitempty"`
} }
// NewBoxComponent -
func NewBoxComponent(layout string) (box *BoxComponent) {
box = &BoxComponent{}
box.Type = "box"
box.SetLayout(layout)
return
}
// SetLayout -
func (p *BoxComponent) SetLayout(layout string) {
switch layout {
case "horizontal":
case "vertical":
p.Layout = layout
default:
p.Layout = "horizontal"
}
}

View File

@ -44,9 +44,23 @@ func NewCarouselContainer() *CarouselContainer {
} }
// AddContent - // AddContent -
func (p *CarouselContainer) AddContent(obj ...*BubbleContainer) (err error) { func (p *CarouselContainer) AddContent(items ...*BubbleContainer) (err error) {
if len(obj) == 0 { if len(items) == 0 {
return errors.New("no item") return errors.New("no item")
} }
if len(items) > 10 {
return errors.New("too many items")
}
if len(items)+len(p.Contents) > 10 {
return errors.New("too many items")
}
for _, v := range items {
if v == nil {
continue
}
p.Contents = append(p.Contents, v)
}
return return
} }