Skip to content

Commit

Permalink
Fix golint warnings in types package. (hypermodeinc#3452)
Browse files Browse the repository at this point in the history
Add comments to unexported methods, types, and variables.
  • Loading branch information
martinmr authored May 31, 2019
1 parent 4e68ac3 commit 1df5b31
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 18 deletions.
1 change: 1 addition & 0 deletions types/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions types/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions types/facets/facet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion types/facets/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions types/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions types/s2index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 26 additions & 10 deletions types/scalar_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand All @@ -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:
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion types/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1df5b31

Please sign in to comment.