start anew. re-think the GUI to add menu's to widgets
This commit is contained in:
commit
adc8a7604a
|
@ -0,0 +1,4 @@
|
|||
*.swp
|
||||
go.mod
|
||||
go.sum
|
||||
junk
|
|
@ -0,0 +1,18 @@
|
|||
all:
|
||||
@#GO111MODULE=off go build
|
||||
@GO111MODULE=off go vet -x
|
||||
@echo this go library package builds okay
|
||||
|
||||
build:
|
||||
@GO111MODULE=off go build -x -o junk
|
||||
./junk
|
||||
|
||||
goimports:
|
||||
goimports -w *.go
|
||||
|
||||
redomod:
|
||||
rm -f go.*
|
||||
goimports -w *.go
|
||||
GO111MODULE= go mod init
|
||||
GO111MODULE= go mod tidy
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type Circle struct {
|
||||
Radius float64
|
||||
}
|
||||
|
||||
func (c Circle) Area() float64 {
|
||||
return math.Pi * math.Pow(c.Radius, 2)
|
||||
}
|
||||
|
||||
func (c Circle) String() string {
|
||||
return fmt.Sprintf("Circle {Radius: %.2f}", c.Radius)
|
||||
}
|
||||
|
||||
type Square struct {
|
||||
Width float64
|
||||
Height float64
|
||||
}
|
||||
|
||||
func (s Square) Area() float64 {
|
||||
return s.Width * s.Height
|
||||
}
|
||||
|
||||
func (s Square) String() string {
|
||||
return fmt.Sprintf("Square {Width: %.2f, Height: %.2f}", s.Width, s.Height)
|
||||
}
|
||||
|
||||
type Sizer interface {
|
||||
Area() float64
|
||||
}
|
||||
|
||||
type Shaper interface {
|
||||
Sizer
|
||||
fmt.Stringer
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := Circle{Radius: 10}
|
||||
PrintArea(c)
|
||||
|
||||
s := Square{Height: 10, Width: 5}
|
||||
PrintArea(s)
|
||||
|
||||
l := Less(c, s)
|
||||
fmt.Printf("%v is the smallest\n", l)
|
||||
|
||||
}
|
||||
|
||||
func Less(s1, s2 Sizer) Sizer {
|
||||
if s1.Area() < s2.Area() {
|
||||
return s1
|
||||
}
|
||||
return s2
|
||||
}
|
||||
|
||||
func PrintArea(s Shaper) {
|
||||
fmt.Printf("area of %s is %.2f\n", s.String(), s.Area())
|
||||
}
|
Loading…
Reference in New Issue