command
Version:
v0.1.7
Opens a new window with list of versions in this module.
Published: Apr 15, 2025
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Pointer Slices Example
This example demonstrates how to use pointers and slices of pointers with genstruct.
Features Demonstrated
- Single pointer references (
*Author)
- Slices of pointer references (
[]*Comment)
- Bi-directional references between different types
Data Model
This example uses three related types:
- Author: Represents a content creator
- Comment: User feedback with a pointer to its Author
- Article: A blog article with a pointer to its Author and a slice of pointers to Comments
Relationships
- Each Article has one Author (single pointer:
*Author)
- Each Article has multiple Comments (slice of pointers:
[]*Comment)
- Each Comment has one Author (single pointer:
*Author)
Running the Example
go run main.go
This will generate articles_generated.go with constants, variables, and slices for all the data, including proper pointer references.
Generated Code Usage
The generated code enables you to:
- Access specific articles via their constants:
ArticleUnderstandingPointerSlices
- Navigate directly to their author:
ArticleUnderstandingPointerSlices.Author.Name
- Access all comments:
ArticleUnderstandingPointerSlices.Comments
- Navigate from comments back to their authors:
ArticleUnderstandingPointerSlices.Comments[0].Author.Name
Testing
Run the tests with:
go test -v
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.