本文整理汇总了Golang中datamodel.Info.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Info.ID方法的具体用法?Golang Info.ID怎么用?Golang Info.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datamodel.Info
的用法示例。
在下文中一共展示了Info.ID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: create
func (m *infoManager) create(info *datamodel.Info) error {
if _, ok := m.info[info.ID()]; ok {
return fmt.Errorf(`Sketch of type "%s" with name "%s" already exists`,
info.GetType(), info.GetName())
}
m.info[info.ID()] = info
return nil
}
示例2: create
// CreateSketch ...
func (m *sketchManager) create(info *datamodel.Info) error {
sketch, err := sketches.CreateSketch(info)
if err != nil {
return err
}
m.sketches[info.ID()] = sketch
return nil
}
示例3: CreateSketch
// CreateSketch ...
func (m *Manager) CreateSketch(info *datamodel.Info) error {
if !isValidType(info) {
return fmt.Errorf("Can not create sketch of type %s, invalid type.", info.Type)
}
if err := m.infos.create(info); err != nil {
return err
}
if err := m.sketches.create(info); err != nil {
// If error occurred during creation of sketch, delete info
if err2 := m.infos.delete(info.ID()); err2 != nil {
return fmt.Errorf("%q\n%q ", err, err2)
}
return err
}
return nil
}
示例4: LoadSketch
// LoadSketch ...
func LoadSketch(info *datamodel.Info, file *os.File) (*SketchProxy, error) {
var sketch datamodel.Sketcher
sp := &SketchProxy{info, sketch, sync.RWMutex{}}
size, err := utils.GetFileSize(file)
if err != nil {
return nil, err
}
data := make([]byte, size, size)
_, err = file.Read(data)
if err != nil {
return nil, fmt.Errorf("Error loading data for sketch: %s", info.ID())
}
switch datamodel.GetTypeString(info.GetType()) {
case datamodel.HLLPP:
sp.sketch = &HLLPPSketch{}
err = sp.sketch.Unmarshal(info, data)
case datamodel.CML:
sp.sketch = &CMLSketch{}
err = sp.sketch.Unmarshal(info, data)
case datamodel.TopK:
sp.sketch = &TopKSketch{}
err = sp.sketch.Unmarshal(info, data)
case datamodel.Bloom:
sp.sketch = &BloomSketch{}
err = sp.sketch.Unmarshal(info, data)
default:
return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType())
}
if err != nil {
return nil, err
}
return sp, nil
}