x

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package x contains some very common utilities used by Dgraph. These utilities are of "miscellaneous" nature, e.g., error checking.

Index

Constants

View Source
const (
	ErrorOk              = "ErrorOk"
	ErrorUnauthorized    = "ErrorUnauthorized"
	ErrorInvalidMethod   = "ErrorInvalidMethod"
	ErrorInvalidRequest  = "ErrorInvalidRequest"
	ErrorMissingRequired = "ErrorMissingRequired"
	Error                = "Error"
	ErrorNoData          = "ErrorNoData"
	ErrorUptodate        = "ErrorUptodate"
	ErrorNoPermission    = "ErrorNoPermission"
	ErrorInvalidMutation = "ErrorInvalidMutation"
)

Error constants representing different types of errors.

Variables

View Source
var Nilbyte []byte

Functions

func AddInit

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

func AssertTrue(b bool)

AssertTrue asserts that b is true. Otherwise, it would log fatal.

func AssertTruef

func AssertTruef(b bool, format string, args ...interface{})

AssertTruef is AssertTrue with extra info.

func Check

func Check(err error)

Check logs fatal if err != nil.

func Check2

func Check2(_ interface{}, err error)

Check2 acts as convenience wrapper around Check, using the 2nd argument as error.

func Check2f

func Check2f(_ interface{}, err error, format string, args ...interface{})

Check2f acts as convenience wrapper around Checkf, using the 2nd argument as error.

func Checkf

func Checkf(err error, format string, args ...interface{})

Checkf is Check with extra info.

func DataKey

func DataKey(attr string, uid uint64) []byte

func Err

func Err(entry *logrus.Entry, err error) *logrus.Entry

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf creates a new error with stack trace, etc.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs fatal.

func IndexKey

func IndexKey(attr, term string) []byte

func Init

func Init()

Init initializes flags and run all functions in initFunc.

func Log

func Log(p string) *logrus.Entry

func ParseRequest

func ParseRequest(w http.ResponseWriter, r *http.Request, data interface{}) bool

func Printf

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

func ReadLine(r *bufio.Reader, buf *bytes.Buffer) error

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 SetError

func SetError(prev *error, n error)

SetError sets the error logged in this package.

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 Trace

func Trace(ctx context.Context, format string, args ...interface{})

func TraceError

func TraceError(ctx context.Context, err error)

TraceError is like Trace but it logs just an error, which may have stacktrace.

func Wrap

func Wrap(err error) error

Wrap wraps errors from external lib.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf is Wrap with extra info.

Types

type ParsedKey

type ParsedKey struct {
	Attr string
	Uid  uint64
	Term string
	// contains filtered or unexported fields
}

func Parse

func Parse(key []byte) *ParsedKey

func (ParsedKey) IndexPrefix

func (p ParsedKey) IndexPrefix() []byte

func (ParsedKey) IsData

func (p ParsedKey) IsData() bool

func (ParsedKey) IsIndex

func (p ParsedKey) IsIndex() bool

func (ParsedKey) SkipPredicate

func (p ParsedKey) SkipPredicate() []byte

func (ParsedKey) SkipRangeOfSameType

func (p ParsedKey) SkipRangeOfSameType() []byte

type SafeMutex

type SafeMutex struct {
	// contains filtered or unexported fields
}

SafeLock can be used in place of sync.RWMutex

func (*SafeMutex) AssertLock

func (s *SafeMutex) AssertLock()

func (*SafeMutex) AssertRLock

func (s *SafeMutex) AssertRLock()

func (*SafeMutex) Lock

func (s *SafeMutex) Lock()

func (*SafeMutex) RLock

func (s *SafeMutex) RLock()

func (*SafeMutex) RUnlock

func (s *SafeMutex) RUnlock()

func (*SafeMutex) StartWait

func (s *SafeMutex) StartWait() *SafeWait

func (*SafeMutex) Unlock

func (s *SafeMutex) Unlock()

func (*SafeMutex) Wait

func (s *SafeMutex) Wait()

type SafeWait

type SafeWait struct {
	// contains filtered or unexported fields
}

func (*SafeWait) Done

func (s *SafeWait) Done()

type Status

type Status struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL