update
This commit is contained in:
parent
9aadc7c1d0
commit
0ca1d9889d
1
go.mod
1
go.mod
@ -16,7 +16,6 @@ require (
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
|
||||
github.com/stretchr/testify v1.2.2 // 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/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
|
||||
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -32,8 +32,6 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
|
||||
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/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/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
|
@ -1,5 +1,9 @@
|
||||
package line
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Component -
|
||||
type Component struct {
|
||||
Type string `json:"type"`
|
||||
@ -16,6 +20,49 @@ type BoxComponent struct {
|
||||
Margin NullString `json:"margin,omitempty"`
|
||||
}
|
||||
|
||||
// SetLayout -
|
||||
func (p *BoxComponent) SetLayout(layout string) {
|
||||
switch layout {
|
||||
case "horizontal":
|
||||
case "vertical":
|
||||
case "baseline":
|
||||
p.Layout = layout
|
||||
default:
|
||||
p.Layout = "horizontal"
|
||||
}
|
||||
}
|
||||
|
||||
// SetContent -
|
||||
func (p *BoxComponent) SetContent(content interface{}) (err error) {
|
||||
if p.Layout == "horizontal" || p.Layout == "vertical" {
|
||||
switch content.(type) {
|
||||
case *BoxComponent:
|
||||
case *ButtonComponent:
|
||||
case *FillerComponent:
|
||||
case *ImageComponent:
|
||||
case *SeparatorComponent:
|
||||
case *SpacerComponent:
|
||||
case *TextComponent:
|
||||
p.Contents = append(p.Contents, content)
|
||||
default:
|
||||
return errors.New("content type not allow")
|
||||
}
|
||||
} else if p.Layout == "baseline" {
|
||||
switch content.(type) {
|
||||
case *FillerComponent:
|
||||
case *IconComponent:
|
||||
case *SpacerComponent:
|
||||
case *TextComponent:
|
||||
p.Contents = append(p.Contents, content)
|
||||
default:
|
||||
return errors.New("content type not allow")
|
||||
}
|
||||
} else {
|
||||
return errors.New("layout type not valid")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ButtonComponent -
|
||||
type ButtonComponent struct {
|
||||
Component
|
||||
@ -94,13 +141,32 @@ func NewBoxComponent(layout string) (box *BoxComponent) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetLayout -
|
||||
func (p *BoxComponent) SetLayout(layout string) {
|
||||
switch layout {
|
||||
case "horizontal":
|
||||
case "vertical":
|
||||
p.Layout = layout
|
||||
default:
|
||||
p.Layout = "horizontal"
|
||||
// NewButtonComponent -
|
||||
func NewButtonComponent() (btn *ButtonComponent) {
|
||||
btn = &ButtonComponent{}
|
||||
btn.Type = "button"
|
||||
return
|
||||
}
|
||||
|
||||
// NewFillerComponent -
|
||||
func NewFillerComponent() (filler *FillerComponent) {
|
||||
filler = &FillerComponent{}
|
||||
filler.Type = "filler"
|
||||
return
|
||||
}
|
||||
|
||||
// NewIconComponent -
|
||||
func NewIconComponent(imgUrl string) (icon *IconComponent) {
|
||||
icon = &IconComponent{}
|
||||
icon.Type = "icon"
|
||||
icon.URL = imgUrl
|
||||
return
|
||||
}
|
||||
|
||||
// NewImageComponent -
|
||||
func NewImageComponent(imgUrl string) (image *ImageComponent) {
|
||||
image = &ImageComponent{}
|
||||
image.Type = "image"
|
||||
image.URL = imgUrl
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user