Documentation ¶
Overview ¶
Package x contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.
Index ¶
- Constants
- Variables
- func AddInit(f func())
- func AssertTrue(b bool)
- func AssertTruef(b bool, format string, args ...interface{})
- func Check(err error)
- func Check2(_ interface{}, err error)
- func Check2f(_ interface{}, err error, format string, args ...interface{})
- func Checkf(err error, format string, args ...interface{})
- func DataKey(attr string, uid uint64) []byte
- func Err(entry *logrus.Entry, err error) *logrus.Entry
- func Errorf(format string, args ...interface{}) error
- func Fatalf(format string, args ...interface{})
- func IndexKey(attr, term string) []byte
- func Init()
- func Log(p string) *logrus.Entry
- func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
- func Printf(format string, args ...interface{})
- func ReadLine(r *bufio.Reader, buf *bytes.Buffer) error
- func Reply(w http.ResponseWriter, rep interface{})
- func SetError(prev *error, n error)
- func SetStatus(w http.ResponseWriter, code, msg string)
- func Trace(ctx context.Context, format string, args ...interface{})
- func TraceError(ctx context.Context, err error)
- func Wrap(err error) error
- func Wrapf(err error, format string, args ...interface{}) error
- type ParsedKey
- type SafeMutex
- type SafeWait
- type Status
Constants ¶
const ( ErrorOk = "ErrorOk" ErrorInvalidMethod = "ErrorInvalidMethod" ErrorInvalidRequest = "ErrorInvalidRequest" ErrorMissingRequired = "ErrorMissingRequired" Error = "Error" ErrorNoData = "ErrorNoData" ErrorUptodate = "ErrorUptodate" ErrorNoPermission = "ErrorNoPermission" ErrorInvalidMutation = "ErrorInvalidMutation" )
Error constants representing different types of errors.
Variables ¶
var Nilbyte []byte
Functions ¶
func AddInit ¶ added in v0.4.4
func AddInit(f func())
AddInit adds a function to be run in x.Init, which should be called at the beginning of all mains.
func AssertTrue ¶ added in v0.7.0
func AssertTrue(b bool)
AssertTrue asserts that b is true. Otherwise, it would log fatal.
func AssertTruef ¶ added in v0.7.0
AssertTruef is AssertTrue with extra info.
func Check2 ¶ added in v0.7.0
func Check2(_ interface{}, err error)
Check2 acts as convenience wrapper around Check, using the 2nd argument as error.
func Check2f ¶ added in v0.7.0
Check2f acts as convenience wrapper around Checkf, using the 2nd argument as error.
func ParseRequest ¶
func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool
func Printf ¶ added in v0.7.0
func Printf(format string, args ...interface{})
Printf does a log.Printf. We often do printf for debugging but has to keep adding import "fmt" or "log" and removing them after we are done. Let's add Printf to "x" and include "x" almost everywhere. Caution: Do remember to call x.Init. For tests, you need a TestMain that calls x.Init.
func ReadLine ¶ added in v0.7.0
Reads a single line from a buffered reader. The line is read into the passed in buffer to minimize allocations. This is the preferred method for loading long lines which could be longer than the buffer size of bufio.Scanner.
func Reply ¶
func Reply(w http.ResponseWriter, rep interface{})
func SetStatus ¶
func SetStatus(w http.ResponseWriter, code, msg string)
SetStatus sets the error code, message and the newly assigned uids in the http response.
func TraceError ¶ added in v0.7.0
TraceError is like Trace but it logs just an error, which may have stacktrace.
Types ¶
type ParsedKey ¶ added in v0.7.0
type ParsedKey struct { Attr string Uid uint64 Term string // contains filtered or unexported fields }
func (ParsedKey) IndexPrefix ¶ added in v0.7.0
func (ParsedKey) SkipPredicate ¶ added in v0.7.0
func (ParsedKey) SkipRangeOfSameType ¶ added in v0.7.0
type SafeMutex ¶ added in v0.7.0
type SafeMutex struct {
// contains filtered or unexported fields
}
SafeLock can be used in place of sync.RWMutex
func (*SafeMutex) AssertLock ¶ added in v0.7.0
func (s *SafeMutex) AssertLock()
func (*SafeMutex) AssertRLock ¶ added in v0.7.0
func (s *SafeMutex) AssertRLock()