The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/registry/apis/dashboard/legacy/token.go

67 lines
1.7 KiB

package legacy
import (
"fmt"
"strconv"
"strings"
"github.com/grafana/grafana/pkg/util"
)
type continueToken struct {
orgId int64
id int64 // the internal id (sort by!)
folder string // from the query
bytes int64 // information, not a query
}
func readContinueToken(next string) (continueToken, error) {
var err error
token := continueToken{}
if next == "" {
return token, nil
}
parts := strings.Split(next, "/")
if len(parts) < 3 {
return token, fmt.Errorf("invalid continue token (too few parts)")
}
sub := strings.Split(parts[0], ":")
if sub[0] != "org" {
return token, fmt.Errorf("expected org in first slug")
}
token.orgId, err = strconv.ParseInt(sub[1], 10, 64)
if err != nil {
return token, fmt.Errorf("error parsing orgid")
}
sub = strings.Split(parts[1], ":")
if sub[0] != "start" {
return token, fmt.Errorf("expected internal ID in second slug")
}
token.id, err = strconv.ParseInt(sub[1], 10, 64)
if err != nil {
return token, fmt.Errorf("error parsing updated")
}
sub = strings.Split(parts[2], ":")
if sub[0] != "folder" {
return token, fmt.Errorf("expected folder UID in third slug")
}
token.folder = sub[1]
// // Check if the folder filter is the same from the previous query
// if q.Requirements.Folder == nil {
// if token.folder != "" {
// return token, fmt.Errorf("invalid token, the folder must match previous query")
// }
// } else if token.folder != *q.Requirements.Folder {
// return token, fmt.Errorf("invalid token, the folder must match previous query")
// }
return token, err
}
func (r *continueToken) String() string {
return fmt.Sprintf("org:%d/start:%d/folder:%s/%s",
r.orgId, r.id, r.folder, util.ByteCountSI(r.bytes))
}