-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(nwgate): Update for new protobufs and interface data gathering
Signed-off-by: Mark Sanders <marksanders194@gmail.com>
- Loading branch information
Showing
9 changed files
with
150 additions
and
46 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
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
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 |
---|---|---|
@@ -1,4 +1,40 @@ | ||
// Copyright (c) xxxx, . | ||
|
||
// Package dpudev (DPU Device) is the main package of the application | ||
// Package utils is support functions of the application | ||
package utils | ||
|
||
import ( | ||
"log" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// ExtractPagination fetches pagination from the database, calculate size and offset | ||
func ExtractPagination(pageSize int32, pageToken string, pagination map[string]int) (size int, offset int, err error) { | ||
const ( | ||
maxPageSize = 250 | ||
defaultPageSize = 50 | ||
) | ||
switch { | ||
case pageSize < 0: | ||
return -1, -1, status.Error(codes.InvalidArgument, "negative PageSize is not allowed") | ||
case pageSize == 0: | ||
size = defaultPageSize | ||
case pageSize > maxPageSize: | ||
size = maxPageSize | ||
default: | ||
size = int(pageSize) | ||
} | ||
// fetch offset from the database using opaque token | ||
offset = 0 | ||
if pageToken != "" { | ||
var ok bool | ||
offset, ok = pagination[pageToken] | ||
if !ok { | ||
return -1, -1, status.Errorf(codes.NotFound, "unable to find pagination token %s", pageToken) | ||
} | ||
log.Printf("Found offset %d from pagination token: %s", offset, pageToken) | ||
} | ||
return size, offset, nil | ||
} |
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,13 @@ | ||
// Copyright (c) xxxx, . | ||
|
||
// Package utils is support functions of the application | ||
package utils | ||
|
||
import ( | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// ProtoClone creates a deep copy of a provided gRPC structure | ||
func ProtoClone[T proto.Message](protoStruct T) T { | ||
return proto.Clone(protoStruct).(T) | ||
} |