This commit is contained in:
Jay 2019-02-05 00:42:24 +08:00
parent 9aadc7c1d0
commit 0ca1d9889d
3 changed files with 75 additions and 12 deletions

1
go.mod
View File

@ -16,7 +16,6 @@ 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,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/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

@ -1,5 +1,9 @@
package line package line
import (
"errors"
)
// Component - // Component -
type Component struct { type Component struct {
Type string `json:"type"` Type string `json:"type"`
@ -16,6 +20,49 @@ type BoxComponent struct {
Margin NullString `json:"margin,omitempty"` 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 - // ButtonComponent -
type ButtonComponent struct { type ButtonComponent struct {
Component Component
@ -94,13 +141,32 @@ func NewBoxComponent(layout string) (box *BoxComponent) {
return return
} }
// SetLayout - // NewButtonComponent -
func (p *BoxComponent) SetLayout(layout string) { func NewButtonComponent() (btn *ButtonComponent) {
switch layout { btn = &ButtonComponent{}
case "horizontal": btn.Type = "button"
case "vertical": return
p.Layout = layout
default:
p.Layout = "horizontal"
} }
// 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
} }