Defining a Product Catalog Struct in Go
This challenge focuses on defining a struct in Go to represent a product in an online catalog. Structs are fundamental for organizing data into logical units, and this exercise will help you understand how to define and structure data effectively. You'll be creating a Product struct with various attributes commonly found in product listings.
Problem Description
You are tasked with defining a Product struct in Go. This struct should represent a single product in an online catalog and contain the following fields:
ID: An integer representing the unique identifier of the product.Name: A string representing the name of the product.Description: A string providing a detailed description of the product.Price: A float64 representing the price of the product.InStock: A boolean indicating whether the product is currently in stock.Category: A string representing the category the product belongs to.
Your solution should only include the struct definition. No methods or instances of the struct are required.
Examples
Example 1:
Input: None (just struct definition)
Output:
type Product struct {
ID int
Name string
Description string
Price float64
InStock bool
Category string
}
Explanation: This defines a struct named Product with the specified fields and their corresponding types.
Example 2:
Input: None (just struct definition)
Output:
type Product struct {
ProductID int
ProductName string
ProductDescription string
Cost float64
Available bool
ProductCategory string
}
Explanation: This is a valid alternative struct definition, using different field names but still fulfilling the requirements of representing a product with the specified attributes. The field names are flexible as long as the types are correct.
Constraints
- The struct must be named
Product. - The struct must contain all the fields listed in the Problem Description with the specified types.
- Field names can be different, but the types must match.
- No methods or instances of the struct are allowed in the solution. Only the struct definition is required.
Notes
- Structs are a core concept in Go for data aggregation.
- Consider the data types carefully to ensure they accurately represent the product attributes.
- This is a foundational exercise; focus on correctly defining the struct's structure.