Compare commits
32 Commits
50567bc93e
...
main
Author | SHA1 | Date | |
---|---|---|---|
ce125279ca | |||
f68fdf3d9b | |||
56fa94fce7 | |||
5cbc048b51 | |||
19b1581f10 | |||
943191e9dd | |||
3ccf860ffc | |||
810d704afb | |||
34b69520f3 | |||
eeda65afea | |||
d204e58baf | |||
d29f680d0c | |||
50853b19b4 | |||
883e0e2e27 | |||
984bfa9ae1 | |||
6bcbe63df5 | |||
8c5dd62355 | |||
276d8b42d3 | |||
b2579520b9 | |||
95241405da | |||
805c0a7e21 | |||
66f06e8dd9 | |||
5f11ccf9f6 | |||
f4b408cf92 | |||
02c95ceb05 | |||
d834371a80 | |||
907c979ced | |||
42b66cc8af | |||
991b3a450a | |||
9d9ddfedcd | |||
9fe6dcac42 | |||
af6ae12947 |
@@ -4,7 +4,9 @@ Playing with Golang mostly using the Head First Go book.
|
|||||||
|
|
||||||
Entry point is playground.go.
|
Entry point is playground.go.
|
||||||
|
|
||||||
To run use
|
To run the playground use
|
||||||
```sh
|
```sh
|
||||||
|
cd playground
|
||||||
go run trying_out_go
|
go run trying_out_go
|
||||||
```
|
```
|
||||||
|
For any other folders, these are all separate go programs. Use the commands above and edit playground and trying_out_go to the matching folder name.
|
13
average.go
13
average.go
@@ -1,13 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func average() {
|
|
||||||
numbers := [3]float64{71.8, 56.2, 89.5}
|
|
||||||
var sum float64 = 0
|
|
||||||
for _, number := range numbers {
|
|
||||||
sum += number
|
|
||||||
}
|
|
||||||
sampleCount := float64(len(numbers))
|
|
||||||
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
|
||||||
}
|
|
22
cmd/averageWithArgs/averageWithArgs.go
Normal file
22
cmd/averageWithArgs/averageWithArgs.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
arguments := os.Args[1:]
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, argument := range arguments {
|
||||||
|
number, err := strconv.ParseFloat(argument, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
sampleCount := float64(len(arguments))
|
||||||
|
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
||||||
|
}
|
18
cmd/headFirstCodeMagnets/variadic.go
Normal file
18
cmd/headFirstCodeMagnets/variadic.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func sum(numbers ...int) int {
|
||||||
|
var sum = 0
|
||||||
|
|
||||||
|
for _, number := range numbers {
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(sum(4, 1, 9, 2))
|
||||||
|
fmt.Println(sum(7))
|
||||||
|
}
|
24
cmd/playground/averageHeadFirstSolution.go
Normal file
24
cmd/playground/averageHeadFirstSolution.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"trying_out_go/pkg/datafile"
|
||||||
|
"trying_out_go/pkg/keyboard"
|
||||||
|
)
|
||||||
|
|
||||||
|
func averageHeadFirstSolution() {
|
||||||
|
fmt.Printf("What is the name of the file: ")
|
||||||
|
fileString, err := keyboard.GetString()
|
||||||
|
Error(err)
|
||||||
|
fileString = strings.TrimSpace(fileString)
|
||||||
|
numbers, err := datafile.GetFloats(fileString)
|
||||||
|
Error(err)
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, number := range numbers {
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
sampleCount := float64(len(numbers))
|
||||||
|
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
||||||
|
}
|
26
cmd/playground/averageHeadFirstVariadic.go
Normal file
26
cmd/playground/averageHeadFirstVariadic.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func averageCalc(numbers ...float64) float64 {
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, number := range numbers {
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
return sum / float64(len(numbers))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
arguments := os.Args[1:]
|
||||||
|
var numbers []float64
|
||||||
|
for _, argument := range arguments {
|
||||||
|
number, err := strconv.ParseFloat(argument, 64)
|
||||||
|
Error(err)
|
||||||
|
numbers = append(numbers, number)
|
||||||
|
}
|
||||||
|
fmt.Printf("Average: %0.2f\n", averageCalc(numbers...))
|
||||||
|
}
|
37
cmd/playground/averageMySolution.go
Normal file
37
cmd/playground/averageMySolution.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"trying_out_go/pkg/keyboard"
|
||||||
|
)
|
||||||
|
|
||||||
|
func averageMySolution() {
|
||||||
|
fmt.Printf("What is the name of the file: ")
|
||||||
|
fileString, err := keyboard.GetString()
|
||||||
|
Error(err)
|
||||||
|
fileString = strings.TrimSpace(fileString)
|
||||||
|
file, err := os.Open(fileString)
|
||||||
|
Error(err)
|
||||||
|
var sum float64 = 0
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
counter := 0
|
||||||
|
for scanner.Scan() {
|
||||||
|
number, err := strconv.ParseFloat(scanner.Text(), 64)
|
||||||
|
Error(err)
|
||||||
|
sum += number
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
|
Error(err)
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
log.Fatal(scanner.Err())
|
||||||
|
}
|
||||||
|
sampleCount := float64(counter)
|
||||||
|
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
||||||
|
}
|
16
cmd/playground/averageVariadic.go
Normal file
16
cmd/playground/averageVariadic.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func average(numbers ...float64) float64 {
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, number := range numbers {
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
return sum / float64(len(numbers))
|
||||||
|
}
|
||||||
|
|
||||||
|
func averageVariadic() {
|
||||||
|
fmt.Println(average(100, 50))
|
||||||
|
fmt.Println(average(90.7, 89.7, 98.5, 92.3))
|
||||||
|
}
|
24
cmd/playground/calendar.go
Normal file
24
cmd/playground/calendar.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// from chapter 10
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"trying_out_go/pkg/calendar"
|
||||||
|
)
|
||||||
|
|
||||||
|
func companyCalendar() {
|
||||||
|
event := calendar.Event{}
|
||||||
|
err := event.SetTitle("Mom's Birthday")
|
||||||
|
Error(err)
|
||||||
|
err = event.SetYear(2019)
|
||||||
|
Error(err)
|
||||||
|
err = event.SetMonth(5)
|
||||||
|
Error(err)
|
||||||
|
err = event.SetDay(27)
|
||||||
|
Error(err)
|
||||||
|
|
||||||
|
fmt.Println(event.Title())
|
||||||
|
fmt.Println(event.Year())
|
||||||
|
fmt.Println(event.Month())
|
||||||
|
fmt.Println(event.Day())
|
||||||
|
}
|
56
cmd/playground/countVotes.go
Normal file
56
cmd/playground/countVotes.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// from Chapter 7 of Head First Go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"trying_out_go/pkg/datafile"
|
||||||
|
"trying_out_go/pkg/keyboard"
|
||||||
|
)
|
||||||
|
|
||||||
|
func countVotes() {
|
||||||
|
fmt.Printf("What is the name of the file: ")
|
||||||
|
fileString, err := keyboard.GetString()
|
||||||
|
Error(err)
|
||||||
|
fileString = strings.TrimSpace(fileString)
|
||||||
|
lines, err := datafile.GetStrings(fileString)
|
||||||
|
Error(err)
|
||||||
|
|
||||||
|
// Count the hard way with slices
|
||||||
|
var names []string
|
||||||
|
var counts []int
|
||||||
|
for _, line := range lines {
|
||||||
|
matched := false
|
||||||
|
for i, name := range names {
|
||||||
|
if name == line {
|
||||||
|
counts[i]++
|
||||||
|
matched = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if matched == false {
|
||||||
|
names = append(names, line)
|
||||||
|
counts = append(counts, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, name := range names {
|
||||||
|
fmt.Printf("%s: %d\n", name, counts[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
|
||||||
|
// Easy way
|
||||||
|
votes := make(map[string]int)
|
||||||
|
var namesMap []string
|
||||||
|
for _, line := range lines {
|
||||||
|
votes[line]++
|
||||||
|
}
|
||||||
|
for name := range votes {
|
||||||
|
namesMap = append(namesMap, name)
|
||||||
|
}
|
||||||
|
sort.Strings(namesMap)
|
||||||
|
for _, name := range namesMap {
|
||||||
|
fmt.Printf("%v: %v\n", name, votes[name])
|
||||||
|
}
|
||||||
|
}
|
28
cmd/playground/directory.go
Normal file
28
cmd/playground/directory.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func scanDirectory(path string) {
|
||||||
|
fmt.Println(path)
|
||||||
|
files, err := os.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
filePath := filepath.Join(path, file.Name())
|
||||||
|
if file.IsDir() {
|
||||||
|
scanDirectory(filePath)
|
||||||
|
} else {
|
||||||
|
fmt.Println(filePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func directory() {
|
||||||
|
scanDirectory("../../trying_out_go")
|
||||||
|
}
|
10
cmd/playground/error.go
Normal file
10
cmd/playground/error.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
func Error(err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
66
cmd/playground/fuel.go
Normal file
66
cmd/playground/fuel.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// part of chapter 9
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Liters float64
|
||||||
|
|
||||||
|
func (l Liters) String() string {
|
||||||
|
return fmt.Sprintf("%0.2f L", l)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Gallons float64
|
||||||
|
|
||||||
|
func (g Gallons) String() string {
|
||||||
|
return fmt.Sprintf("%0.2f gal", g)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Milliliters float64
|
||||||
|
|
||||||
|
func (m Milliliters) String() string {
|
||||||
|
return fmt.Sprintf("%0.2f mL", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Liters) ToGallons() Gallons {
|
||||||
|
return Gallons(l * 0.264)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Milliliters) ToGallons() Gallons {
|
||||||
|
return Gallons(m * 0.000264)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Gallons) ToLiters() Liters {
|
||||||
|
return Liters(g * 3.785)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Gallons) ToMilliliters() Milliliters {
|
||||||
|
return Milliliters(g * 3785.41)
|
||||||
|
}
|
||||||
|
|
||||||
|
func fuel() {
|
||||||
|
// long version
|
||||||
|
//var carFuel Gallons
|
||||||
|
//var busFuel Liters
|
||||||
|
//carFuel = Gallons(10.0)
|
||||||
|
//busFuel = Liters(240.0)
|
||||||
|
// short version
|
||||||
|
soda := Liters(2)
|
||||||
|
fmt.Printf("%0.0f liters equals %0.3f gallons\n", soda, soda.ToGallons())
|
||||||
|
water := Milliliters(500)
|
||||||
|
fmt.Printf("%0.0f milliliters equals %0.3f gallons \n", water, water.ToGallons())
|
||||||
|
//carFuel := Gallons(10.0)
|
||||||
|
//busFuel := Liters(240.0)
|
||||||
|
//
|
||||||
|
////if you want to convert between types, save variable with correct calculation
|
||||||
|
//carFuel += ToGallons(Liters(40.0))
|
||||||
|
//busFuel += ToLiters(Gallons(30.0))
|
||||||
|
//fmt.Printf("Car Fuel: %0.1f gallons\n", carFuel)
|
||||||
|
//fmt.Printf("Bus Fuel: %0.1f liters\n", busFuel)
|
||||||
|
milk := Gallons(2)
|
||||||
|
fmt.Printf("%0.0f gallons equals %0.3f liters\n", milk, milk.ToLiters())
|
||||||
|
fmt.Printf("%0.0f gallons equals %0.3f milliliters\n", milk, milk.ToMilliliters())
|
||||||
|
fmt.Println(Gallons(12.09285934))
|
||||||
|
fmt.Println(Liters(12.09285934))
|
||||||
|
fmt.Println(Milliliters(12.09285934))
|
||||||
|
}
|
46
cmd/playground/magazineSubscribers.go
Normal file
46
cmd/playground/magazineSubscribers.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// from chapter 8 of head first go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"trying_out_go/pkg/magazine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printInfo(s *magazine.Subscriber) {
|
||||||
|
fmt.Println("Name:", s.Name)
|
||||||
|
fmt.Println("Monthly rate:", s.Rate)
|
||||||
|
fmt.Println("Active?:", s.Active)
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultSubscriber(name string) *magazine.Subscriber {
|
||||||
|
s := magazine.Subscriber{
|
||||||
|
Name: name,
|
||||||
|
Rate: 5.99,
|
||||||
|
Active: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Street = "123 Oak St."
|
||||||
|
s.City = "Omaha"
|
||||||
|
s.State = "NE"
|
||||||
|
s.PostalCode = "68111"
|
||||||
|
|
||||||
|
return &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// accept a point to modify original struct
|
||||||
|
func applyDiscount(s *magazine.Subscriber) {
|
||||||
|
s.Rate = 4.99
|
||||||
|
}
|
||||||
|
|
||||||
|
func magazineSubscribers() {
|
||||||
|
employee := magazine.Employee{Name: "Joy Carr", Salary: 60000}
|
||||||
|
fmt.Println(employee.Name)
|
||||||
|
fmt.Println(employee.Salary)
|
||||||
|
subscriber := defaultSubscriber("Aman Singh")
|
||||||
|
applyDiscount(subscriber)
|
||||||
|
printInfo(subscriber)
|
||||||
|
fmt.Println(subscriber.State)
|
||||||
|
|
||||||
|
subscriber2 := defaultSubscriber("Beth Ryan")
|
||||||
|
printInfo(subscriber2)
|
||||||
|
}
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.linuxhg.com/john-okeefe/keyboard"
|
"trying_out_go/pkg/keyboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
func passFail() {
|
func passFail() {
|
145
cmd/playground/playground.go
Normal file
145
cmd/playground/playground.go
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/dixonwille/wmenu/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type program struct {
|
||||||
|
name string
|
||||||
|
launchFunction func()
|
||||||
|
}
|
||||||
|
|
||||||
|
programs := []program{
|
||||||
|
{
|
||||||
|
name: "Pass or Fail",
|
||||||
|
launchFunction: func() {
|
||||||
|
passFail()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Guessing Game",
|
||||||
|
launchFunction: func() {
|
||||||
|
guess()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Shopping List",
|
||||||
|
launchFunction: func() {
|
||||||
|
shopping()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Commandline Test",
|
||||||
|
launchFunction: func() {
|
||||||
|
terminalTest()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Wall Area",
|
||||||
|
launchFunction: func() {
|
||||||
|
wallArea()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "myIntPointer",
|
||||||
|
launchFunction: func() {
|
||||||
|
myIntPointer()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Double",
|
||||||
|
launchFunction: func() {
|
||||||
|
double()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Convert To Celsius",
|
||||||
|
launchFunction: func() {
|
||||||
|
toCelsius()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Get the Average My Solution",
|
||||||
|
launchFunction: func() {
|
||||||
|
averageMySolution()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Get the Average Head First Solution",
|
||||||
|
launchFunction: func() {
|
||||||
|
averageHeadFirstSolution()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Get the Average Variadic",
|
||||||
|
launchFunction: func() {
|
||||||
|
averageVariadic()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Slices",
|
||||||
|
launchFunction: func() {
|
||||||
|
slices()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Variadic Functions",
|
||||||
|
launchFunction: func() {
|
||||||
|
variadic()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Count Votes",
|
||||||
|
launchFunction: func() {
|
||||||
|
countVotes()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Magazine Subscribers",
|
||||||
|
launchFunction: func() {
|
||||||
|
magazineSubscribers()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Fuel",
|
||||||
|
launchFunction: func() {
|
||||||
|
fuel()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Calendar",
|
||||||
|
launchFunction: func() {
|
||||||
|
companyCalendar()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Directory List",
|
||||||
|
launchFunction: func() {
|
||||||
|
directory()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
menu := wmenu.NewMenu("Choose a program.")
|
||||||
|
menu.Action(func(opts []wmenu.Opt) error {
|
||||||
|
fmt.Printf("You chose " + opts[0].Text + ". Launching...\n")
|
||||||
|
for _, v := range programs {
|
||||||
|
if v.name == opts[0].Text {
|
||||||
|
v.launchFunction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
menu.PadOptionID()
|
||||||
|
for _, option := range programs {
|
||||||
|
menu.Option(option.name, nil, false, nil)
|
||||||
|
}
|
||||||
|
err := menu.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
41
cmd/playground/slices.go
Normal file
41
cmd/playground/slices.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func slices() {
|
||||||
|
var notes []string
|
||||||
|
notes = make([]string, 7)
|
||||||
|
|
||||||
|
notes[0] = "do"
|
||||||
|
notes[1] = "re"
|
||||||
|
notes[2] = "mi"
|
||||||
|
|
||||||
|
fmt.Println(notes[0])
|
||||||
|
fmt.Println(notes[1])
|
||||||
|
fmt.Println(len(notes))
|
||||||
|
|
||||||
|
primes := make([]int, 5)
|
||||||
|
primes[0] = 2
|
||||||
|
primes[1] = 3
|
||||||
|
primes[2] = 5
|
||||||
|
primes[3] = 7
|
||||||
|
primes[4] = 11
|
||||||
|
fmt.Println(primes[0])
|
||||||
|
fmt.Println(primes[1])
|
||||||
|
fmt.Println(primes[2])
|
||||||
|
fmt.Println(primes[3])
|
||||||
|
fmt.Println(primes[4])
|
||||||
|
fmt.Println(len(primes))
|
||||||
|
|
||||||
|
literalNotes := []string{"do", "re", "mi", "fa", "so", "la", "ti"}
|
||||||
|
fmt.Println(literalNotes[3], literalNotes[6], literalNotes[0])
|
||||||
|
literalPrimes := []int{
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
5,
|
||||||
|
}
|
||||||
|
fmt.Println(literalPrimes[0], literalPrimes[1], literalPrimes[2])
|
||||||
|
fmt.Println(literalPrimes, len(literalPrimes))
|
||||||
|
literalPrimes = append(literalPrimes, 7, 11)
|
||||||
|
fmt.Println(literalPrimes, len(literalPrimes))
|
||||||
|
}
|
@@ -48,6 +48,7 @@ func (m testModel) View() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func terminalTest() {
|
func terminalTest() {
|
||||||
|
//goland:noinspection SpellCheckingInspection,SpellCheckingInspection
|
||||||
items := []list.Item{
|
items := []list.Item{
|
||||||
item{title: "Raspberry Pi’s", desc: "I have ’em all over my house"},
|
item{title: "Raspberry Pi’s", desc: "I have ’em all over my house"},
|
||||||
item{title: "Nutella", desc: "It's good on toast"},
|
item{title: "Nutella", desc: "It's good on toast"},
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.linuxhg.com/john-okeefe/keyboard"
|
"trying_out_go/pkg/keyboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toCelsius() {
|
func toCelsius() {
|
33
cmd/playground/variadic.go
Normal file
33
cmd/playground/variadic.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func maximum(numbers ...float64) float64 {
|
||||||
|
maxNumber := math.Inf(-1)
|
||||||
|
for _, number := range numbers {
|
||||||
|
if number > maxNumber {
|
||||||
|
maxNumber = number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func inRange(min float64, max float64, numbers ...float64) []float64 {
|
||||||
|
var result []float64
|
||||||
|
for _, number := range numbers {
|
||||||
|
if number >= min && number <= max {
|
||||||
|
result = append(result, number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func variadic() {
|
||||||
|
fmt.Println(maximum(71.8, 56.2, 89.5))
|
||||||
|
fmt.Println(maximum(90.7, 89.7, 98.5, 92.3))
|
||||||
|
fmt.Println(inRange(1, 100, -12.5, 3.2, 0, 50, 103.5))
|
||||||
|
fmt.Println(inRange(-10, 10, 4.1, 12, -12, -5.2))
|
||||||
|
}
|
@@ -5,15 +5,15 @@ import "fmt"
|
|||||||
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
||||||
area := width * height
|
area := width * height
|
||||||
if width < 0.0 {
|
if width < 0.0 {
|
||||||
return 0, fmt.Errorf("a width of %0.2f is invalid.", width)
|
return 0, fmt.Errorf("a width of %0.2f is invalid", width)
|
||||||
}
|
}
|
||||||
if height < 0.0 {
|
if height < 0.0 {
|
||||||
return 0, fmt.Errorf("a height of %0.2f is invalid.", height)
|
return 0, fmt.Errorf("a height of %0.2f is invalid", height)
|
||||||
}
|
}
|
||||||
return area / 10.0, nil
|
return area / 10.0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printListersNeeded(amount float64) {
|
func printLitersNeeded(amount float64) {
|
||||||
fmt.Printf("%.2f liters needed\n", amount)
|
fmt.Printf("%.2f liters needed\n", amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,21 +23,21 @@ func wallArea() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
amount, err = paintNeeded(-5.2, 3.5)
|
amount, err = paintNeeded(-5.2, 3.5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
amount, err = paintNeeded(5.2, 5.0)
|
amount, err = paintNeeded(5.2, 5.0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
fmt.Printf("Total: %.2f liters\n", total)
|
fmt.Printf("Total: %.2f liters\n", total)
|
55
cmd/sum/sum.go
Normal file
55
cmd/sum/sum.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OpenFile(fileName string) (*os.File, error) {
|
||||||
|
fmt.Println("Opening", fileName)
|
||||||
|
return os.Open(fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CloseFile(file *os.File) {
|
||||||
|
fmt.Println("Closing file")
|
||||||
|
err := file.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFloats(fileName string) ([]float64, error) {
|
||||||
|
var numbers []float64
|
||||||
|
file, err := OpenFile(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer CloseFile(file)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
number, err := strconv.ParseFloat(scanner.Text(), 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
numbers = append(numbers, number)
|
||||||
|
}
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
return nil, scanner.Err()
|
||||||
|
}
|
||||||
|
return numbers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
numbers, err := GetFloats(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, number := range numbers {
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
fmt.Printf("Sum: %0.2f\n", sum)
|
||||||
|
}
|
4
datafile.txt
Normal file
4
datafile.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
50.2
|
||||||
|
60.2
|
||||||
|
74.3
|
||||||
|
85.4
|
23
go.mod
23
go.mod
@@ -1,11 +1,10 @@
|
|||||||
module trying_out_go
|
module trying_out_go
|
||||||
|
|
||||||
go 1.21.3
|
go 1.21.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc
|
github.com/charmbracelet/bubbles v0.18.0
|
||||||
github.com/charmbracelet/bubbles v0.16.1
|
github.com/charmbracelet/bubbletea v0.25.0
|
||||||
github.com/charmbracelet/bubbletea v0.24.2
|
|
||||||
github.com/charmbracelet/lipgloss v0.9.1
|
github.com/charmbracelet/lipgloss v0.9.1
|
||||||
github.com/dixonwille/wmenu/v5 v5.1.0
|
github.com/dixonwille/wmenu/v5 v5.1.0
|
||||||
)
|
)
|
||||||
@@ -15,19 +14,19 @@ require (
|
|||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
|
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
|
||||||
github.com/daviddengcn/go-colortext v1.0.0 // indirect
|
github.com/daviddengcn/go-colortext v1.0.0 // indirect
|
||||||
github.com/dixonwille/wlog/v3 v3.0.1 // indirect
|
github.com/dixonwille/wlog/v3 v3.0.4 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
github.com/muesli/reflow v0.3.0 // indirect
|
github.com/muesli/reflow v0.3.0 // indirect
|
||||||
github.com/muesli/termenv v0.15.2 // indirect
|
github.com/muesli/termenv v0.15.2 // indirect
|
||||||
github.com/rivo/uniseg v0.4.4 // indirect
|
github.com/rivo/uniseg v0.4.6 // indirect
|
||||||
github.com/sahilm/fuzzy v0.1.0 // indirect
|
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
|
||||||
golang.org/x/sync v0.4.0 // indirect
|
golang.org/x/sync v0.6.0 // indirect
|
||||||
golang.org/x/sys v0.13.0 // indirect
|
golang.org/x/sys v0.16.0 // indirect
|
||||||
golang.org/x/term v0.13.0 // indirect
|
golang.org/x/term v0.16.0 // indirect
|
||||||
golang.org/x/text v0.13.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
)
|
)
|
||||||
|
76
go.sum
76
go.sum
@@ -1,36 +1,30 @@
|
|||||||
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016005355-05ed8b28800e h1:oCGqHZUhesu14KQUELz0jxIPnL/KcGFhsmNnKoAZMo4=
|
|
||||||
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016005355-05ed8b28800e/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY=
|
|
||||||
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc h1:J5VWew9I6gCCYVxQ/5NEtsD4wcMZcc4e05V44OiSNi4=
|
|
||||||
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY=
|
|
||||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
|
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
|
||||||
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
|
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
|
||||||
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=
|
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
|
||||||
github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg=
|
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
|
||||||
github.com/charmbracelet/lipgloss v0.8.0 h1:IS00fk4XAHcf8uZKc3eHeMUTCxUH6NkaTrdyCQk84RU=
|
|
||||||
github.com/charmbracelet/lipgloss v0.8.0/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU=
|
|
||||||
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
|
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
|
||||||
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
|
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
|
||||||
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
|
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
|
||||||
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
|
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
|
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
|
||||||
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
|
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
|
||||||
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
|
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
|
||||||
github.com/dixonwille/wlog/v3 v3.0.1 h1:ViTSsNNndHlKW5S89x5O0KSTpTT9zdPqrkA/TZYY8+s=
|
|
||||||
github.com/dixonwille/wlog/v3 v3.0.1/go.mod h1:fPYZR9Ne5gFh3N8b3CuXVWHWxkY6Yg1wCeS3Km6Nc0I=
|
github.com/dixonwille/wlog/v3 v3.0.1/go.mod h1:fPYZR9Ne5gFh3N8b3CuXVWHWxkY6Yg1wCeS3Km6Nc0I=
|
||||||
|
github.com/dixonwille/wlog/v3 v3.0.4 h1:YLV5QT+dVKunV/XdlsWlrbTAZp41Zq21lb3YI3KKfRw=
|
||||||
|
github.com/dixonwille/wlog/v3 v3.0.4/go.mod h1:wh5luTpI/rczzuFeEjjLglEUkeGBIK1wZa2VTtpLkwY=
|
||||||
github.com/dixonwille/wmenu/v5 v5.1.0 h1:sKBHDoQ945NRvK0Eitd0kHDYHl1IYOSr1sdCK9c+Qr0=
|
github.com/dixonwille/wmenu/v5 v5.1.0 h1:sKBHDoQ945NRvK0Eitd0kHDYHl1IYOSr1sdCK9c+Qr0=
|
||||||
github.com/dixonwille/wmenu/v5 v5.1.0/go.mod h1:l6EGfXHaN6DPgv5+V5RY+cydAXJsj/oDZVczcdukPzc=
|
github.com/dixonwille/wmenu/v5 v5.1.0/go.mod h1:l6EGfXHaN6DPgv5+V5RY+cydAXJsj/oDZVczcdukPzc=
|
||||||
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
|
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
|
||||||
github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A=
|
github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A=
|
||||||
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
|
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
|
||||||
github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE=
|
github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE=
|
||||||
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZPbFy2P7jH5LKJ3La+0ZeknkkmrSgqb0=
|
|
||||||
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
|
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
|
||||||
github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ=
|
github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ=
|
||||||
github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA=
|
github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA=
|
||||||
@@ -39,19 +33,13 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
|
|||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||||
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
|
||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
||||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
|
||||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
|
|
||||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
|
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||||
@@ -63,34 +51,32 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n
|
|||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
|
||||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
|
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
|
||||||
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||||
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
|
||||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||||
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
|
||||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
|
||||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
|
||||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
56
pkg/calendar/date.go
Normal file
56
pkg/calendar/date.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package calendar
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
// Date Struct
|
||||||
|
type Date struct {
|
||||||
|
year int
|
||||||
|
month int
|
||||||
|
day int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter Methods
|
||||||
|
|
||||||
|
// SetYear Method
|
||||||
|
func (d *Date) SetYear(year int) error {
|
||||||
|
if year < 1 {
|
||||||
|
return errors.New("invalid year")
|
||||||
|
}
|
||||||
|
d.year = year
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMonth Method
|
||||||
|
func (d *Date) SetMonth(month int) error {
|
||||||
|
if month < 1 || month > 12 {
|
||||||
|
return errors.New("invalid month")
|
||||||
|
}
|
||||||
|
d.month = month
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDay Method
|
||||||
|
func (d *Date) SetDay(day int) error {
|
||||||
|
if day < 1 || day > 31 {
|
||||||
|
return errors.New("invalid day")
|
||||||
|
}
|
||||||
|
d.day = day
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter Methods
|
||||||
|
|
||||||
|
// Year Method
|
||||||
|
func (d *Date) Year() int {
|
||||||
|
return d.year
|
||||||
|
}
|
||||||
|
|
||||||
|
// Month Method
|
||||||
|
func (d *Date) Month() int {
|
||||||
|
return d.month
|
||||||
|
}
|
||||||
|
|
||||||
|
// Day Method
|
||||||
|
func (d *Date) Day() int {
|
||||||
|
return d.day
|
||||||
|
}
|
23
pkg/calendar/event.go
Normal file
23
pkg/calendar/event.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package calendar
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
title string
|
||||||
|
Date
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Event) Title() string {
|
||||||
|
return e.title
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Event) SetTitle(title string) error {
|
||||||
|
if utf8.RuneCountInString(title) > 32 {
|
||||||
|
return errors.New("invalid title length")
|
||||||
|
}
|
||||||
|
e.title = title
|
||||||
|
return nil
|
||||||
|
}
|
32
pkg/datafile/floats.go
Normal file
32
pkg/datafile/floats.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package datafile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetFloats reads a float64 from each line of a file.
|
||||||
|
func GetFloats(fileName string) ([]float64, error) {
|
||||||
|
var numbers []float64
|
||||||
|
file, err := os.Open(fileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
number, err := strconv.ParseFloat(scanner.Text(), 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
numbers = append(numbers, number)
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
return numbers, scanner.Err()
|
||||||
|
}
|
||||||
|
return numbers, nil
|
||||||
|
}
|
31
pkg/datafile/strings.go
Normal file
31
pkg/datafile/strings.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package datafile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetStrings(filename string) ([]string, error) {
|
||||||
|
var lines []string
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
return nil, scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines, nil
|
||||||
|
}
|
56
pkg/date/date.go
Normal file
56
pkg/date/date.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package calendar
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
// Date Struct
|
||||||
|
type Date struct {
|
||||||
|
year int
|
||||||
|
month int
|
||||||
|
day int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter Methods
|
||||||
|
|
||||||
|
// SetYear Method
|
||||||
|
func (d *Date) SetYear(year int) error {
|
||||||
|
if year < 1 {
|
||||||
|
return errors.New("invalid year")
|
||||||
|
}
|
||||||
|
d.year = year
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMonth Method
|
||||||
|
func (d *Date) SetMonth(month int) error {
|
||||||
|
if month < 1 || month > 12 {
|
||||||
|
return errors.New("invalid month")
|
||||||
|
}
|
||||||
|
d.month = month
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDay Method
|
||||||
|
func (d *Date) SetDay(day int) error {
|
||||||
|
if day < 1 || day > 31 {
|
||||||
|
return errors.New("invalid day")
|
||||||
|
}
|
||||||
|
d.day = day
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter Methods
|
||||||
|
|
||||||
|
// Year Method
|
||||||
|
func (d *Date) Year() int {
|
||||||
|
return d.year
|
||||||
|
}
|
||||||
|
|
||||||
|
// Month Method
|
||||||
|
func (d *Date) Month() int {
|
||||||
|
return d.month
|
||||||
|
}
|
||||||
|
|
||||||
|
// Day Method
|
||||||
|
func (d *Date) Day() int {
|
||||||
|
return d.day
|
||||||
|
}
|
23
pkg/date/event.go
Normal file
23
pkg/date/event.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package calendar
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
title string
|
||||||
|
Date
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Event) Title() string {
|
||||||
|
return e.title
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Event) SetTitle(title string) error {
|
||||||
|
if utf8.RuneCountInString(title) > 32 {
|
||||||
|
return errors.New("invalid title length")
|
||||||
|
}
|
||||||
|
e.title = title
|
||||||
|
return nil
|
||||||
|
}
|
33
pkg/gadget/program.go
Normal file
33
pkg/gadget/program.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Player interface {
|
||||||
|
Play(string)
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryOut(player Player) {
|
||||||
|
player.Play("Test Track")
|
||||||
|
player.Stop()
|
||||||
|
recorder, ok := player.(TapeRecorder)
|
||||||
|
if ok {
|
||||||
|
recorder.Record()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func playList(device Player, songs []string) {
|
||||||
|
for _, song := range songs {
|
||||||
|
device.Play(song)
|
||||||
|
}
|
||||||
|
|
||||||
|
device.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
mixTape := []string{"Jessie's Girl", "Whip It", "9 to 5"}
|
||||||
|
var player Player = TapePlayer{}
|
||||||
|
playList(player, mixTape)
|
||||||
|
player = TapeRecorder{}
|
||||||
|
playList(player, mixTape)
|
||||||
|
TryOut(TapeRecorder{})
|
||||||
|
TryOut(TapePlayer{})
|
||||||
|
}
|
31
pkg/gadget/tape.go
Normal file
31
pkg/gadget/tape.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type TapePlayer struct {
|
||||||
|
Batteries string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TapePlayer) Play(song string) {
|
||||||
|
fmt.Println("Playing", song)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TapePlayer) Stop() {
|
||||||
|
fmt.Println("Stopped")
|
||||||
|
}
|
||||||
|
|
||||||
|
type TapeRecorder struct {
|
||||||
|
Microphone int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TapeRecorder) Play(song string) {
|
||||||
|
fmt.Println("Playing", song)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TapeRecorder) Record() {
|
||||||
|
fmt.Println("Recording")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TapeRecorder) Stop() {
|
||||||
|
fmt.Println("Stopped")
|
||||||
|
}
|
38
pkg/keyboard/keyboard.go
Normal file
38
pkg/keyboard/keyboard.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Package keyboard reads user input from the keyboard.
|
||||||
|
package keyboard
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetString reads a string from the keyboard.
|
||||||
|
// It returns the string read and any error encountered.
|
||||||
|
func GetString() (string, error) {
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
input, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return input, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFloat reads a floating-point number from the keyboard.
|
||||||
|
// It returns the number read and any error encountered.
|
||||||
|
func GetFloat() (float64, error) {
|
||||||
|
input, err := GetString()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
input = strings.TrimSpace(input)
|
||||||
|
number, err := strconv.ParseFloat(input, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return number, nil
|
||||||
|
}
|
21
pkg/magazine/types.go
Normal file
21
pkg/magazine/types.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package magazine
|
||||||
|
|
||||||
|
type Subscriber struct {
|
||||||
|
Name string
|
||||||
|
Rate float64
|
||||||
|
Active bool
|
||||||
|
Address
|
||||||
|
}
|
||||||
|
|
||||||
|
type Employee struct {
|
||||||
|
Name string
|
||||||
|
Salary float64
|
||||||
|
Address
|
||||||
|
}
|
||||||
|
|
||||||
|
type Address struct {
|
||||||
|
Street string
|
||||||
|
City string
|
||||||
|
State string
|
||||||
|
PostalCode string
|
||||||
|
}
|
@@ -1,50 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/dixonwille/wmenu/v5"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
menu := wmenu.NewMenu("Choose a program.")
|
|
||||||
menu.Action(func(opts []wmenu.Opt) error {
|
|
||||||
fmt.Printf("You chose " + opts[0].Text + ". Launching...\n")
|
|
||||||
switch opts[0].Text {
|
|
||||||
case "Pass or Fail":
|
|
||||||
passFail()
|
|
||||||
case "Guessing Game":
|
|
||||||
guess()
|
|
||||||
case "Shopping List":
|
|
||||||
shopping()
|
|
||||||
case "Commandline Test":
|
|
||||||
terminalTest()
|
|
||||||
case "Wall Area":
|
|
||||||
wallArea()
|
|
||||||
case "myIntPointer":
|
|
||||||
myIntPointer()
|
|
||||||
case "Double":
|
|
||||||
double()
|
|
||||||
case "Convert To Celsius":
|
|
||||||
toCelsius()
|
|
||||||
case "Get the Average":
|
|
||||||
average()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
menu.PadOptionID()
|
|
||||||
menu.Option("Pass or Fail", nil, false, nil)
|
|
||||||
menu.Option("Guessing Game", nil, false, nil)
|
|
||||||
menu.Option("Shopping List", nil, false, nil)
|
|
||||||
menu.Option("Commandline Test", nil, false, nil)
|
|
||||||
menu.Option("Wall Area", nil, false, nil)
|
|
||||||
menu.Option("myIntPointer", nil, false, nil)
|
|
||||||
menu.Option("Double", nil, false, nil)
|
|
||||||
menu.Option("Convert To Celsius", nil, false, nil)
|
|
||||||
menu.Option("Get the Average", nil, false, nil)
|
|
||||||
err := menu.Run()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
97
votes.txt
Normal file
97
votes.txt
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Brian Martin
|
||||||
|
Amber Graham
|
||||||
|
Carlos Diaz
|
||||||
|
Silly name
|
Reference in New Issue
Block a user