-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from sashahilton00/master
feat: add support for custom encoder/decoder implementations
- Loading branch information
Showing
5 changed files
with
209 additions
and
20 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 |
---|---|---|
@@ -1,6 +1,44 @@ | ||
package paginator | ||
|
||
import "github.com/pilagod/gorm-cursor-paginator/v2/cursor" | ||
import ( | ||
pc "github.com/pilagod/gorm-cursor-paginator/v2/cursor" | ||
) | ||
|
||
// Cursor re-exports cursor.Cursor | ||
type Cursor = cursor.Cursor | ||
type Cursor = pc.Cursor | ||
|
||
// CursorCodec encodes/decodes cursor | ||
type CursorCodec interface { | ||
// Encode encodes model fields into cursor | ||
Encode( | ||
fields []pc.EncoderField, | ||
model interface{}, | ||
) (string, error) | ||
|
||
// Decode decodes cursor into model fields | ||
Decode( | ||
fields []pc.DecoderField, | ||
cursor string, | ||
model interface{}, | ||
) ([]interface{}, error) | ||
} | ||
|
||
// JSONCursorCodec encodes/decodes cursor in JSON format | ||
type JSONCursorCodec struct{} | ||
|
||
// Encode encodes model fields into JSON format cursor | ||
func (*JSONCursorCodec) Encode( | ||
fields []pc.EncoderField, | ||
model interface{}, | ||
) (string, error) { | ||
return pc.NewEncoder(fields).Encode(model) | ||
} | ||
|
||
// Decode decodes JSON format cursor into model fields | ||
func (*JSONCursorCodec) Decode( | ||
fields []pc.DecoderField, | ||
cursor string, | ||
model interface{}, | ||
) ([]interface{}, error) { | ||
return pc.NewDecoder(fields).Decode(cursor, model) | ||
} |
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