2016-01-23 16:08:03 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Handle is used to store and access data in a backend.
|
|
|
|
type Handle struct {
|
|
|
|
Type Type
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Handle) String() string {
|
|
|
|
name := h.Name
|
|
|
|
if len(name) > 10 {
|
|
|
|
name = name[:10]
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("<%s/%s>", h.Type, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid returns an error if h is not valid.
|
|
|
|
func (h Handle) Valid() error {
|
|
|
|
if h.Type == "" {
|
|
|
|
return errors.New("type is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
switch h.Type {
|
|
|
|
case Data:
|
|
|
|
case Key:
|
|
|
|
case Lock:
|
|
|
|
case Snapshot:
|
|
|
|
case Index:
|
|
|
|
case Config:
|
|
|
|
default:
|
2016-01-24 15:59:38 +00:00
|
|
|
return fmt.Errorf("invalid Type %q", h.Type)
|
2016-01-23 16:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if h.Type == Config {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if h.Name == "" {
|
|
|
|
return errors.New("invalid Name")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|