part one of the app

This commit is contained in:
2026-08-06 21:45:07 +02:00
parent 32c8995bf9
commit 063489774e
4 changed files with 97 additions and 1 deletions
+13
View File
@@ -1,3 +1,16 @@
# go-cli-course
Full golang course with a CLI project development
## Project
- Booking App
- Stopped at 1:56:05 - https://youtu.be/yyUHQIec83I?si=62O0tlgcHmQBku9f&t=6965
## Setup
### Install Go
### VS Code Extensions
- Go - Go Team at Google
+3
View File
@@ -0,0 +1,3 @@
module booking-app
go 1.26.5
BIN
View File
Binary file not shown.
+80
View File
@@ -0,0 +1,80 @@
package main
import (
"fmt"
"strings"
)
func main() {
conferenceName := "Go Conference"
const conferenceTickets int = 50
var remainingTickets uint = 50
fmt.Printf("Welcome to %v booking application\n", conferenceName)
fmt.Printf("We have total of %v tickets and %v are still available.\n", conferenceTickets, remainingTickets)
fmt.Println("Get your tickets here to attend")
bookings := []string{}
for remainingTickets > 0 && len(bookings) < 50 {
var firstName string
var lastName string
var email string
var userTickets uint
// ask user for their name
fmt.Printf("- Enter your first name: ")
fmt.Scan(&firstName)
// ask user for their last name
fmt.Printf("- Enter your last name: ")
fmt.Scan(&lastName)
// ask user for their email
fmt.Printf("- Enter your email address: ")
fmt.Scan(&email)
// ask user for the number of tickets
fmt.Printf("- How many tickets to you want to book: ")
fmt.Scan(&userTickets)
// validations
isValidName := len(firstName) >= 2 && len(lastName) >= 2
isValidEmail := strings.Contains(email, "@")
isValidNumber := userTickets > 0 && userTickets <= remainingTickets
if isValidName && isValidEmail && isValidNumber {
// array-fashion: bookings[0] = firstName + " " + lastName
bookings = append(bookings, firstName + " " + lastName)
remainingTickets = remainingTickets - userTickets
// Thank you message
fmt.Printf("Thank you %v %v for booking %v tickets. You will receive a confirmation email at %v\n", firstName, lastName, userTickets, email)
fmt.Printf("%v ticket remaining for %v\n", remainingTickets, conferenceName)
firstNames := []string{}
for _, firstAndLastName := range bookings {
var names = strings.Fields(firstAndLastName)
firstNames = append(firstNames, names[0])
}
fmt.Printf("These are all the first names of our bookings: %v\n", firstNames)
if remainingTickets == 0 {
// end program
fmt.Println("Out conference is booked out. Come back next year.")
break
}
} else {
if !isValidName {
fmt.Printf("!! Oops: first name and last name must be at least size 2\n")
}
if !isValidEmail {
fmt.Printf("!! Oops: email must be a valid email\n")
}
if !isValidNumber {
fmt.Printf("!! Oops: number of tickets should be valid and less or equals %v\n", remainingTickets)
}
}
}
}