mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 00:35:12 +08:00

* Add support for ASC ordering and introduce ResourceVersionMatch_Unset as default Add SortAscending to continue token and add integration test for pagination. * Change protobuf order * Make backwards compatible * Update pkg/storage/unified/sql/backend.go Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com> --------- Co-authored-by: Marco de Abreu <18629099+marcoabreu@users.noreply.github.com> Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
34 lines
638 B
Go
34 lines
638 B
Go
package resource
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type ContinueToken struct {
|
|
StartOffset int64 `json:"o"`
|
|
ResourceVersion int64 `json:"v"`
|
|
SortAscending bool `json:"s"`
|
|
}
|
|
|
|
func (c ContinueToken) String() string {
|
|
b, _ := json.Marshal(c)
|
|
return base64.StdEncoding.EncodeToString(b)
|
|
}
|
|
|
|
func GetContinueToken(token string) (*ContinueToken, error) {
|
|
continueVal, err := base64.StdEncoding.DecodeString(token)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decoding continue token")
|
|
}
|
|
|
|
t := &ContinueToken{}
|
|
err = json.Unmarshal(continueVal, t)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return t, nil
|
|
}
|