Added basic and some advanced menu options

This commit is contained in:
Andrew Scott 2022-07-07 20:27:00 -04:00
parent 089c69c642
commit 9e8e00e915
Signed by: a
GPG key ID: 3EB62D0BBB8DB381
3 changed files with 91 additions and 11 deletions

View file

@ -0,0 +1,40 @@
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"sync"
)
func advancedMenu(wg *sync.WaitGroup) {
var option string
for option != "0" {
fmt.Print("\nAdvanced Menu\n-------------\n\n")
fmt.Println("1. Change units (Fahrenheit/Celsius)")
fmt.Println("2. Enter precise location")
fmt.Print("0. Back\n\n")
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
option = strings.TrimSuffix(input, "\n")
if option == "1" {
fmt.Print("\nChanged units...\n\n")
} else if option == "2" {
fmt.Print("Precise location selected...\n\n")
}
}
wg.Done()
}

51
cmd/client/main.go Normal file
View file

@ -0,0 +1,51 @@
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"sync"
)
func main() {
var option string
var wg sync.WaitGroup
fmt.Println("\n==============================================")
fmt.Println("| Welcome to the OpenWeatherMap-gRPC Client! |")
fmt.Print("==============================================\n")
for option != "0" {
fmt.Print("\nMain Menu\n---------\n\n")
fmt.Println("1. Today's forecast (use current location)")
fmt.Println("2. Advanced options")
fmt.Print("0. Exit\n\n")
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
option = strings.TrimSuffix(input, "\n")
if option == "1" {
fmt.Println("Option 1 selected...")
} else if option == "2" {
wg.Add(1)
go advancedMenu(&wg)
wg.Wait()
} else if option == "0" {
return
} else {
fmt.Print("\nOops! An error occurred, please choose a valid option.\n\n")
}
}
}

View file

@ -1,11 +0,0 @@
package main
import "flag"
func main() {
var mode string
flag.StringVar(&mode, "mode", "client", "Specify \"client\" or \"server\" mode")
flag.Parse()
}