-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-eventix
- Loading branch information
Showing
144 changed files
with
6,461 additions
and
8,175 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 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 |
---|---|---|
|
@@ -27,7 +27,7 @@ jobs: | |
cache: true | ||
|
||
- uses: sigstore/[email protected] | ||
- uses: anchore/sbom-action/[email protected].8 | ||
- uses: anchore/sbom-action/[email protected].9 | ||
|
||
- uses: docker/login-action@v3 | ||
with: | ||
|
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ jobs: | |
cache: true | ||
|
||
- uses: sigstore/[email protected] | ||
- uses: anchore/sbom-action/[email protected].8 | ||
- uses: anchore/sbom-action/[email protected].9 | ||
|
||
- uses: docker/login-action@v3 | ||
with: | ||
|
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 @@ | ||
module gno.land/p/demo/avl/rolist |
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,119 @@ | ||
// Package rolist provides a read-only wrapper for list.List with safe value transformation. | ||
// | ||
// It is useful when you want to expose a read-only view of a list while ensuring that | ||
// the sensitive data cannot be modified. | ||
// | ||
// Example: | ||
// | ||
// // Define a user structure with sensitive data | ||
// type User struct { | ||
// Name string | ||
// Balance int | ||
// Internal string // sensitive field | ||
// } | ||
// | ||
// // Create and populate the original list | ||
// privateList := list.New() | ||
// privateList.Append(&User{ | ||
// Name: "Alice", | ||
// Balance: 100, | ||
// Internal: "sensitive", | ||
// }) | ||
// | ||
// // Create a safe transformation function that copies the struct | ||
// // while excluding sensitive data | ||
// makeEntrySafeFn := func(v interface{}) interface{} { | ||
// u := v.(*User) | ||
// return &User{ | ||
// Name: u.Name, | ||
// Balance: u.Balance, | ||
// Internal: "", // omit sensitive data | ||
// } | ||
// } | ||
// | ||
// // Create a read-only view of the list | ||
// publicList := rolist.Wrap(list, makeEntrySafeFn) | ||
// | ||
// // Safely access the data | ||
// value := publicList.Get(0) | ||
// user := value.(*User) | ||
// // user.Name == "Alice" | ||
// // user.Balance == 100 | ||
// // user.Internal == "" (sensitive data is filtered) | ||
package rolist | ||
|
||
import ( | ||
"gno.land/p/demo/avl/list" | ||
) | ||
|
||
// IReadOnlyList defines the read-only operations available on a list. | ||
type IReadOnlyList interface { | ||
Len() int | ||
Get(index int) interface{} | ||
Slice(startIndex, endIndex int) []interface{} | ||
ForEach(fn func(index int, value interface{}) bool) | ||
} | ||
|
||
// ReadOnlyList wraps a list.List and provides read-only access. | ||
type ReadOnlyList struct { | ||
list *list.List | ||
makeEntrySafeFn func(interface{}) interface{} | ||
} | ||
|
||
// Verify interface implementations | ||
var _ IReadOnlyList = (*ReadOnlyList)(nil) | ||
var _ IReadOnlyList = (interface{ list.IList })(nil) // is subset of list.IList | ||
|
||
// Wrap creates a new ReadOnlyList from an existing list.List and a safety transformation function. | ||
// If makeEntrySafeFn is nil, values will be returned as-is without transformation. | ||
func Wrap(list *list.List, makeEntrySafeFn func(interface{}) interface{}) *ReadOnlyList { | ||
return &ReadOnlyList{ | ||
list: list, | ||
makeEntrySafeFn: makeEntrySafeFn, | ||
} | ||
} | ||
|
||
// getSafeValue applies the makeEntrySafeFn if it exists, otherwise returns the original value | ||
func (rol *ReadOnlyList) getSafeValue(value interface{}) interface{} { | ||
if rol.makeEntrySafeFn == nil { | ||
return value | ||
} | ||
return rol.makeEntrySafeFn(value) | ||
} | ||
|
||
// Len returns the number of elements in the list. | ||
func (rol *ReadOnlyList) Len() int { | ||
return rol.list.Len() | ||
} | ||
|
||
// Get returns the value at the specified index, converted to a safe format. | ||
// Returns nil if index is out of bounds. | ||
func (rol *ReadOnlyList) Get(index int) interface{} { | ||
value := rol.list.Get(index) | ||
if value == nil { | ||
return nil | ||
} | ||
return rol.getSafeValue(value) | ||
} | ||
|
||
// Slice returns a slice of values from startIndex (inclusive) to endIndex (exclusive), | ||
// with all values converted to a safe format. | ||
func (rol *ReadOnlyList) Slice(startIndex, endIndex int) []interface{} { | ||
values := rol.list.Slice(startIndex, endIndex) | ||
if values == nil { | ||
return nil | ||
} | ||
|
||
result := make([]interface{}, len(values)) | ||
for i, v := range values { | ||
result[i] = rol.getSafeValue(v) | ||
} | ||
return result | ||
} | ||
|
||
// ForEach iterates through all elements in the list, providing safe versions of the values. | ||
func (rol *ReadOnlyList) ForEach(fn func(index int, value interface{}) bool) { | ||
rol.list.ForEach(func(index int, value interface{}) bool { | ||
return fn(index, rol.getSafeValue(value)) | ||
}) | ||
} |
Oops, something went wrong.