Skip to content

Commit

Permalink
Fix metalint
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Jan 1, 2019
1 parent ba96aca commit 2dd724a
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 284 deletions.
2 changes: 1 addition & 1 deletion document/doc_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type fullDocIDSet struct {
numTotalDocs int32
}

func (s *fullDocIDSet) NumDocuments() int32 { return int32(s.numTotalDocs) }
func (s *fullDocIDSet) NumDocuments() int32 { return s.numTotalDocs }

func (s *fullDocIDSet) Iter() DocIDSetIterator { return NewFullDocIDSetIterator(s.numTotalDocs) }

Expand Down
71 changes: 14 additions & 57 deletions event/field/field.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package field

import (
"fmt"

"github.com/xichen2020/eventdb/event/field"
)

// ValueType is the type of a field value.
type ValueType int

Expand Down Expand Up @@ -39,30 +33,33 @@ func (t ValueType) String() string {
}
}

// ConvertibleFrom returns a list of value types that can be converted into type `t`.
func (t ValueType) ConvertibleFrom() ([]ValueType, error) {
vts, exists := comparableTypeMap[t]
if exists {
return vts, nil
}
return nil, fmt.Errorf("unknown value type %v does not have comparable types", t)
}

// ValueTypeSet is a set of value types.
type ValueTypeSet map[field.ValueType]struct{}
type ValueTypeSet map[ValueType]struct{}

// Clone clones a value type set.
func (m ValueTypeSet) Clone() ValueTypeSet {
if len(m) == 0 {
return nil
}
cloned := make(field.ValueTypeSet, len(m))
cloned := make(ValueTypeSet, len(m))
for k := range m {
cloned[k] = struct{}{}
}
return cloned
}

var (
// OrderableTypes is a list of value types eligible for ordering.
OrderableTypes = ValueTypeSet{
NullType: struct{}{},
BoolType: struct{}{},
IntType: struct{}{},
DoubleType: struct{}{},
StringType: struct{}{},
TimeType: struct{}{},
}
)

// ValueUnion is a value union.
type ValueUnion struct {
Type ValueType
Expand All @@ -73,46 +70,6 @@ type ValueUnion struct {
TimeNanosVal int64
}

// ValueExtractionMode determines how to extract values from the value union.
type ValueExtractionMode int

// A list of supported value extraction modes.
const (
DontConvertTypes ValueExtractionMode = iota
ConvertTypes
)

// BoolValue attempts to extract a bool value from the union.
func (v *ValueUnion) BoolValue(mode ValueExtractionMode) (bool, error) {
if v.Type == BoolType {
return v.BoolVal, nil
}
if mode == DontConvertTypes {
return false, fmt.Errorf("unable to extract a bool value from the union %v", v)
}

}

var (
// OrderableTypes is a list of value types eligible for ordering.
OrderableTypes = []ValueType{
NullType,
BoolType,
IntType,
DoubleType,
StringType,
TimeType,
}
convertibleFromTypesMap = map[ValueType][]ValueType{
NullType: []ValueType{NullType},
BoolType: []ValueType{BoolType},
IntType: []ValueType{IntType, DoubleType},
DoubleType: []ValueType{IntType, DoubleType},
StringType: []ValueType{StringType},
TimeType: []ValueType{TimeType},
}
)

// Field is an event field.
type Field struct {
Path []string
Expand Down

0 comments on commit 2dd724a

Please sign in to comment.