-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exploration for adding a helper that builds a displayer.
- Loading branch information
Showing
6 changed files
with
42 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package format | ||
|
||
// NewField creates a new Field with the given name and value format string. See | ||
// the Field struct for more information. | ||
func NewField(name, valueFormat string) Field { | ||
return Field{Name: name, ValueFormat: valueFormat} | ||
} | ||
|
||
// NewDisplayer creates a new Displayer with the given payload, default format, | ||
// and fields. | ||
func NewDisplayer[T any](payload T, defaultFormat Format, fields []Field) Displayer { | ||
return &internalDisplayer[T]{ | ||
payload: payload, | ||
fields: fields, | ||
defaultFormat: defaultFormat, | ||
} | ||
} | ||
|
||
type internalDisplayer[T any] struct { | ||
payload T | ||
fields []Field | ||
defaultFormat Format | ||
} | ||
|
||
func (i *internalDisplayer[T]) DefaultFormat() Format { return i.defaultFormat } | ||
func (i *internalDisplayer[T]) FieldTemplates() []Field { return i.fields } | ||
func (i *internalDisplayer[T]) Payload() any { return i.payload } |