
Go Learning Notes - Part 7: Struct
Today I learned about Structs in Go and encountered the type keyword, which allows us to create custom data types. This lesson helped me improve my booking app by replacing maps with a more structured and type-safe approach. Struct A struct is a composite data type that groups together variables under a single name. It helps organize related data into one logical unit. In my booking app, instead of using a map[string]string , I created a custom struct: type UserData struct { firstName string lastName string email string numberOfTickets uint } Here, UserData is a custom type created using the type keyword. The type Keyword The type keyword in Go allows us to define our own data types. type UserData struct { ... } This means: I created a new type called UserData It has fields like firstName , lastName , email , and numberOfTickets It behaves like a blueprint for user booking information This makes the program cleaner and more structured. Creating a struct Instance Inside my bookTicket()
Continue reading on Dev.to Beginners
Opens in a new tab



