diff --git a/types/compare.go b/types/compare.go index e60dc503bc3..c903bbb5c9f 100644 --- a/types/compare.go +++ b/types/compare.go @@ -18,6 +18,7 @@ package types import "github.com/dgraph-io/dgraph/x" +// CompareVals compares two values using the given comparison type. // Should be used only in filtering arg1 by comparing with arg2. // arg2 is reference Val to which arg1 is compared. func CompareVals(op string, arg1, arg2 Val) bool { diff --git a/types/conversion.go b/types/conversion.go index 42a1f3ef296..7429e0b2bf1 100644 --- a/types/conversion.go +++ b/types/conversion.go @@ -519,6 +519,7 @@ func cantConvert(from TypeID, to TypeID) error { return errors.Errorf("Cannot convert %s to type %s", from.Name(), to.Name()) } +// MarshalJSON makes Val satisfy the json.Marshaler interface. func (v Val) MarshalJSON() ([]byte, error) { switch v.Tid { case IntID: diff --git a/types/facets/facet_types.go b/types/facets/facet_types.go index 6850599e429..f0155e91228 100644 --- a/types/facets/facet_types.go +++ b/types/facets/facet_types.go @@ -19,13 +19,19 @@ package facets import "github.com/dgraph-io/dgo/protos/api" const ( - IntID = TypeID(api.Facet_INT) - FloatID = TypeID(api.Facet_FLOAT) - BoolID = TypeID(api.Facet_BOOL) + // IntID represents the integer type. + IntID = TypeID(api.Facet_INT) + // FloatID represents the floating-point number type. + FloatID = TypeID(api.Facet_FLOAT) + // BoolID represents the boolean type. + BoolID = TypeID(api.Facet_BOOL) + // DateTimeID represents the datetime type. DateTimeID = TypeID(api.Facet_DATETIME) - StringID = TypeID(api.Facet_STRING) + // StringID represents the string type. + StringID = TypeID(api.Facet_STRING) ) +// TypeID represents the type of a facet. type TypeID api.Facet_ValType // ValTypeForTypeID gives api.Facet_ValType for given TypeID diff --git a/types/facets/utils.go b/types/facets/utils.go index 712bfcc0224..e410f763d92 100644 --- a/types/facets/utils.go +++ b/types/facets/utils.go @@ -30,7 +30,7 @@ import ( "github.com/pkg/errors" ) -// Sorts And validates the facets. +// SortAndValidate sorts And validates the facets. func SortAndValidate(fs []*api.Facet) error { if len(fs) == 0 { return nil @@ -148,6 +148,7 @@ func FacetFor(key, val string) (*api.Facet, error) { return facet, err } +// ToBinary converts the given value into a binary value. func ToBinary(key string, value interface{}, sourceType api.Facet_ValType) ( *api.Facet, error) { // convert facet val interface{} to binary diff --git a/types/password.go b/types/password.go index 9233044896b..70978fbf3be 100644 --- a/types/password.go +++ b/types/password.go @@ -26,6 +26,7 @@ const ( pwdLenLimit = 6 ) +// Encrypt encrypts the given plain-text password. func Encrypt(plain string) (string, error) { if len(plain) < pwdLenLimit { return "", errors.Errorf("Password too short, i.e. should have at least 6 chars") @@ -39,6 +40,7 @@ func Encrypt(plain string) (string, error) { return string(encrypted), nil } +// VerifyPassword checks that the plain-text password matches the encrypted password. func VerifyPassword(plain, encrypted string) error { if len(plain) < pwdLenLimit || len(encrypted) == 0 { return errors.Errorf("Invalid password/crypted string") diff --git a/types/s2index.go b/types/s2index.go index 042729186f8..1105b3b9496 100644 --- a/types/s2index.go +++ b/types/s2index.go @@ -38,8 +38,8 @@ func parentCoverTokens(parents s2.CellUnion, cover s2.CellUnion) []string { return tokens } -// IndexTokens returns the tokens to be used in a geospatial index for the given geometry. If the -// geometry is not supported it returns an error. +// IndexGeoTokens returns the tokens to be used in a geospatial index for the +// given geometry. If the geometry is not supported it returns an error. func IndexGeoTokens(g geom.T) ([]string, error) { parents, cover, err := indexCells(g) if err != nil { diff --git a/types/scalar_types.go b/types/scalar_types.go index 38c7afaa5ee..5c75fbcc316 100644 --- a/types/scalar_types.go +++ b/types/scalar_types.go @@ -30,16 +30,27 @@ const nanoSecondsInSec = 1000000000 // data. When adding a new type *always* add to the end of this list. // Never delete anything from this list even if it becomes unused. const ( - DefaultID = TypeID(pb.Posting_DEFAULT) - BinaryID = TypeID(pb.Posting_BINARY) - IntID = TypeID(pb.Posting_INT) - FloatID = TypeID(pb.Posting_FLOAT) - BoolID = TypeID(pb.Posting_BOOL) - DateTimeID = TypeID(pb.Posting_DATETIME) - GeoID = TypeID(pb.Posting_GEO) - UidID = TypeID(pb.Posting_UID) - PasswordID = TypeID(pb.Posting_PASSWORD) - StringID = TypeID(pb.Posting_STRING) + // DefaultID represents the default type. + DefaultID = TypeID(pb.Posting_DEFAULT) + // BinaryID represents the binary data type. + BinaryID = TypeID(pb.Posting_BINARY) + // IntID represents the integer type. + IntID = TypeID(pb.Posting_INT) + // FloatID represents the floating-point number type. + FloatID = TypeID(pb.Posting_FLOAT) + // FloatID represents the boolean type. + BoolID = TypeID(pb.Posting_BOOL) + // DateTimeID represents the datetime type. + DateTimeID = TypeID(pb.Posting_DATETIME) + // GeoID represents the geo-location data type. + GeoID = TypeID(pb.Posting_GEO) + // UidID represents the uid type. + UidID = TypeID(pb.Posting_UID) + // PasswordID represents the password type. + PasswordID = TypeID(pb.Posting_PASSWORD) + // StringID represents the string type. + StringID = TypeID(pb.Posting_STRING) + // UndefinedID represents the undefined type. UndefinedID = TypeID(100) ) @@ -56,12 +67,15 @@ var typeNameMap = map[string]TypeID{ "password": PasswordID, } +// TypeID represents the type of the data. type TypeID pb.Posting_ValType +// Enum takes a TypeID value and returns the corresponding ValType enum value. func (t TypeID) Enum() pb.Posting_ValType { return pb.Posting_ValType(t) } +// Name returns the name of the type. func (t TypeID) Name() string { switch t { case DefaultID: @@ -115,10 +129,12 @@ func TypeForName(name string) (TypeID, bool) { return t, ok } +// IsScalar returns whether the type is a scalar type. func (t TypeID) IsScalar() bool { return t != UidID } +// IsNumber returns whether the type is a number type. func (t TypeID) IsNumber() bool { return t == IntID || t == FloatID } diff --git a/types/sort.go b/types/sort.go index 65eb5e1b899..6ed772fac4b 100644 --- a/types/sort.go +++ b/types/sort.go @@ -80,7 +80,8 @@ func (s byValue) Less(i, j int) bool { return false } -// Sort sorts the given array in-place. +// SortWithFacet sorts the given array in-place and considers the given facets to calculate +// the proper ordering. func SortWithFacet(v [][]Val, ul *pb.List, l []*pb.Facets, desc []bool) error { if len(v) == 0 || len(v[0]) == 0 { return nil