id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
5,600
arangodb/go-driver
error.go
Error
func (ae ArangoError) Error() string { if ae.ErrorMessage != "" { return ae.ErrorMessage } return fmt.Sprintf("ArangoError: Code %d, ErrorNum %d", ae.Code, ae.ErrorNum) }
go
func (ae ArangoError) Error() string { if ae.ErrorMessage != "" { return ae.ErrorMessage } return fmt.Sprintf("ArangoError: Code %d, ErrorNum %d", ae.Code, ae.ErrorNum) }
[ "func", "(", "ae", "ArangoError", ")", "Error", "(", ")", "string", "{", "if", "ae", ".", "ErrorMessage", "!=", "\"", "\"", "{", "return", "ae", ".", "ErrorMessage", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ae", ".", "Code", ",", "ae", ".", "ErrorNum", ")", "\n", "}" ]
// Error returns the error message of an ArangoError.
[ "Error", "returns", "the", "error", "message", "of", "an", "ArangoError", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L43-L48
5,601
arangodb/go-driver
error.go
Timeout
func (ae ArangoError) Timeout() bool { return ae.HasError && (ae.Code == http.StatusRequestTimeout || ae.Code == http.StatusGatewayTimeout) }
go
func (ae ArangoError) Timeout() bool { return ae.HasError && (ae.Code == http.StatusRequestTimeout || ae.Code == http.StatusGatewayTimeout) }
[ "func", "(", "ae", "ArangoError", ")", "Timeout", "(", ")", "bool", "{", "return", "ae", ".", "HasError", "&&", "(", "ae", ".", "Code", "==", "http", ".", "StatusRequestTimeout", "||", "ae", ".", "Code", "==", "http", ".", "StatusGatewayTimeout", ")", "\n", "}" ]
// Timeout returns true when the given error is a timeout error.
[ "Timeout", "returns", "true", "when", "the", "given", "error", "is", "a", "timeout", "error", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L51-L53
5,602
arangodb/go-driver
error.go
Temporary
func (ae ArangoError) Temporary() bool { return ae.HasError && ae.Code == http.StatusServiceUnavailable }
go
func (ae ArangoError) Temporary() bool { return ae.HasError && ae.Code == http.StatusServiceUnavailable }
[ "func", "(", "ae", "ArangoError", ")", "Temporary", "(", ")", "bool", "{", "return", "ae", ".", "HasError", "&&", "ae", ".", "Code", "==", "http", ".", "StatusServiceUnavailable", "\n", "}" ]
// Temporary returns true when the given error is a temporary error.
[ "Temporary", "returns", "true", "when", "the", "given", "error", "is", "a", "temporary", "error", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L56-L58
5,603
arangodb/go-driver
error.go
newArangoError
func newArangoError(code, errorNum int, errorMessage string) error { return ArangoError{ HasError: true, Code: code, ErrorNum: errorNum, ErrorMessage: errorMessage, } }
go
func newArangoError(code, errorNum int, errorMessage string) error { return ArangoError{ HasError: true, Code: code, ErrorNum: errorNum, ErrorMessage: errorMessage, } }
[ "func", "newArangoError", "(", "code", ",", "errorNum", "int", ",", "errorMessage", "string", ")", "error", "{", "return", "ArangoError", "{", "HasError", ":", "true", ",", "Code", ":", "code", ",", "ErrorNum", ":", "errorNum", ",", "ErrorMessage", ":", "errorMessage", ",", "}", "\n", "}" ]
// newArangoError creates a new ArangoError with given values.
[ "newArangoError", "creates", "a", "new", "ArangoError", "with", "given", "values", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L61-L68
5,604
arangodb/go-driver
error.go
IsArangoError
func IsArangoError(err error) bool { ae, ok := Cause(err).(ArangoError) return ok && ae.HasError }
go
func IsArangoError(err error) bool { ae, ok := Cause(err).(ArangoError) return ok && ae.HasError }
[ "func", "IsArangoError", "(", "err", "error", ")", "bool", "{", "ae", ",", "ok", ":=", "Cause", "(", "err", ")", ".", "(", "ArangoError", ")", "\n", "return", "ok", "&&", "ae", ".", "HasError", "\n", "}" ]
// IsArangoError returns true when the given error is an ArangoError.
[ "IsArangoError", "returns", "true", "when", "the", "given", "error", "is", "an", "ArangoError", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L71-L74
5,605
arangodb/go-driver
error.go
IsArangoErrorWithCode
func IsArangoErrorWithCode(err error, code int) bool { ae, ok := Cause(err).(ArangoError) return ok && ae.Code == code }
go
func IsArangoErrorWithCode(err error, code int) bool { ae, ok := Cause(err).(ArangoError) return ok && ae.Code == code }
[ "func", "IsArangoErrorWithCode", "(", "err", "error", ",", "code", "int", ")", "bool", "{", "ae", ",", "ok", ":=", "Cause", "(", "err", ")", ".", "(", "ArangoError", ")", "\n", "return", "ok", "&&", "ae", ".", "Code", "==", "code", "\n", "}" ]
// IsArangoErrorWithCode returns true when the given error is an ArangoError and its Code field is equal to the given code.
[ "IsArangoErrorWithCode", "returns", "true", "when", "the", "given", "error", "is", "an", "ArangoError", "and", "its", "Code", "field", "is", "equal", "to", "the", "given", "code", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L77-L80
5,606
arangodb/go-driver
error.go
IsArangoErrorWithErrorNum
func IsArangoErrorWithErrorNum(err error, errorNum ...int) bool { ae, ok := Cause(err).(ArangoError) if !ok { return false } for _, x := range errorNum { if ae.ErrorNum == x { return true } } return false }
go
func IsArangoErrorWithErrorNum(err error, errorNum ...int) bool { ae, ok := Cause(err).(ArangoError) if !ok { return false } for _, x := range errorNum { if ae.ErrorNum == x { return true } } return false }
[ "func", "IsArangoErrorWithErrorNum", "(", "err", "error", ",", "errorNum", "...", "int", ")", "bool", "{", "ae", ",", "ok", ":=", "Cause", "(", "err", ")", ".", "(", "ArangoError", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "x", ":=", "range", "errorNum", "{", "if", "ae", ".", "ErrorNum", "==", "x", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsArangoErrorWithErrorNum returns true when the given error is an ArangoError and its ErrorNum field is equal to one of the given numbers.
[ "IsArangoErrorWithErrorNum", "returns", "true", "when", "the", "given", "error", "is", "an", "ArangoError", "and", "its", "ErrorNum", "field", "is", "equal", "to", "one", "of", "the", "given", "numbers", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L83-L94
5,607
arangodb/go-driver
error.go
IsNoLeaderOrOngoing
func IsNoLeaderOrOngoing(err error) bool { return IsArangoErrorWithCode(err, 503) && (IsArangoErrorWithErrorNum(err, 1495) || IsArangoErrorWithErrorNum(err, 1496)) }
go
func IsNoLeaderOrOngoing(err error) bool { return IsArangoErrorWithCode(err, 503) && (IsArangoErrorWithErrorNum(err, 1495) || IsArangoErrorWithErrorNum(err, 1496)) }
[ "func", "IsNoLeaderOrOngoing", "(", "err", "error", ")", "bool", "{", "return", "IsArangoErrorWithCode", "(", "err", ",", "503", ")", "&&", "(", "IsArangoErrorWithErrorNum", "(", "err", ",", "1495", ")", "||", "IsArangoErrorWithErrorNum", "(", "err", ",", "1496", ")", ")", "\n", "}" ]
// IsNoLeaderOrOngoing return true if the given error is an ArangoError with code 503 and error number 1496 or 1495
[ "IsNoLeaderOrOngoing", "return", "true", "if", "the", "given", "error", "is", "an", "ArangoError", "with", "code", "503", "and", "error", "number", "1496", "or", "1495" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L132-L134
5,608
arangodb/go-driver
error.go
IsInvalidArgument
func IsInvalidArgument(err error) bool { _, ok := Cause(err).(InvalidArgumentError) return ok }
go
func IsInvalidArgument(err error) bool { _, ok := Cause(err).(InvalidArgumentError) return ok }
[ "func", "IsInvalidArgument", "(", "err", "error", ")", "bool", "{", "_", ",", "ok", ":=", "Cause", "(", "err", ")", ".", "(", "InvalidArgumentError", ")", "\n", "return", "ok", "\n", "}" ]
// IsInvalidArgument returns true if the given error is an InvalidArgumentError.
[ "IsInvalidArgument", "returns", "true", "if", "the", "given", "error", "is", "an", "InvalidArgumentError", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L147-L150
5,609
arangodb/go-driver
error.go
IsNoMoreDocuments
func IsNoMoreDocuments(err error) bool { _, ok := Cause(err).(NoMoreDocumentsError) return ok }
go
func IsNoMoreDocuments(err error) bool { _, ok := Cause(err).(NoMoreDocumentsError) return ok }
[ "func", "IsNoMoreDocuments", "(", "err", "error", ")", "bool", "{", "_", ",", "ok", ":=", "Cause", "(", "err", ")", ".", "(", "NoMoreDocumentsError", ")", "\n", "return", "ok", "\n", "}" ]
// IsNoMoreDocuments returns true if the given error is an NoMoreDocumentsError.
[ "IsNoMoreDocuments", "returns", "true", "if", "the", "given", "error", "is", "an", "NoMoreDocumentsError", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L161-L164
5,610
arangodb/go-driver
error.go
IsCanceled
func IsCanceled(err error) bool { return isCausedBy(err, func(e error) bool { return e == context.Canceled }) }
go
func IsCanceled(err error) bool { return isCausedBy(err, func(e error) bool { return e == context.Canceled }) }
[ "func", "IsCanceled", "(", "err", "error", ")", "bool", "{", "return", "isCausedBy", "(", "err", ",", "func", "(", "e", "error", ")", "bool", "{", "return", "e", "==", "context", ".", "Canceled", "}", ")", "\n", "}" ]
// IsCanceled returns true if the given error is the result on a cancelled context.
[ "IsCanceled", "returns", "true", "if", "the", "given", "error", "is", "the", "result", "on", "a", "cancelled", "context", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L183-L185
5,611
arangodb/go-driver
error.go
IsTimeout
func IsTimeout(err error) bool { return isCausedBy(err, func(e error) bool { return e == context.DeadlineExceeded }) }
go
func IsTimeout(err error) bool { return isCausedBy(err, func(e error) bool { return e == context.DeadlineExceeded }) }
[ "func", "IsTimeout", "(", "err", "error", ")", "bool", "{", "return", "isCausedBy", "(", "err", ",", "func", "(", "e", "error", ")", "bool", "{", "return", "e", "==", "context", ".", "DeadlineExceeded", "}", ")", "\n", "}" ]
// IsTimeout returns true if the given error is the result on a deadline that has been exceeded.
[ "IsTimeout", "returns", "true", "if", "the", "given", "error", "is", "the", "result", "on", "a", "deadline", "that", "has", "been", "exceeded", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L188-L190
5,612
arangodb/go-driver
error.go
isCausedBy
func isCausedBy(err error, p func(error) bool) bool { if p(err) { return true } err = Cause(err) for { if p(err) { return true } else if err == nil { return false } if xerr, ok := err.(*ResponseError); ok { err = xerr.Err } else if xerr, ok := err.(*url.Error); ok { err = xerr.Err } else if xerr, ok := err.(*net.OpError); ok { err = xerr.Err } else if xerr, ok := err.(*os.SyscallError); ok { err = xerr.Err } else { return false } } }
go
func isCausedBy(err error, p func(error) bool) bool { if p(err) { return true } err = Cause(err) for { if p(err) { return true } else if err == nil { return false } if xerr, ok := err.(*ResponseError); ok { err = xerr.Err } else if xerr, ok := err.(*url.Error); ok { err = xerr.Err } else if xerr, ok := err.(*net.OpError); ok { err = xerr.Err } else if xerr, ok := err.(*os.SyscallError); ok { err = xerr.Err } else { return false } } }
[ "func", "isCausedBy", "(", "err", "error", ",", "p", "func", "(", "error", ")", "bool", ")", "bool", "{", "if", "p", "(", "err", ")", "{", "return", "true", "\n", "}", "\n", "err", "=", "Cause", "(", "err", ")", "\n", "for", "{", "if", "p", "(", "err", ")", "{", "return", "true", "\n", "}", "else", "if", "err", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "xerr", ",", "ok", ":=", "err", ".", "(", "*", "ResponseError", ")", ";", "ok", "{", "err", "=", "xerr", ".", "Err", "\n", "}", "else", "if", "xerr", ",", "ok", ":=", "err", ".", "(", "*", "url", ".", "Error", ")", ";", "ok", "{", "err", "=", "xerr", ".", "Err", "\n", "}", "else", "if", "xerr", ",", "ok", ":=", "err", ".", "(", "*", "net", ".", "OpError", ")", ";", "ok", "{", "err", "=", "xerr", ".", "Err", "\n", "}", "else", "if", "xerr", ",", "ok", ":=", "err", ".", "(", "*", "os", ".", "SyscallError", ")", ";", "ok", "{", "err", "=", "xerr", ".", "Err", "\n", "}", "else", "{", "return", "false", "\n", "}", "\n", "}", "\n", "}" ]
// isCausedBy returns true if the given error returns true on the given predicate, // unwrapping various standard library error wrappers.
[ "isCausedBy", "returns", "true", "if", "the", "given", "error", "returns", "true", "on", "the", "given", "predicate", "unwrapping", "various", "standard", "library", "error", "wrappers", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L194-L217
5,613
arangodb/go-driver
error.go
FirstNonNil
func (l ErrorSlice) FirstNonNil() error { for _, e := range l { if e != nil { return e } } return nil }
go
func (l ErrorSlice) FirstNonNil() error { for _, e := range l { if e != nil { return e } } return nil }
[ "func", "(", "l", "ErrorSlice", ")", "FirstNonNil", "(", ")", "error", "{", "for", "_", ",", "e", ":=", "range", "l", "{", "if", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// FirstNonNil returns the first error in the slice that is not nil. // If all errors in the slice are nil, nil is returned.
[ "FirstNonNil", "returns", "the", "first", "error", "in", "the", "slice", "that", "is", "not", "nil", ".", "If", "all", "errors", "in", "the", "slice", "are", "nil", "nil", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/error.go#L234-L241
5,614
arangodb/go-driver
vst/protocol/connection.go
dial
func dial(version Version, addr string, tlsConfig *tls.Config) (*Connection, error) { // Create TCP connection conn, err := net.Dial("tcp", addr) if err != nil { return nil, driver.WithStack(err) } // Configure connection if tcpConn, ok := conn.(*net.TCPConn); ok { tcpConn.SetKeepAlive(true) tcpConn.SetNoDelay(true) } // Add TLS if needed if tlsConfig != nil { tlsConn := tls.Client(conn, tlsConfig) conn = tlsConn } // Send protocol header switch version { case Version1_0: if _, err := conn.Write(vstProtocolHeader1_0); err != nil { return nil, driver.WithStack(err) } case Version1_1: if _, err := conn.Write(vstProtocolHeader1_1); err != nil { return nil, driver.WithStack(err) } default: return nil, driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(version))) } // prepare connection c := &Connection{ version: version, maxChunkSize: defaultMaxChunkSize, conn: conn, } c.updateLastActivity() // Start reading responses go c.readChunkLoop() return c, nil }
go
func dial(version Version, addr string, tlsConfig *tls.Config) (*Connection, error) { // Create TCP connection conn, err := net.Dial("tcp", addr) if err != nil { return nil, driver.WithStack(err) } // Configure connection if tcpConn, ok := conn.(*net.TCPConn); ok { tcpConn.SetKeepAlive(true) tcpConn.SetNoDelay(true) } // Add TLS if needed if tlsConfig != nil { tlsConn := tls.Client(conn, tlsConfig) conn = tlsConn } // Send protocol header switch version { case Version1_0: if _, err := conn.Write(vstProtocolHeader1_0); err != nil { return nil, driver.WithStack(err) } case Version1_1: if _, err := conn.Write(vstProtocolHeader1_1); err != nil { return nil, driver.WithStack(err) } default: return nil, driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(version))) } // prepare connection c := &Connection{ version: version, maxChunkSize: defaultMaxChunkSize, conn: conn, } c.updateLastActivity() // Start reading responses go c.readChunkLoop() return c, nil }
[ "func", "dial", "(", "version", "Version", ",", "addr", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ")", "(", "*", "Connection", ",", "error", ")", "{", "// Create TCP connection", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Configure connection", "if", "tcpConn", ",", "ok", ":=", "conn", ".", "(", "*", "net", ".", "TCPConn", ")", ";", "ok", "{", "tcpConn", ".", "SetKeepAlive", "(", "true", ")", "\n", "tcpConn", ".", "SetNoDelay", "(", "true", ")", "\n", "}", "\n\n", "// Add TLS if needed", "if", "tlsConfig", "!=", "nil", "{", "tlsConn", ":=", "tls", ".", "Client", "(", "conn", ",", "tlsConfig", ")", "\n", "conn", "=", "tlsConn", "\n", "}", "\n\n", "// Send protocol header", "switch", "version", "{", "case", "Version1_0", ":", "if", "_", ",", "err", ":=", "conn", ".", "Write", "(", "vstProtocolHeader1_0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "case", "Version1_1", ":", "if", "_", ",", "err", ":=", "conn", ".", "Write", "(", "vstProtocolHeader1_1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "default", ":", "return", "nil", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "int", "(", "version", ")", ")", ")", "\n", "}", "\n\n", "// prepare connection", "c", ":=", "&", "Connection", "{", "version", ":", "version", ",", "maxChunkSize", ":", "defaultMaxChunkSize", ",", "conn", ":", "conn", ",", "}", "\n", "c", ".", "updateLastActivity", "(", ")", "\n\n", "// Start reading responses", "go", "c", ".", "readChunkLoop", "(", ")", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// dial opens a new connection to the server on the given address.
[ "dial", "opens", "a", "new", "connection", "to", "the", "server", "on", "the", "given", "address", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L62-L107
5,615
arangodb/go-driver
vst/protocol/connection.go
Close
func (c *Connection) Close() error { if atomic.CompareAndSwapInt32(&c.closing, 0, 1) { if err := c.conn.Close(); err != nil { return driver.WithStack(err) } c.msgStore.ForEach(func(m *Message) { m.closeResponseChan() }) } return nil }
go
func (c *Connection) Close() error { if atomic.CompareAndSwapInt32(&c.closing, 0, 1) { if err := c.conn.Close(); err != nil { return driver.WithStack(err) } c.msgStore.ForEach(func(m *Message) { m.closeResponseChan() }) } return nil }
[ "func", "(", "c", "*", "Connection", ")", "Close", "(", ")", "error", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "c", ".", "closing", ",", "0", ",", "1", ")", "{", "if", "err", ":=", "c", ".", "conn", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "c", ".", "msgStore", ".", "ForEach", "(", "func", "(", "m", "*", "Message", ")", "{", "m", ".", "closeResponseChan", "(", ")", "\n", "}", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close the connection to the server
[ "Close", "the", "connection", "to", "the", "server" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L116-L126
5,616
arangodb/go-driver
vst/protocol/connection.go
sendChunk
func (c *Connection) sendChunk(deadline time.Time, chunk chunk) error { c.writeMutex.Lock() defer c.writeMutex.Unlock() c.conn.SetWriteDeadline(deadline) var err error switch c.version { case Version1_0: _, err = chunk.WriteToVST1_0(c.conn) case Version1_1: _, err = chunk.WriteToVST1_1(c.conn) default: err = driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(c.version))) } c.updateLastActivity() if err != nil { return driver.WithStack(err) } return nil }
go
func (c *Connection) sendChunk(deadline time.Time, chunk chunk) error { c.writeMutex.Lock() defer c.writeMutex.Unlock() c.conn.SetWriteDeadline(deadline) var err error switch c.version { case Version1_0: _, err = chunk.WriteToVST1_0(c.conn) case Version1_1: _, err = chunk.WriteToVST1_1(c.conn) default: err = driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(c.version))) } c.updateLastActivity() if err != nil { return driver.WithStack(err) } return nil }
[ "func", "(", "c", "*", "Connection", ")", "sendChunk", "(", "deadline", "time", ".", "Time", ",", "chunk", "chunk", ")", "error", "{", "c", ".", "writeMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "writeMutex", ".", "Unlock", "(", ")", "\n\n", "c", ".", "conn", ".", "SetWriteDeadline", "(", "deadline", ")", "\n", "var", "err", "error", "\n", "switch", "c", ".", "version", "{", "case", "Version1_0", ":", "_", ",", "err", "=", "chunk", ".", "WriteToVST1_0", "(", "c", ".", "conn", ")", "\n", "case", "Version1_1", ":", "_", ",", "err", "=", "chunk", ".", "WriteToVST1_1", "(", "c", ".", "conn", ")", "\n", "default", ":", "err", "=", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "int", "(", "c", ".", "version", ")", ")", ")", "\n", "}", "\n", "c", ".", "updateLastActivity", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// sendChunk sends a single chunk to the server.
[ "sendChunk", "sends", "a", "single", "chunk", "to", "the", "server", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L189-L208
5,617
arangodb/go-driver
vst/protocol/connection.go
readChunkLoop
func (c *Connection) readChunkLoop() { recentErrors := 0 goodChunks := 0 for { if c.IsClosed() { // Closing, we're done return } var chunk chunk var err error switch c.version { case Version1_0: chunk, err = readChunkVST1_0(c.conn) case Version1_1: chunk, err = readChunkVST1_1(c.conn) default: err = driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(c.version))) } c.updateLastActivity() if err != nil { if !c.IsClosed() { // Handle error if driver.Cause(err) == io.EOF { // Connection closed c.Close() } else { recentErrors++ fmt.Printf("readChunkLoop error: %#v (goodChunks=%d)\n", err, goodChunks) if recentErrors > maxRecentErrors { // When we get to many errors in a row, close this connection c.Close() } else { // Backoff a bit, so we allow things to settle. time.Sleep(time.Millisecond * time.Duration(recentErrors*5)) } } } } else { // Process chunk recentErrors = 0 goodChunks++ go c.processChunk(chunk) } } }
go
func (c *Connection) readChunkLoop() { recentErrors := 0 goodChunks := 0 for { if c.IsClosed() { // Closing, we're done return } var chunk chunk var err error switch c.version { case Version1_0: chunk, err = readChunkVST1_0(c.conn) case Version1_1: chunk, err = readChunkVST1_1(c.conn) default: err = driver.WithStack(fmt.Errorf("Unknown protocol version %d", int(c.version))) } c.updateLastActivity() if err != nil { if !c.IsClosed() { // Handle error if driver.Cause(err) == io.EOF { // Connection closed c.Close() } else { recentErrors++ fmt.Printf("readChunkLoop error: %#v (goodChunks=%d)\n", err, goodChunks) if recentErrors > maxRecentErrors { // When we get to many errors in a row, close this connection c.Close() } else { // Backoff a bit, so we allow things to settle. time.Sleep(time.Millisecond * time.Duration(recentErrors*5)) } } } } else { // Process chunk recentErrors = 0 goodChunks++ go c.processChunk(chunk) } } }
[ "func", "(", "c", "*", "Connection", ")", "readChunkLoop", "(", ")", "{", "recentErrors", ":=", "0", "\n", "goodChunks", ":=", "0", "\n", "for", "{", "if", "c", ".", "IsClosed", "(", ")", "{", "// Closing, we're done", "return", "\n", "}", "\n", "var", "chunk", "chunk", "\n", "var", "err", "error", "\n", "switch", "c", ".", "version", "{", "case", "Version1_0", ":", "chunk", ",", "err", "=", "readChunkVST1_0", "(", "c", ".", "conn", ")", "\n", "case", "Version1_1", ":", "chunk", ",", "err", "=", "readChunkVST1_1", "(", "c", ".", "conn", ")", "\n", "default", ":", "err", "=", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "int", "(", "c", ".", "version", ")", ")", ")", "\n", "}", "\n", "c", ".", "updateLastActivity", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "c", ".", "IsClosed", "(", ")", "{", "// Handle error", "if", "driver", ".", "Cause", "(", "err", ")", "==", "io", ".", "EOF", "{", "// Connection closed", "c", ".", "Close", "(", ")", "\n", "}", "else", "{", "recentErrors", "++", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ",", "goodChunks", ")", "\n", "if", "recentErrors", ">", "maxRecentErrors", "{", "// When we get to many errors in a row, close this connection", "c", ".", "Close", "(", ")", "\n", "}", "else", "{", "// Backoff a bit, so we allow things to settle.", "time", ".", "Sleep", "(", "time", ".", "Millisecond", "*", "time", ".", "Duration", "(", "recentErrors", "*", "5", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "else", "{", "// Process chunk", "recentErrors", "=", "0", "\n", "goodChunks", "++", "\n", "go", "c", ".", "processChunk", "(", "chunk", ")", "\n", "}", "\n", "}", "\n", "}" ]
// readChunkLoop reads chunks from the connection until it is closed.
[ "readChunkLoop", "reads", "chunks", "from", "the", "connection", "until", "it", "is", "closed", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L211-L255
5,618
arangodb/go-driver
vst/protocol/connection.go
processChunk
func (c *Connection) processChunk(chunk chunk) { m := c.msgStore.Get(chunk.MessageID) if m == nil { // Unexpected chunk, ignore it return } // Add chunk to message m.addChunk(chunk) // Try to assembly if m.assemble() { // Message is complete // Remove message from store c.msgStore.Remove(m.ID) //fmt.Println("Chunk: " + hex.EncodeToString(chunk.Data) + "\nMessage: " + hex.EncodeToString(m.Data)) // Notify listener m.notifyListener() } }
go
func (c *Connection) processChunk(chunk chunk) { m := c.msgStore.Get(chunk.MessageID) if m == nil { // Unexpected chunk, ignore it return } // Add chunk to message m.addChunk(chunk) // Try to assembly if m.assemble() { // Message is complete // Remove message from store c.msgStore.Remove(m.ID) //fmt.Println("Chunk: " + hex.EncodeToString(chunk.Data) + "\nMessage: " + hex.EncodeToString(m.Data)) // Notify listener m.notifyListener() } }
[ "func", "(", "c", "*", "Connection", ")", "processChunk", "(", "chunk", "chunk", ")", "{", "m", ":=", "c", ".", "msgStore", ".", "Get", "(", "chunk", ".", "MessageID", ")", "\n", "if", "m", "==", "nil", "{", "// Unexpected chunk, ignore it", "return", "\n", "}", "\n\n", "// Add chunk to message", "m", ".", "addChunk", "(", "chunk", ")", "\n\n", "// Try to assembly", "if", "m", ".", "assemble", "(", ")", "{", "// Message is complete", "// Remove message from store", "c", ".", "msgStore", ".", "Remove", "(", "m", ".", "ID", ")", "\n\n", "//fmt.Println(\"Chunk: \" + hex.EncodeToString(chunk.Data) + \"\\nMessage: \" + hex.EncodeToString(m.Data))", "// Notify listener", "m", ".", "notifyListener", "(", ")", "\n", "}", "\n", "}" ]
// processChunk adds the given chunk to its message and notifies the listener // when the message is complete.
[ "processChunk", "adds", "the", "given", "chunk", "to", "its", "message", "and", "notifies", "the", "listener", "when", "the", "message", "is", "complete", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L259-L280
5,619
arangodb/go-driver
vst/protocol/connection.go
IsIdle
func (c *Connection) IsIdle(idleTimeout time.Duration) bool { return time.Since(c.lastActivity) > idleTimeout && c.msgStore.Size() == 0 }
go
func (c *Connection) IsIdle(idleTimeout time.Duration) bool { return time.Since(c.lastActivity) > idleTimeout && c.msgStore.Size() == 0 }
[ "func", "(", "c", "*", "Connection", ")", "IsIdle", "(", "idleTimeout", "time", ".", "Duration", ")", "bool", "{", "return", "time", ".", "Since", "(", "c", ".", "lastActivity", ")", ">", "idleTimeout", "&&", "c", ".", "msgStore", ".", "Size", "(", ")", "==", "0", "\n", "}" ]
// IsIdle returns true when the last activity was more than the given timeout ago.
[ "IsIdle", "returns", "true", "when", "the", "last", "activity", "was", "more", "than", "the", "given", "timeout", "ago", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/connection.go#L288-L290
5,620
arangodb/go-driver
index_impl.go
indexStringToType
func indexStringToType(indexTypeString string) (IndexType, error) { switch indexTypeString { case string(FullTextIndex): return FullTextIndex, nil case string(HashIndex): return HashIndex, nil case string(SkipListIndex): return SkipListIndex, nil case string(PrimaryIndex): return PrimaryIndex, nil case string(PersistentIndex): return PersistentIndex, nil case string(GeoIndex), "geo1", "geo2": return GeoIndex, nil case string(EdgeIndex): return EdgeIndex, nil default: return "", WithStack(InvalidArgumentError{Message: "unknown index type"}) } }
go
func indexStringToType(indexTypeString string) (IndexType, error) { switch indexTypeString { case string(FullTextIndex): return FullTextIndex, nil case string(HashIndex): return HashIndex, nil case string(SkipListIndex): return SkipListIndex, nil case string(PrimaryIndex): return PrimaryIndex, nil case string(PersistentIndex): return PersistentIndex, nil case string(GeoIndex), "geo1", "geo2": return GeoIndex, nil case string(EdgeIndex): return EdgeIndex, nil default: return "", WithStack(InvalidArgumentError{Message: "unknown index type"}) } }
[ "func", "indexStringToType", "(", "indexTypeString", "string", ")", "(", "IndexType", ",", "error", ")", "{", "switch", "indexTypeString", "{", "case", "string", "(", "FullTextIndex", ")", ":", "return", "FullTextIndex", ",", "nil", "\n", "case", "string", "(", "HashIndex", ")", ":", "return", "HashIndex", ",", "nil", "\n", "case", "string", "(", "SkipListIndex", ")", ":", "return", "SkipListIndex", ",", "nil", "\n", "case", "string", "(", "PrimaryIndex", ")", ":", "return", "PrimaryIndex", ",", "nil", "\n", "case", "string", "(", "PersistentIndex", ")", ":", "return", "PersistentIndex", ",", "nil", "\n", "case", "string", "(", "GeoIndex", ")", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "GeoIndex", ",", "nil", "\n", "case", "string", "(", "EdgeIndex", ")", ":", "return", "EdgeIndex", ",", "nil", "\n\n", "default", ":", "return", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "}" ]
// indexStringToType converts a string representation of an index to IndexType
[ "indexStringToType", "converts", "a", "string", "representation", "of", "an", "index", "to", "IndexType" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/index_impl.go#L32-L52
5,621
arangodb/go-driver
index_impl.go
newIndex
func newIndex(id string, indexTypeString string, col *collection) (Index, error) { if id == "" { return nil, WithStack(InvalidArgumentError{Message: "id is empty"}) } parts := strings.Split(id, "/") if len(parts) != 2 { return nil, WithStack(InvalidArgumentError{Message: "id must be `collection/name`"}) } if col == nil { return nil, WithStack(InvalidArgumentError{Message: "col is nil"}) } indexType, err := indexStringToType(indexTypeString) if err != nil { return nil, WithStack(err) } return &index{ id: id, indexType: indexType, col: col, db: col.db, conn: col.conn, }, nil }
go
func newIndex(id string, indexTypeString string, col *collection) (Index, error) { if id == "" { return nil, WithStack(InvalidArgumentError{Message: "id is empty"}) } parts := strings.Split(id, "/") if len(parts) != 2 { return nil, WithStack(InvalidArgumentError{Message: "id must be `collection/name`"}) } if col == nil { return nil, WithStack(InvalidArgumentError{Message: "col is nil"}) } indexType, err := indexStringToType(indexTypeString) if err != nil { return nil, WithStack(err) } return &index{ id: id, indexType: indexType, col: col, db: col.db, conn: col.conn, }, nil }
[ "func", "newIndex", "(", "id", "string", ",", "indexTypeString", "string", ",", "col", "*", "collection", ")", "(", "Index", ",", "error", ")", "{", "if", "id", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "parts", ":=", "strings", ".", "Split", "(", "id", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "col", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "indexType", ",", "err", ":=", "indexStringToType", "(", "indexTypeString", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "&", "index", "{", "id", ":", "id", ",", "indexType", ":", "indexType", ",", "col", ":", "col", ",", "db", ":", "col", ".", "db", ",", "conn", ":", "col", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newIndex creates a new Index implementation.
[ "newIndex", "creates", "a", "new", "Index", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/index_impl.go#L55-L77
5,622
arangodb/go-driver
index_impl.go
Name
func (i *index) Name() string { parts := strings.Split(i.id, "/") return parts[1] }
go
func (i *index) Name() string { parts := strings.Split(i.id, "/") return parts[1] }
[ "func", "(", "i", "*", "index", ")", "Name", "(", ")", "string", "{", "parts", ":=", "strings", ".", "Split", "(", "i", ".", "id", ",", "\"", "\"", ")", "\n", "return", "parts", "[", "1", "]", "\n", "}" ]
// Name returns the name of the index.
[ "Name", "returns", "the", "name", "of", "the", "index", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/index_impl.go#L93-L96
5,623
arangodb/go-driver
index_impl.go
Remove
func (i *index) Remove(ctx context.Context) error { req, err := i.conn.NewRequest("DELETE", path.Join(i.relPath(), i.id)) if err != nil { return WithStack(err) } resp, err := i.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (i *index) Remove(ctx context.Context) error { req, err := i.conn.NewRequest("DELETE", path.Join(i.relPath(), i.id)) if err != nil { return WithStack(err) } resp, err := i.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "i", "*", "index", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "i", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "i", ".", "relPath", "(", ")", ",", "i", ".", "id", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "i", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Remove removes the entire index. // If the index does not exist, a NotFoundError is returned.
[ "Remove", "removes", "the", "entire", "index", ".", "If", "the", "index", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/index_impl.go#L105-L118
5,624
arangodb/go-driver
agency/lock.go
NewLock
func NewLock(log Logger, api Agency, key []string, id string, ttl time.Duration) (Lock, error) { if ttl < minLockTTL { ttl = minLockTTL } if id == "" { randBytes := make([]byte, 16) rand.Read(randBytes) id = hex.EncodeToString(randBytes) } return &lock{ log: log, api: api, key: key, id: id, ttl: ttl, }, nil }
go
func NewLock(log Logger, api Agency, key []string, id string, ttl time.Duration) (Lock, error) { if ttl < minLockTTL { ttl = minLockTTL } if id == "" { randBytes := make([]byte, 16) rand.Read(randBytes) id = hex.EncodeToString(randBytes) } return &lock{ log: log, api: api, key: key, id: id, ttl: ttl, }, nil }
[ "func", "NewLock", "(", "log", "Logger", ",", "api", "Agency", ",", "key", "[", "]", "string", ",", "id", "string", ",", "ttl", "time", ".", "Duration", ")", "(", "Lock", ",", "error", ")", "{", "if", "ttl", "<", "minLockTTL", "{", "ttl", "=", "minLockTTL", "\n", "}", "\n", "if", "id", "==", "\"", "\"", "{", "randBytes", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n", "rand", ".", "Read", "(", "randBytes", ")", "\n", "id", "=", "hex", ".", "EncodeToString", "(", "randBytes", ")", "\n", "}", "\n", "return", "&", "lock", "{", "log", ":", "log", ",", "api", ":", "api", ",", "key", ":", "key", ",", "id", ":", "id", ",", "ttl", ":", "ttl", ",", "}", ",", "nil", "\n", "}" ]
// NewLock creates a new lock on the given key.
[ "NewLock", "creates", "a", "new", "lock", "on", "the", "given", "key", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/lock.go#L61-L77
5,625
arangodb/go-driver
agency/lock.go
Lock
func (l *lock) Lock(ctx context.Context) error { l.mutex.Lock() defer l.mutex.Unlock() if l.locked { return driver.WithStack(AlreadyLockedError) } // Try to claim lock ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.WriteKeyIfEmpty(ctx, l.key, l.id, l.ttl); err != nil { if driver.IsPreconditionFailed(err) { return driver.WithStack(AlreadyLockedError) } return driver.WithStack(err) } // Success l.locked = true // Keep renewing renewCtx, renewCancel := context.WithCancel(context.Background()) go l.renewLock(renewCtx) l.cancelRenewal = renewCancel return nil }
go
func (l *lock) Lock(ctx context.Context) error { l.mutex.Lock() defer l.mutex.Unlock() if l.locked { return driver.WithStack(AlreadyLockedError) } // Try to claim lock ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.WriteKeyIfEmpty(ctx, l.key, l.id, l.ttl); err != nil { if driver.IsPreconditionFailed(err) { return driver.WithStack(AlreadyLockedError) } return driver.WithStack(err) } // Success l.locked = true // Keep renewing renewCtx, renewCancel := context.WithCancel(context.Background()) go l.renewLock(renewCtx) l.cancelRenewal = renewCancel return nil }
[ "func", "(", "l", "*", "lock", ")", "Lock", "(", "ctx", "context", ".", "Context", ")", "error", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "l", ".", "locked", "{", "return", "driver", ".", "WithStack", "(", "AlreadyLockedError", ")", "\n", "}", "\n\n", "// Try to claim lock", "ctx", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "time", ".", "Second", "*", "10", ")", "\n", "defer", "cancel", "(", ")", "\n", "if", "err", ":=", "l", ".", "api", ".", "WriteKeyIfEmpty", "(", "ctx", ",", "l", ".", "key", ",", "l", ".", "id", ",", "l", ".", "ttl", ")", ";", "err", "!=", "nil", "{", "if", "driver", ".", "IsPreconditionFailed", "(", "err", ")", "{", "return", "driver", ".", "WithStack", "(", "AlreadyLockedError", ")", "\n", "}", "\n", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Success", "l", ".", "locked", "=", "true", "\n\n", "// Keep renewing", "renewCtx", ",", "renewCancel", ":=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n", "go", "l", ".", "renewLock", "(", "renewCtx", ")", "\n", "l", ".", "cancelRenewal", "=", "renewCancel", "\n\n", "return", "nil", "\n", "}" ]
// Lock tries to lock the lock. // If it is not possible to lock, an error is returned. // If the lock is already held by me, an error is returned.
[ "Lock", "tries", "to", "lock", "the", "lock", ".", "If", "it", "is", "not", "possible", "to", "lock", "an", "error", "is", "returned", ".", "If", "the", "lock", "is", "already", "held", "by", "me", "an", "error", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/lock.go#L93-L120
5,626
arangodb/go-driver
agency/lock.go
Unlock
func (l *lock) Unlock(ctx context.Context) error { l.mutex.Lock() defer l.mutex.Unlock() if !l.locked { return driver.WithStack(NotLockedError) } // Release the lock ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.RemoveKeyIfEqualTo(ctx, l.key, l.id); err != nil { return driver.WithStack(err) } // Cleanup l.locked = false if l.cancelRenewal != nil { l.cancelRenewal() l.cancelRenewal = nil } return nil }
go
func (l *lock) Unlock(ctx context.Context) error { l.mutex.Lock() defer l.mutex.Unlock() if !l.locked { return driver.WithStack(NotLockedError) } // Release the lock ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.RemoveKeyIfEqualTo(ctx, l.key, l.id); err != nil { return driver.WithStack(err) } // Cleanup l.locked = false if l.cancelRenewal != nil { l.cancelRenewal() l.cancelRenewal = nil } return nil }
[ "func", "(", "l", "*", "lock", ")", "Unlock", "(", "ctx", "context", ".", "Context", ")", "error", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "!", "l", ".", "locked", "{", "return", "driver", ".", "WithStack", "(", "NotLockedError", ")", "\n", "}", "\n\n", "// Release the lock", "ctx", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "time", ".", "Second", "*", "10", ")", "\n", "defer", "cancel", "(", ")", "\n", "if", "err", ":=", "l", ".", "api", ".", "RemoveKeyIfEqualTo", "(", "ctx", ",", "l", ".", "key", ",", "l", ".", "id", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Cleanup", "l", ".", "locked", "=", "false", "\n", "if", "l", ".", "cancelRenewal", "!=", "nil", "{", "l", ".", "cancelRenewal", "(", ")", "\n", "l", ".", "cancelRenewal", "=", "nil", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Unlock tries to unlock the lock. // If it is not possible to unlock, an error is returned. // If the lock is not held by me, an error is returned.
[ "Unlock", "tries", "to", "unlock", "the", "lock", ".", "If", "it", "is", "not", "possible", "to", "unlock", "an", "error", "is", "returned", ".", "If", "the", "lock", "is", "not", "held", "by", "me", "an", "error", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/lock.go#L125-L148
5,627
arangodb/go-driver
agency/lock.go
IsLocked
func (l *lock) IsLocked() bool { l.mutex.Lock() defer l.mutex.Unlock() return l.locked }
go
func (l *lock) IsLocked() bool { l.mutex.Lock() defer l.mutex.Unlock() return l.locked }
[ "func", "(", "l", "*", "lock", ")", "IsLocked", "(", ")", "bool", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "l", ".", "locked", "\n", "}" ]
// IsLocked return true if the lock is held by me.
[ "IsLocked", "return", "true", "if", "the", "lock", "is", "held", "by", "me", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/lock.go#L151-L155
5,628
arangodb/go-driver
agency/lock.go
renewLock
func (l *lock) renewLock(ctx context.Context) { // op performs a renewal once. // returns stop, error op := func() (bool, error) { l.mutex.Lock() defer l.mutex.Unlock() if !l.locked { return true, driver.WithStack(NotLockedError) } // Update key in agency ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.WriteKeyIfEqualTo(ctx, l.key, l.id, l.id, l.ttl); err != nil { if driver.IsPreconditionFailed(err) { // We're not longer the leader l.locked = false l.cancelRenewal = nil return true, driver.WithStack(err) } return false, driver.WithStack(err) } return false, nil } for { delay := l.ttl / 2 stop, err := op() if stop || driver.Cause(err) == context.Canceled { return } if err != nil { if l.log != nil { l.log.Errorf("Failed to renew lock %s. %v", l.key, err) } delay = time.Second } select { case <-ctx.Done(): // we're done return case <-time.After(delay): // Try to renew } } }
go
func (l *lock) renewLock(ctx context.Context) { // op performs a renewal once. // returns stop, error op := func() (bool, error) { l.mutex.Lock() defer l.mutex.Unlock() if !l.locked { return true, driver.WithStack(NotLockedError) } // Update key in agency ctx, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() if err := l.api.WriteKeyIfEqualTo(ctx, l.key, l.id, l.id, l.ttl); err != nil { if driver.IsPreconditionFailed(err) { // We're not longer the leader l.locked = false l.cancelRenewal = nil return true, driver.WithStack(err) } return false, driver.WithStack(err) } return false, nil } for { delay := l.ttl / 2 stop, err := op() if stop || driver.Cause(err) == context.Canceled { return } if err != nil { if l.log != nil { l.log.Errorf("Failed to renew lock %s. %v", l.key, err) } delay = time.Second } select { case <-ctx.Done(): // we're done return case <-time.After(delay): // Try to renew } } }
[ "func", "(", "l", "*", "lock", ")", "renewLock", "(", "ctx", "context", ".", "Context", ")", "{", "// op performs a renewal once.", "// returns stop, error", "op", ":=", "func", "(", ")", "(", "bool", ",", "error", ")", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "!", "l", ".", "locked", "{", "return", "true", ",", "driver", ".", "WithStack", "(", "NotLockedError", ")", "\n", "}", "\n\n", "// Update key in agency", "ctx", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "time", ".", "Second", "*", "10", ")", "\n", "defer", "cancel", "(", ")", "\n", "if", "err", ":=", "l", ".", "api", ".", "WriteKeyIfEqualTo", "(", "ctx", ",", "l", ".", "key", ",", "l", ".", "id", ",", "l", ".", "id", ",", "l", ".", "ttl", ")", ";", "err", "!=", "nil", "{", "if", "driver", ".", "IsPreconditionFailed", "(", "err", ")", "{", "// We're not longer the leader", "l", ".", "locked", "=", "false", "\n", "l", ".", "cancelRenewal", "=", "nil", "\n", "return", "true", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "false", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}", "\n", "for", "{", "delay", ":=", "l", ".", "ttl", "/", "2", "\n", "stop", ",", "err", ":=", "op", "(", ")", "\n", "if", "stop", "||", "driver", ".", "Cause", "(", "err", ")", "==", "context", ".", "Canceled", "{", "return", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "if", "l", ".", "log", "!=", "nil", "{", "l", ".", "log", ".", "Errorf", "(", "\"", "\"", ",", "l", ".", "key", ",", "err", ")", "\n", "}", "\n", "delay", "=", "time", ".", "Second", "\n", "}", "\n\n", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "// we're done", "return", "\n", "case", "<-", "time", ".", "After", "(", "delay", ")", ":", "// Try to renew", "}", "\n", "}", "\n", "}" ]
// renewLock keeps renewing the lock until the given context is canceled.
[ "renewLock", "keeps", "renewing", "the", "lock", "until", "the", "given", "context", "is", "canceled", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/lock.go#L158-L204
5,629
arangodb/go-driver
client_users_impl.go
User
func (c *client) User(ctx context.Context, name string) (User, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_api/user", escapedName)) if err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } u, err := newUser(data, c.conn) if err != nil { return nil, WithStack(err) } return u, nil }
go
func (c *client) User(ctx context.Context, name string) (User, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_api/user", escapedName)) if err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } u, err := newUser(data, c.conn) if err != nil { return nil, WithStack(err) } return u, nil }
[ "func", "(", "c", "*", "client", ")", "User", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "User", ",", "error", ")", "{", "escapedName", ":=", "pathEscape", "(", "name", ")", "\n", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "escapedName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "userData", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "u", ",", "err", ":=", "newUser", "(", "data", ",", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "u", ",", "nil", "\n", "}" ]
// User opens a connection to an existing user. // If no user with given name exists, an NotFoundError is returned.
[ "User", "opens", "a", "connection", "to", "an", "existing", "user", ".", "If", "no", "user", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_users_impl.go#L32-L54
5,630
arangodb/go-driver
client_users_impl.go
UserExists
func (c *client) UserExists(ctx context.Context, name string) (bool, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_api", "user", escapedName)) if err != nil { return false, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return false, WithStack(err) } if err := resp.CheckStatus(200); err == nil { return true, nil } else if IsNotFound(err) { return false, nil } else { return false, WithStack(err) } }
go
func (c *client) UserExists(ctx context.Context, name string) (bool, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_api", "user", escapedName)) if err != nil { return false, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return false, WithStack(err) } if err := resp.CheckStatus(200); err == nil { return true, nil } else if IsNotFound(err) { return false, nil } else { return false, WithStack(err) } }
[ "func", "(", "c", "*", "client", ")", "UserExists", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "escapedName", ":=", "pathEscape", "(", "name", ")", "\n", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "\"", "\"", ",", "escapedName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "==", "nil", "{", "return", "true", ",", "nil", "\n", "}", "else", "if", "IsNotFound", "(", "err", ")", "{", "return", "false", ",", "nil", "\n", "}", "else", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "}" ]
// UserExists returns true if a database with given name exists.
[ "UserExists", "returns", "true", "if", "a", "database", "with", "given", "name", "exists", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_users_impl.go#L57-L74
5,631
arangodb/go-driver
client_users_impl.go
Users
func (c *client) Users(ctx context.Context) ([]User, error) { req, err := c.conn.NewRequest("GET", "/_api/user") if err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listUsersResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]User, 0, len(data.Result)) for _, userData := range data.Result { u, err := newUser(userData, c.conn) if err != nil { return nil, WithStack(err) } result = append(result, u) } return result, nil }
go
func (c *client) Users(ctx context.Context) ([]User, error) { req, err := c.conn.NewRequest("GET", "/_api/user") if err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listUsersResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]User, 0, len(data.Result)) for _, userData := range data.Result { u, err := newUser(userData, c.conn) if err != nil { return nil, WithStack(err) } result = append(result, u) } return result, nil }
[ "func", "(", "c", "*", "client", ")", "Users", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "User", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "listUsersResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "User", ",", "0", ",", "len", "(", "data", ".", "Result", ")", ")", "\n", "for", "_", ",", "userData", ":=", "range", "data", ".", "Result", "{", "u", ",", "err", ":=", "newUser", "(", "userData", ",", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "u", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Users returns a list of all users found by the client.
[ "Users", "returns", "a", "list", "of", "all", "users", "found", "by", "the", "client", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_users_impl.go#L81-L106
5,632
arangodb/go-driver
client_users_impl.go
CreateUser
func (c *client) CreateUser(ctx context.Context, name string, options *UserOptions) (User, error) { input := struct { UserOptions Name string `json:"user"` }{ Name: name, } if options != nil { input.UserOptions = *options } req, err := c.conn.NewRequest("POST", path.Join("_api/user")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } u, err := newUser(data, c.conn) if err != nil { return nil, WithStack(err) } return u, nil }
go
func (c *client) CreateUser(ctx context.Context, name string, options *UserOptions) (User, error) { input := struct { UserOptions Name string `json:"user"` }{ Name: name, } if options != nil { input.UserOptions = *options } req, err := c.conn.NewRequest("POST", path.Join("_api/user")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } u, err := newUser(data, c.conn) if err != nil { return nil, WithStack(err) } return u, nil }
[ "func", "(", "c", "*", "client", ")", "CreateUser", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "options", "*", "UserOptions", ")", "(", "User", ",", "error", ")", "{", "input", ":=", "struct", "{", "UserOptions", "\n", "Name", "string", "`json:\"user\"`", "\n", "}", "{", "Name", ":", "name", ",", "}", "\n", "if", "options", "!=", "nil", "{", "input", ".", "UserOptions", "=", "*", "options", "\n", "}", "\n", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "201", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "userData", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "u", ",", "err", ":=", "newUser", "(", "data", ",", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "u", ",", "nil", "\n", "}" ]
// CreateUser creates a new user with given name and opens a connection to it. // If a user with given name already exists, a DuplicateError is returned.
[ "CreateUser", "creates", "a", "new", "user", "with", "given", "name", "and", "opens", "a", "connection", "to", "it", ".", "If", "a", "user", "with", "given", "name", "already", "exists", "a", "DuplicateError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_users_impl.go#L110-L143
5,633
arangodb/go-driver
edge_collection_impl.go
newEdgeCollection
func newEdgeCollection(name string, g *graph) (Collection, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if g == nil { return nil, WithStack(InvalidArgumentError{Message: "g is nil"}) } return &edgeCollection{ name: name, g: g, conn: g.db.conn, }, nil }
go
func newEdgeCollection(name string, g *graph) (Collection, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if g == nil { return nil, WithStack(InvalidArgumentError{Message: "g is nil"}) } return &edgeCollection{ name: name, g: g, conn: g.db.conn, }, nil }
[ "func", "newEdgeCollection", "(", "name", "string", ",", "g", "*", "graph", ")", "(", "Collection", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "g", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "edgeCollection", "{", "name", ":", "name", ",", "g", ":", "g", ",", "conn", ":", "g", ".", "db", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newEdgeCollection creates a new EdgeCollection implementation.
[ "newEdgeCollection", "creates", "a", "new", "EdgeCollection", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_impl.go#L31-L43
5,634
arangodb/go-driver
edge_collection_impl.go
rawCollection
func (c *edgeCollection) rawCollection() Collection { result, _ := newCollection(c.name, c.g.db) return result }
go
func (c *edgeCollection) rawCollection() Collection { result, _ := newCollection(c.name, c.g.db) return result }
[ "func", "(", "c", "*", "edgeCollection", ")", "rawCollection", "(", ")", "Collection", "{", "result", ",", "_", ":=", "newCollection", "(", "c", ".", "name", ",", "c", ".", "g", ".", "db", ")", "\n", "return", "result", "\n", "}" ]
// rawCollection returns a standard document implementation of Collection // for this edge collection.
[ "rawCollection", "returns", "a", "standard", "document", "implementation", "of", "Collection", "for", "this", "edge", "collection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_impl.go#L69-L72
5,635
arangodb/go-driver
edge_collection_impl.go
Statistics
func (c *edgeCollection) Statistics(ctx context.Context) (CollectionStatistics, error) { result, err := c.rawCollection().Statistics(ctx) if err != nil { return CollectionStatistics{}, WithStack(err) } return result, nil }
go
func (c *edgeCollection) Statistics(ctx context.Context) (CollectionStatistics, error) { result, err := c.rawCollection().Statistics(ctx) if err != nil { return CollectionStatistics{}, WithStack(err) } return result, nil }
[ "func", "(", "c", "*", "edgeCollection", ")", "Statistics", "(", "ctx", "context", ".", "Context", ")", "(", "CollectionStatistics", ",", "error", ")", "{", "result", ",", "err", ":=", "c", ".", "rawCollection", "(", ")", ".", "Statistics", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "CollectionStatistics", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Statistics returns the number of documents and additional statistical information about the collection.
[ "Statistics", "returns", "the", "number", "of", "documents", "and", "additional", "statistical", "information", "about", "the", "collection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_impl.go#L93-L99
5,636
arangodb/go-driver
vst/request.go
SetBody
func (r *vstRequest) SetBody(body ...interface{}) (driver.Request, error) { switch len(body) { case 0: return r, driver.WithStack(fmt.Errorf("Must provide at least 1 body")) case 1: if data, err := velocypack.Marshal(body[0]); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil default: slices := make([]velocypack.Slice, len(body)) for i, b := range body { var err error slices[i], err = velocypack.Marshal(b) if err != nil { return r, driver.WithStack(err) } } merged, err := velocypack.Merge(slices...) if err != nil { return r, driver.WithStack(err) } r.body = merged return r, nil } }
go
func (r *vstRequest) SetBody(body ...interface{}) (driver.Request, error) { switch len(body) { case 0: return r, driver.WithStack(fmt.Errorf("Must provide at least 1 body")) case 1: if data, err := velocypack.Marshal(body[0]); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil default: slices := make([]velocypack.Slice, len(body)) for i, b := range body { var err error slices[i], err = velocypack.Marshal(b) if err != nil { return r, driver.WithStack(err) } } merged, err := velocypack.Merge(slices...) if err != nil { return r, driver.WithStack(err) } r.body = merged return r, nil } }
[ "func", "(", "r", "*", "vstRequest", ")", "SetBody", "(", "body", "...", "interface", "{", "}", ")", "(", "driver", ".", "Request", ",", "error", ")", "{", "switch", "len", "(", "body", ")", "{", "case", "0", ":", "return", "r", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "case", "1", ":", "if", "data", ",", "err", ":=", "velocypack", ".", "Marshal", "(", "body", "[", "0", "]", ")", ";", "err", "!=", "nil", "{", "return", "r", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "r", ".", "body", "=", "data", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "default", ":", "slices", ":=", "make", "(", "[", "]", "velocypack", ".", "Slice", ",", "len", "(", "body", ")", ")", "\n", "for", "i", ",", "b", ":=", "range", "body", "{", "var", "err", "error", "\n", "slices", "[", "i", "]", ",", "err", "=", "velocypack", ".", "Marshal", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "r", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "merged", ",", "err", ":=", "velocypack", ".", "Merge", "(", "slices", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "r", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "r", ".", "body", "=", "merged", "\n", "return", "r", ",", "nil", "\n", "}", "\n", "}" ]
// SetBody sets the content of the request. // The protocol of the connection determines what kinds of marshalling is taking place. // When multiple bodies are given, they are merged, with fields in the first document prevailing.
[ "SetBody", "sets", "the", "content", "of", "the", "request", ".", "The", "protocol", "of", "the", "connection", "determines", "what", "kinds", "of", "marshalling", "is", "taking", "place", ".", "When", "multiple", "bodies", "are", "given", "they", "are", "merged", "with", "fields", "in", "the", "first", "document", "prevailing", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/request.go#L87-L114
5,637
arangodb/go-driver
vst/request.go
requestType
func (r *vstRequest) requestType() int64 { switch r.method { case "DELETE": return 0 case "GET": return 1 case "POST": return 2 case "PUT": return 3 case "HEAD": return 4 case "PATCH": return 5 case "OPTIONS": return 6 default: panic(fmt.Errorf("Unknown method '%s'", r.method)) } }
go
func (r *vstRequest) requestType() int64 { switch r.method { case "DELETE": return 0 case "GET": return 1 case "POST": return 2 case "PUT": return 3 case "HEAD": return 4 case "PATCH": return 5 case "OPTIONS": return 6 default: panic(fmt.Errorf("Unknown method '%s'", r.method)) } }
[ "func", "(", "r", "*", "vstRequest", ")", "requestType", "(", ")", "int64", "{", "switch", "r", ".", "method", "{", "case", "\"", "\"", ":", "return", "0", "\n", "case", "\"", "\"", ":", "return", "1", "\n", "case", "\"", "\"", ":", "return", "2", "\n", "case", "\"", "\"", ":", "return", "3", "\n", "case", "\"", "\"", ":", "return", "4", "\n", "case", "\"", "\"", ":", "return", "5", "\n", "case", "\"", "\"", ":", "return", "6", "\n", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "method", ")", ")", "\n", "}", "\n", "}" ]
// requestType converts method to request type.
[ "requestType", "converts", "method", "to", "request", "type", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/request.go#L285-L304
5,638
arangodb/go-driver
cursor_impl.go
newCursor
func newCursor(data cursorData, endpoint string, db *database, allowDirtyReads bool) (Cursor, error) { if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &cursor{ cursorData: data, endpoint: endpoint, db: db, conn: db.conn, allowDirtyReads: allowDirtyReads, }, nil }
go
func newCursor(data cursorData, endpoint string, db *database, allowDirtyReads bool) (Cursor, error) { if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &cursor{ cursorData: data, endpoint: endpoint, db: db, conn: db.conn, allowDirtyReads: allowDirtyReads, }, nil }
[ "func", "newCursor", "(", "data", "cursorData", ",", "endpoint", "string", ",", "db", "*", "database", ",", "allowDirtyReads", "bool", ")", "(", "Cursor", ",", "error", ")", "{", "if", "db", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "cursor", "{", "cursorData", ":", "data", ",", "endpoint", ":", "endpoint", ",", "db", ":", "db", ",", "conn", ":", "db", ".", "conn", ",", "allowDirtyReads", ":", "allowDirtyReads", ",", "}", ",", "nil", "\n", "}" ]
// newCursor creates a new Cursor implementation.
[ "newCursor", "creates", "a", "new", "Cursor", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cursor_impl.go#L36-L47
5,639
arangodb/go-driver
cursor_impl.go
HasMore
func (c *cursor) HasMore() bool { return c.resultIndex < len(c.Result) || c.cursorData.HasMore }
go
func (c *cursor) HasMore() bool { return c.resultIndex < len(c.Result) || c.cursorData.HasMore }
[ "func", "(", "c", "*", "cursor", ")", "HasMore", "(", ")", "bool", "{", "return", "c", ".", "resultIndex", "<", "len", "(", "c", ".", "Result", ")", "||", "c", ".", "cursorData", ".", "HasMore", "\n", "}" ]
// Name returns the name of the collection.
[ "Name", "returns", "the", "name", "of", "the", "collection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cursor_impl.go#L94-L96
5,640
arangodb/go-driver
cursor_impl.go
Close
func (c *cursor) Close() error { if c == nil { // Avoid panics in the case that someone defer's a close before checking that the cursor is not nil. return nil } if c := atomic.LoadInt32(&c.closed); c != 0 { return nil } c.closeMutex.Lock() defer c.closeMutex.Unlock() if c.closed == 0 { if c.cursorData.ID != "" { // Force use of initial endpoint ctx := WithEndpoint(nil, c.endpoint) req, err := c.conn.NewRequest("DELETE", path.Join(c.relPath(), c.cursorData.ID)) if err != nil { return WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } } atomic.StoreInt32(&c.closed, 1) } return nil }
go
func (c *cursor) Close() error { if c == nil { // Avoid panics in the case that someone defer's a close before checking that the cursor is not nil. return nil } if c := atomic.LoadInt32(&c.closed); c != 0 { return nil } c.closeMutex.Lock() defer c.closeMutex.Unlock() if c.closed == 0 { if c.cursorData.ID != "" { // Force use of initial endpoint ctx := WithEndpoint(nil, c.endpoint) req, err := c.conn.NewRequest("DELETE", path.Join(c.relPath(), c.cursorData.ID)) if err != nil { return WithStack(err) } resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } } atomic.StoreInt32(&c.closed, 1) } return nil }
[ "func", "(", "c", "*", "cursor", ")", "Close", "(", ")", "error", "{", "if", "c", "==", "nil", "{", "// Avoid panics in the case that someone defer's a close before checking that the cursor is not nil.", "return", "nil", "\n", "}", "\n", "if", "c", ":=", "atomic", ".", "LoadInt32", "(", "&", "c", ".", "closed", ")", ";", "c", "!=", "0", "{", "return", "nil", "\n", "}", "\n", "c", ".", "closeMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "closeMutex", ".", "Unlock", "(", ")", "\n", "if", "c", ".", "closed", "==", "0", "{", "if", "c", ".", "cursorData", ".", "ID", "!=", "\"", "\"", "{", "// Force use of initial endpoint", "ctx", ":=", "WithEndpoint", "(", "nil", ",", "c", ".", "endpoint", ")", "\n\n", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "c", ".", "relPath", "(", ")", ",", "c", ".", "cursorData", ".", "ID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "atomic", ".", "StoreInt32", "(", "&", "c", ".", "closed", ",", "1", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close deletes the cursor and frees the resources associated with it.
[ "Close", "deletes", "the", "cursor", "and", "frees", "the", "resources", "associated", "with", "it", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cursor_impl.go#L106-L136
5,641
arangodb/go-driver
cursor_impl.go
ReadDocument
func (c *cursor) ReadDocument(ctx context.Context, result interface{}) (DocumentMeta, error) { // Force use of initial endpoint ctx = WithEndpoint(ctx, c.endpoint) if c.resultIndex >= len(c.Result) && c.cursorData.HasMore { // This is required since we are interested if this was a dirty read // but we do not want to trash the users bool reference. var wasDirtyRead bool fetchctx := ctx if c.allowDirtyReads { fetchctx = WithAllowDirtyReads(ctx, &wasDirtyRead) } // Fetch next batch req, err := c.conn.NewRequest("PUT", path.Join(c.relPath(), c.cursorData.ID)) if err != nil { return DocumentMeta{}, WithStack(err) } cs := applyContextSettings(fetchctx, req) resp, err := c.conn.Do(fetchctx, req) if err != nil { return DocumentMeta{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return DocumentMeta{}, WithStack(err) } loadContextResponseValues(cs, resp) var data cursorData if err := resp.ParseBody("", &data); err != nil { return DocumentMeta{}, WithStack(err) } c.cursorData = data c.resultIndex = 0 c.lastReadWasDirty = wasDirtyRead } // ReadDocument should act as if it would actually do a read // hence update the bool reference if c.allowDirtyReads { setDirtyReadFlagIfRequired(ctx, c.lastReadWasDirty) } index := c.resultIndex if index >= len(c.Result) { // Out of data return DocumentMeta{}, WithStack(NoMoreDocumentsError{}) } c.resultIndex++ var meta DocumentMeta resultPtr := c.Result[index] if resultPtr == nil { // Got NULL result rv := reflect.ValueOf(result) if rv.Kind() != reflect.Ptr || rv.IsNil() { return DocumentMeta{}, WithStack(&json.InvalidUnmarshalError{Type: reflect.TypeOf(result)}) } e := rv.Elem() e.Set(reflect.Zero(e.Type())) } else { if err := c.conn.Unmarshal(*resultPtr, &meta); err != nil { // If a cursor returns something other than a document, this will fail. // Just ignore it. } if err := c.conn.Unmarshal(*resultPtr, result); err != nil { return DocumentMeta{}, WithStack(err) } } return meta, nil }
go
func (c *cursor) ReadDocument(ctx context.Context, result interface{}) (DocumentMeta, error) { // Force use of initial endpoint ctx = WithEndpoint(ctx, c.endpoint) if c.resultIndex >= len(c.Result) && c.cursorData.HasMore { // This is required since we are interested if this was a dirty read // but we do not want to trash the users bool reference. var wasDirtyRead bool fetchctx := ctx if c.allowDirtyReads { fetchctx = WithAllowDirtyReads(ctx, &wasDirtyRead) } // Fetch next batch req, err := c.conn.NewRequest("PUT", path.Join(c.relPath(), c.cursorData.ID)) if err != nil { return DocumentMeta{}, WithStack(err) } cs := applyContextSettings(fetchctx, req) resp, err := c.conn.Do(fetchctx, req) if err != nil { return DocumentMeta{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return DocumentMeta{}, WithStack(err) } loadContextResponseValues(cs, resp) var data cursorData if err := resp.ParseBody("", &data); err != nil { return DocumentMeta{}, WithStack(err) } c.cursorData = data c.resultIndex = 0 c.lastReadWasDirty = wasDirtyRead } // ReadDocument should act as if it would actually do a read // hence update the bool reference if c.allowDirtyReads { setDirtyReadFlagIfRequired(ctx, c.lastReadWasDirty) } index := c.resultIndex if index >= len(c.Result) { // Out of data return DocumentMeta{}, WithStack(NoMoreDocumentsError{}) } c.resultIndex++ var meta DocumentMeta resultPtr := c.Result[index] if resultPtr == nil { // Got NULL result rv := reflect.ValueOf(result) if rv.Kind() != reflect.Ptr || rv.IsNil() { return DocumentMeta{}, WithStack(&json.InvalidUnmarshalError{Type: reflect.TypeOf(result)}) } e := rv.Elem() e.Set(reflect.Zero(e.Type())) } else { if err := c.conn.Unmarshal(*resultPtr, &meta); err != nil { // If a cursor returns something other than a document, this will fail. // Just ignore it. } if err := c.conn.Unmarshal(*resultPtr, result); err != nil { return DocumentMeta{}, WithStack(err) } } return meta, nil }
[ "func", "(", "c", "*", "cursor", ")", "ReadDocument", "(", "ctx", "context", ".", "Context", ",", "result", "interface", "{", "}", ")", "(", "DocumentMeta", ",", "error", ")", "{", "// Force use of initial endpoint", "ctx", "=", "WithEndpoint", "(", "ctx", ",", "c", ".", "endpoint", ")", "\n\n", "if", "c", ".", "resultIndex", ">=", "len", "(", "c", ".", "Result", ")", "&&", "c", ".", "cursorData", ".", "HasMore", "{", "// This is required since we are interested if this was a dirty read", "// but we do not want to trash the users bool reference.", "var", "wasDirtyRead", "bool", "\n", "fetchctx", ":=", "ctx", "\n", "if", "c", ".", "allowDirtyReads", "{", "fetchctx", "=", "WithAllowDirtyReads", "(", "ctx", ",", "&", "wasDirtyRead", ")", "\n", "}", "\n\n", "// Fetch next batch", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "c", ".", "relPath", "(", ")", ",", "c", ".", "cursorData", ".", "ID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "cs", ":=", "applyContextSettings", "(", "fetchctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "fetchctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "loadContextResponseValues", "(", "cs", ",", "resp", ")", "\n", "var", "data", "cursorData", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "c", ".", "cursorData", "=", "data", "\n", "c", ".", "resultIndex", "=", "0", "\n", "c", ".", "lastReadWasDirty", "=", "wasDirtyRead", "\n", "}", "\n", "// ReadDocument should act as if it would actually do a read", "// hence update the bool reference", "if", "c", ".", "allowDirtyReads", "{", "setDirtyReadFlagIfRequired", "(", "ctx", ",", "c", ".", "lastReadWasDirty", ")", "\n", "}", "\n\n", "index", ":=", "c", ".", "resultIndex", "\n", "if", "index", ">=", "len", "(", "c", ".", "Result", ")", "{", "// Out of data", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "NoMoreDocumentsError", "{", "}", ")", "\n", "}", "\n", "c", ".", "resultIndex", "++", "\n", "var", "meta", "DocumentMeta", "\n", "resultPtr", ":=", "c", ".", "Result", "[", "index", "]", "\n", "if", "resultPtr", "==", "nil", "{", "// Got NULL result", "rv", ":=", "reflect", ".", "ValueOf", "(", "result", ")", "\n", "if", "rv", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "rv", ".", "IsNil", "(", ")", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "&", "json", ".", "InvalidUnmarshalError", "{", "Type", ":", "reflect", ".", "TypeOf", "(", "result", ")", "}", ")", "\n", "}", "\n", "e", ":=", "rv", ".", "Elem", "(", ")", "\n", "e", ".", "Set", "(", "reflect", ".", "Zero", "(", "e", ".", "Type", "(", ")", ")", ")", "\n", "}", "else", "{", "if", "err", ":=", "c", ".", "conn", ".", "Unmarshal", "(", "*", "resultPtr", ",", "&", "meta", ")", ";", "err", "!=", "nil", "{", "// If a cursor returns something other than a document, this will fail.", "// Just ignore it.", "}", "\n", "if", "err", ":=", "c", ".", "conn", ".", "Unmarshal", "(", "*", "resultPtr", ",", "result", ")", ";", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "meta", ",", "nil", "\n", "}" ]
// ReadDocument reads the next document from the cursor. // The document data is stored into result, the document meta data is returned. // If the cursor has no more documents, a NoMoreDocuments error is returned.
[ "ReadDocument", "reads", "the", "next", "document", "from", "the", "cursor", ".", "The", "document", "data", "is", "stored", "into", "result", "the", "document", "meta", "data", "is", "returned", ".", "If", "the", "cursor", "has", "no", "more", "documents", "a", "NoMoreDocuments", "error", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cursor_impl.go#L141-L208
5,642
arangodb/go-driver
http/request_json.go
SetQuery
func (r *httpJSONRequest) SetQuery(key, value string) driver.Request { if r.q == nil { r.q = url.Values{} } r.q.Set(key, value) return r }
go
func (r *httpJSONRequest) SetQuery(key, value string) driver.Request { if r.q == nil { r.q = url.Values{} } r.q.Set(key, value) return r }
[ "func", "(", "r", "*", "httpJSONRequest", ")", "SetQuery", "(", "key", ",", "value", "string", ")", "driver", ".", "Request", "{", "if", "r", ".", "q", "==", "nil", "{", "r", ".", "q", "=", "url", ".", "Values", "{", "}", "\n", "}", "\n", "r", ".", "q", ".", "Set", "(", "key", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// SetQuery sets a single query argument of the request. // Any existing query argument with the same key is overwritten.
[ "SetQuery", "sets", "a", "single", "query", "argument", "of", "the", "request", ".", "Any", "existing", "query", "argument", "with", "the", "same", "key", "is", "overwritten", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/request_json.go#L80-L86
5,643
arangodb/go-driver
http/request_json.go
SetHeader
func (r *httpJSONRequest) SetHeader(key, value string) driver.Request { if r.hdr == nil { r.hdr = make(map[string]string) } r.hdr[key] = value return r }
go
func (r *httpJSONRequest) SetHeader(key, value string) driver.Request { if r.hdr == nil { r.hdr = make(map[string]string) } r.hdr[key] = value return r }
[ "func", "(", "r", "*", "httpJSONRequest", ")", "SetHeader", "(", "key", ",", "value", "string", ")", "driver", ".", "Request", "{", "if", "r", ".", "hdr", "==", "nil", "{", "r", ".", "hdr", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "\n", "r", ".", "hdr", "[", "key", "]", "=", "value", "\n", "return", "r", "\n", "}" ]
// SetHeader sets a single header arguments of the request. // Any existing header argument with the same key is overwritten.
[ "SetHeader", "sets", "a", "single", "header", "arguments", "of", "the", "request", ".", "Any", "existing", "header", "argument", "with", "the", "same", "key", "is", "overwritten", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/request_json.go#L192-L198
5,644
arangodb/go-driver
agency/agency_health.go
WithAllowNoLeader
func WithAllowNoLeader(parent context.Context) context.Context { if parent == nil { parent = context.Background() } return context.WithValue(parent, keyAllowNoLeader, true) }
go
func WithAllowNoLeader(parent context.Context) context.Context { if parent == nil { parent = context.Background() } return context.WithValue(parent, keyAllowNoLeader, true) }
[ "func", "WithAllowNoLeader", "(", "parent", "context", ".", "Context", ")", "context", ".", "Context", "{", "if", "parent", "==", "nil", "{", "parent", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "return", "context", ".", "WithValue", "(", "parent", ",", "keyAllowNoLeader", ",", "true", ")", "\n", "}" ]
// WithAllowNoLeader is used to configure a context to make AreAgentsHealthy // accept the situation where it finds 0 leaders.
[ "WithAllowNoLeader", "is", "used", "to", "configure", "a", "context", "to", "make", "AreAgentsHealthy", "accept", "the", "situation", "where", "it", "finds", "0", "leaders", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_health.go#L50-L55
5,645
arangodb/go-driver
agency/agency_health.go
hasAllowNoLeader
func hasAllowNoLeader(ctx context.Context) bool { return ctx != nil && ctx.Value(keyAllowNoLeader) != nil }
go
func hasAllowNoLeader(ctx context.Context) bool { return ctx != nil && ctx.Value(keyAllowNoLeader) != nil }
[ "func", "hasAllowNoLeader", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "return", "ctx", "!=", "nil", "&&", "ctx", ".", "Value", "(", "keyAllowNoLeader", ")", "!=", "nil", "\n", "}" ]
// hasAllowNoLeader returns true when the given context was // prepared with WithAllowNoLeader.
[ "hasAllowNoLeader", "returns", "true", "when", "the", "given", "context", "was", "prepared", "with", "WithAllowNoLeader", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_health.go#L59-L61
5,646
arangodb/go-driver
agency/agency_health.go
AreAgentsHealthy
func AreAgentsHealthy(ctx context.Context, clients []driver.Connection) error { wg := sync.WaitGroup{} invalidKey := []string{"does-not-exist-70ddb948-59ea-52f3-9a19-baaca18de7ae"} statuses := make([]agentStatus, len(clients)) for i, c := range clients { wg.Add(1) go func(i int, c driver.Connection) { defer wg.Done() lctx, cancel := context.WithTimeout(ctx, maxAgentResponseTime) defer cancel() var result interface{} a, err := NewAgency(c) if err == nil { var resp driver.Response lctx = driver.WithResponse(lctx, &resp) if err := a.ReadKey(lctx, invalidKey, &result); err == nil || IsKeyNotFound(err) { // We got a valid read from the leader statuses[i].IsLeader = true statuses[i].LeaderEndpoint = strings.Join(c.Endpoints(), ",") statuses[i].IsResponding = true } else { if driver.IsArangoErrorWithCode(err, 307) && resp != nil { location := resp.Header("Location") // Valid response from a follower statuses[i].IsLeader = false statuses[i].LeaderEndpoint = location statuses[i].IsResponding = true } else { // Unexpected / invalid response statuses[i].IsResponding = false } } } }(i, c) } wg.Wait() // Check the results noLeaders := 0 for i, status := range statuses { if !status.IsResponding { return driver.WithStack(fmt.Errorf("Agent %s is not responding", strings.Join(clients[i].Endpoints(), ","))) } if status.IsLeader { noLeaders++ } if i > 0 { // Compare leader endpoint with previous prev := statuses[i-1].LeaderEndpoint if !IsSameEndpoint(prev, status.LeaderEndpoint) { return driver.WithStack(fmt.Errorf("Not all agents report the same leader endpoint")) } } } if noLeaders != 1 && !hasAllowNoLeader(ctx) { return driver.WithStack(fmt.Errorf("Unexpected number of agency leaders: %d", noLeaders)) } return nil }
go
func AreAgentsHealthy(ctx context.Context, clients []driver.Connection) error { wg := sync.WaitGroup{} invalidKey := []string{"does-not-exist-70ddb948-59ea-52f3-9a19-baaca18de7ae"} statuses := make([]agentStatus, len(clients)) for i, c := range clients { wg.Add(1) go func(i int, c driver.Connection) { defer wg.Done() lctx, cancel := context.WithTimeout(ctx, maxAgentResponseTime) defer cancel() var result interface{} a, err := NewAgency(c) if err == nil { var resp driver.Response lctx = driver.WithResponse(lctx, &resp) if err := a.ReadKey(lctx, invalidKey, &result); err == nil || IsKeyNotFound(err) { // We got a valid read from the leader statuses[i].IsLeader = true statuses[i].LeaderEndpoint = strings.Join(c.Endpoints(), ",") statuses[i].IsResponding = true } else { if driver.IsArangoErrorWithCode(err, 307) && resp != nil { location := resp.Header("Location") // Valid response from a follower statuses[i].IsLeader = false statuses[i].LeaderEndpoint = location statuses[i].IsResponding = true } else { // Unexpected / invalid response statuses[i].IsResponding = false } } } }(i, c) } wg.Wait() // Check the results noLeaders := 0 for i, status := range statuses { if !status.IsResponding { return driver.WithStack(fmt.Errorf("Agent %s is not responding", strings.Join(clients[i].Endpoints(), ","))) } if status.IsLeader { noLeaders++ } if i > 0 { // Compare leader endpoint with previous prev := statuses[i-1].LeaderEndpoint if !IsSameEndpoint(prev, status.LeaderEndpoint) { return driver.WithStack(fmt.Errorf("Not all agents report the same leader endpoint")) } } } if noLeaders != 1 && !hasAllowNoLeader(ctx) { return driver.WithStack(fmt.Errorf("Unexpected number of agency leaders: %d", noLeaders)) } return nil }
[ "func", "AreAgentsHealthy", "(", "ctx", "context", ".", "Context", ",", "clients", "[", "]", "driver", ".", "Connection", ")", "error", "{", "wg", ":=", "sync", ".", "WaitGroup", "{", "}", "\n", "invalidKey", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "statuses", ":=", "make", "(", "[", "]", "agentStatus", ",", "len", "(", "clients", ")", ")", "\n", "for", "i", ",", "c", ":=", "range", "clients", "{", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", "i", "int", ",", "c", "driver", ".", "Connection", ")", "{", "defer", "wg", ".", "Done", "(", ")", "\n", "lctx", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "maxAgentResponseTime", ")", "\n", "defer", "cancel", "(", ")", "\n", "var", "result", "interface", "{", "}", "\n", "a", ",", "err", ":=", "NewAgency", "(", "c", ")", "\n", "if", "err", "==", "nil", "{", "var", "resp", "driver", ".", "Response", "\n", "lctx", "=", "driver", ".", "WithResponse", "(", "lctx", ",", "&", "resp", ")", "\n", "if", "err", ":=", "a", ".", "ReadKey", "(", "lctx", ",", "invalidKey", ",", "&", "result", ")", ";", "err", "==", "nil", "||", "IsKeyNotFound", "(", "err", ")", "{", "// We got a valid read from the leader", "statuses", "[", "i", "]", ".", "IsLeader", "=", "true", "\n", "statuses", "[", "i", "]", ".", "LeaderEndpoint", "=", "strings", ".", "Join", "(", "c", ".", "Endpoints", "(", ")", ",", "\"", "\"", ")", "\n", "statuses", "[", "i", "]", ".", "IsResponding", "=", "true", "\n", "}", "else", "{", "if", "driver", ".", "IsArangoErrorWithCode", "(", "err", ",", "307", ")", "&&", "resp", "!=", "nil", "{", "location", ":=", "resp", ".", "Header", "(", "\"", "\"", ")", "\n", "// Valid response from a follower", "statuses", "[", "i", "]", ".", "IsLeader", "=", "false", "\n", "statuses", "[", "i", "]", ".", "LeaderEndpoint", "=", "location", "\n", "statuses", "[", "i", "]", ".", "IsResponding", "=", "true", "\n", "}", "else", "{", "// Unexpected / invalid response", "statuses", "[", "i", "]", ".", "IsResponding", "=", "false", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", "i", ",", "c", ")", "\n", "}", "\n", "wg", ".", "Wait", "(", ")", "\n\n", "// Check the results", "noLeaders", ":=", "0", "\n", "for", "i", ",", "status", ":=", "range", "statuses", "{", "if", "!", "status", ".", "IsResponding", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "clients", "[", "i", "]", ".", "Endpoints", "(", ")", ",", "\"", "\"", ")", ")", ")", "\n", "}", "\n", "if", "status", ".", "IsLeader", "{", "noLeaders", "++", "\n", "}", "\n", "if", "i", ">", "0", "{", "// Compare leader endpoint with previous", "prev", ":=", "statuses", "[", "i", "-", "1", "]", ".", "LeaderEndpoint", "\n", "if", "!", "IsSameEndpoint", "(", "prev", ",", "status", ".", "LeaderEndpoint", ")", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "noLeaders", "!=", "1", "&&", "!", "hasAllowNoLeader", "(", "ctx", ")", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "noLeaders", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AreAgentsHealthy performs a health check on all given agents. // Of the given agents, 1 must respond as leader and all others must redirect to the leader. // The function returns nil when all agents are healthy or an error when something is wrong.
[ "AreAgentsHealthy", "performs", "a", "health", "check", "on", "all", "given", "agents", ".", "Of", "the", "given", "agents", "1", "must", "respond", "as", "leader", "and", "all", "others", "must", "redirect", "to", "the", "leader", ".", "The", "function", "returns", "nil", "when", "all", "agents", "are", "healthy", "or", "an", "error", "when", "something", "is", "wrong", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_health.go#L66-L124
5,647
arangodb/go-driver
agency/agency_health.go
IsSameEndpoint
func IsSameEndpoint(a, b string) bool { if a == b { return true } ua, err := url.Parse(a) if err != nil { return false } ub, err := url.Parse(b) if err != nil { return false } return ua.Hostname() == ub.Hostname() }
go
func IsSameEndpoint(a, b string) bool { if a == b { return true } ua, err := url.Parse(a) if err != nil { return false } ub, err := url.Parse(b) if err != nil { return false } return ua.Hostname() == ub.Hostname() }
[ "func", "IsSameEndpoint", "(", "a", ",", "b", "string", ")", "bool", "{", "if", "a", "==", "b", "{", "return", "true", "\n", "}", "\n", "ua", ",", "err", ":=", "url", ".", "Parse", "(", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "ub", ",", "err", ":=", "url", ".", "Parse", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "ua", ".", "Hostname", "(", ")", "==", "ub", ".", "Hostname", "(", ")", "\n", "}" ]
// IsSameEndpoint returns true when the 2 given endpoints // refer to the same server.
[ "IsSameEndpoint", "returns", "true", "when", "the", "2", "given", "endpoints", "refer", "to", "the", "same", "server", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_health.go#L128-L141
5,648
arangodb/go-driver
collection_indexes_impl.go
Indexes
func (c *collection) Indexes(ctx context.Context) ([]Index, error) { req, err := c.conn.NewRequest("GET", path.Join(c.db.relPath(), "_api", "index")) if err != nil { return nil, WithStack(err) } req.SetQuery("collection", c.name) resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data indexListResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Index, 0, len(data.Indexes)) for _, x := range data.Indexes { idx, err := newIndex(x.ID, x.Type, c) if err != nil { return nil, WithStack(err) } result = append(result, idx) } return result, nil }
go
func (c *collection) Indexes(ctx context.Context) ([]Index, error) { req, err := c.conn.NewRequest("GET", path.Join(c.db.relPath(), "_api", "index")) if err != nil { return nil, WithStack(err) } req.SetQuery("collection", c.name) resp, err := c.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data indexListResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Index, 0, len(data.Indexes)) for _, x := range data.Indexes { idx, err := newIndex(x.ID, x.Type, c) if err != nil { return nil, WithStack(err) } result = append(result, idx) } return result, nil }
[ "func", "(", "c", "*", "collection", ")", "Indexes", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Index", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "c", ".", "db", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "req", ".", "SetQuery", "(", "\"", "\"", ",", "c", ".", "name", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "indexListResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Index", ",", "0", ",", "len", "(", "data", ".", "Indexes", ")", ")", "\n", "for", "_", ",", "x", ":=", "range", "data", ".", "Indexes", "{", "idx", ",", "err", ":=", "newIndex", "(", "x", ".", "ID", ",", "x", ".", "Type", ",", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "idx", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Indexes returns a list of all indexes in the collection.
[ "Indexes", "returns", "a", "list", "of", "all", "indexes", "in", "the", "collection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_indexes_impl.go#L95-L121
5,649
arangodb/go-driver
user_impl.go
newUser
func newUser(data userData, conn Connection) (User, error) { if data.Name == "" { return nil, WithStack(InvalidArgumentError{Message: "data.Name is empty"}) } if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &user{ data: data, conn: conn, }, nil }
go
func newUser(data userData, conn Connection) (User, error) { if data.Name == "" { return nil, WithStack(InvalidArgumentError{Message: "data.Name is empty"}) } if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &user{ data: data, conn: conn, }, nil }
[ "func", "newUser", "(", "data", "userData", ",", "conn", "Connection", ")", "(", "User", ",", "error", ")", "{", "if", "data", ".", "Name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "conn", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "user", "{", "data", ":", "data", ",", "conn", ":", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newUser creates a new User implementation.
[ "newUser", "creates", "a", "new", "User", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L31-L42
5,650
arangodb/go-driver
user_impl.go
Remove
func (u *user) Remove(ctx context.Context) error { req, err := u.conn.NewRequest("DELETE", u.relPath()) if err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } return nil }
go
func (u *user) Remove(ctx context.Context) error { req, err := u.conn.NewRequest("DELETE", u.relPath()) if err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } return nil }
[ "func", "(", "u", "*", "user", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Remove removes the entire user. // If the user does not exist, a NotFoundError is returned.
[ "Remove", "removes", "the", "entire", "user", ".", "If", "the", "user", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L90-L103
5,651
arangodb/go-driver
user_impl.go
Update
func (u *user) Update(ctx context.Context, options UserOptions) error { req, err := u.conn.NewRequest("PATCH", u.relPath()) if err != nil { return WithStack(err) } if _, err := req.SetBody(options); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return WithStack(err) } u.data = data return nil }
go
func (u *user) Update(ctx context.Context, options UserOptions) error { req, err := u.conn.NewRequest("PATCH", u.relPath()) if err != nil { return WithStack(err) } if _, err := req.SetBody(options); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } var data userData if err := resp.ParseBody("", &data); err != nil { return WithStack(err) } u.data = data return nil }
[ "func", "(", "u", "*", "user", ")", "Update", "(", "ctx", "context", ".", "Context", ",", "options", "UserOptions", ")", "error", "{", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "options", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "userData", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "u", ".", "data", "=", "data", "\n", "return", "nil", "\n", "}" ]
// Update updates individual properties of the user. // If the user does not exist, a NotFoundError is returned.
[ "Update", "updates", "individual", "properties", "of", "the", "user", ".", "If", "the", "user", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L107-L128
5,652
arangodb/go-driver
user_impl.go
AccessibleDatabases
func (u *user) AccessibleDatabases(ctx context.Context) ([]Database, error) { req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database")) if err != nil { return nil, WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data userAccessibleDatabasesResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Database, 0, len(data.Result)) for name := range data.Result { db, err := newDatabase(name, u.conn) if err != nil { return nil, WithStack(err) } result = append(result, db) } return result, nil }
go
func (u *user) AccessibleDatabases(ctx context.Context) ([]Database, error) { req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database")) if err != nil { return nil, WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data userAccessibleDatabasesResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Database, 0, len(data.Result)) for name := range data.Result { db, err := newDatabase(name, u.conn) if err != nil { return nil, WithStack(err) } result = append(result, db) } return result, nil }
[ "func", "(", "u", "*", "user", ")", "AccessibleDatabases", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Database", ",", "error", ")", "{", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "userAccessibleDatabasesResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Database", ",", "0", ",", "len", "(", "data", ".", "Result", ")", ")", "\n", "for", "name", ":=", "range", "data", ".", "Result", "{", "db", ",", "err", ":=", "newDatabase", "(", "name", ",", "u", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "db", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// AccessibleDatabases returns a list of all databases that can be accessed by this user.
[ "AccessibleDatabases", "returns", "a", "list", "of", "all", "databases", "that", "can", "be", "accessed", "by", "this", "user", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L160-L185
5,653
arangodb/go-driver
user_impl.go
SetDatabaseAccess
func (u *user) SetDatabaseAccess(ctx context.Context, db Database, access Grant) error { dbName, _, err := getDatabaseAndCollectionName(db) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) req, err := u.conn.NewRequest("PUT", path.Join(u.relPath(), "database", escapedDbName)) if err != nil { return WithStack(err) } input := struct { Grant Grant `json:"grant"` }{ Grant: access, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (u *user) SetDatabaseAccess(ctx context.Context, db Database, access Grant) error { dbName, _, err := getDatabaseAndCollectionName(db) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) req, err := u.conn.NewRequest("PUT", path.Join(u.relPath(), "database", escapedDbName)) if err != nil { return WithStack(err) } input := struct { Grant Grant `json:"grant"` }{ Grant: access, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "u", "*", "user", ")", "SetDatabaseAccess", "(", "ctx", "context", ".", "Context", ",", "db", "Database", ",", "access", "Grant", ")", "error", "{", "dbName", ",", "_", ",", "err", ":=", "getDatabaseAndCollectionName", "(", "db", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "escapedDbName", ":=", "pathEscape", "(", "dbName", ")", "\n", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedDbName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "struct", "{", "Grant", "Grant", "`json:\"grant\"`", "\n", "}", "{", "Grant", ":", "access", ",", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetDatabaseAccess sets the access this user has to the given database. // Pass a `nil` database to set the default access this user has to any new database. // This function requires ArangoDB 3.2 and up for access value `GrantReadOnly`.
[ "SetDatabaseAccess", "sets", "the", "access", "this", "user", "has", "to", "the", "given", "database", ".", "Pass", "a", "nil", "database", "to", "set", "the", "default", "access", "this", "user", "has", "to", "any", "new", "database", ".", "This", "function", "requires", "ArangoDB", "3", ".", "2", "and", "up", "for", "access", "value", "GrantReadOnly", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L190-L216
5,654
arangodb/go-driver
user_impl.go
GetDatabaseAccess
func (u *user) GetDatabaseAccess(ctx context.Context, db Database) (Grant, error) { dbName, _, err := getDatabaseAndCollectionName(db) if err != nil { return GrantNone, WithStack(err) } escapedDbName := pathEscape(dbName) req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database", escapedDbName)) if err != nil { return GrantNone, WithStack(err) } applyContextSettings(ctx, req) resp, err := u.conn.Do(ctx, req) if err != nil { return GrantNone, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return GrantNone, WithStack(err) } var data getAccessResponse if err := resp.ParseBody("", &data); err != nil { return GrantNone, WithStack(err) } return Grant(data.Result), nil }
go
func (u *user) GetDatabaseAccess(ctx context.Context, db Database) (Grant, error) { dbName, _, err := getDatabaseAndCollectionName(db) if err != nil { return GrantNone, WithStack(err) } escapedDbName := pathEscape(dbName) req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database", escapedDbName)) if err != nil { return GrantNone, WithStack(err) } applyContextSettings(ctx, req) resp, err := u.conn.Do(ctx, req) if err != nil { return GrantNone, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return GrantNone, WithStack(err) } var data getAccessResponse if err := resp.ParseBody("", &data); err != nil { return GrantNone, WithStack(err) } return Grant(data.Result), nil }
[ "func", "(", "u", "*", "user", ")", "GetDatabaseAccess", "(", "ctx", "context", ".", "Context", ",", "db", "Database", ")", "(", "Grant", ",", "error", ")", "{", "dbName", ",", "_", ",", "err", ":=", "getDatabaseAndCollectionName", "(", "db", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "escapedDbName", ":=", "pathEscape", "(", "dbName", ")", "\n", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedDbName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "var", "data", "getAccessResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "Grant", "(", "data", ".", "Result", ")", ",", "nil", "\n", "}" ]
// GetDatabaseAccess gets the access rights for this user to the given database. // Pass a `nil` database to get the default access this user has to any new database. // This function requires ArangoDB 3.2 and up.
[ "GetDatabaseAccess", "gets", "the", "access", "rights", "for", "this", "user", "to", "the", "given", "database", ".", "Pass", "a", "nil", "database", "to", "get", "the", "default", "access", "this", "user", "has", "to", "any", "new", "database", ".", "This", "function", "requires", "ArangoDB", "3", ".", "2", "and", "up", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L225-L249
5,655
arangodb/go-driver
user_impl.go
SetCollectionAccess
func (u *user) SetCollectionAccess(ctx context.Context, col AccessTarget, access Grant) error { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("PUT", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return WithStack(err) } input := struct { Grant Grant `json:"grant"` }{ Grant: access, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (u *user) SetCollectionAccess(ctx context.Context, col AccessTarget, access Grant) error { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("PUT", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return WithStack(err) } input := struct { Grant Grant `json:"grant"` }{ Grant: access, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "u", "*", "user", ")", "SetCollectionAccess", "(", "ctx", "context", ".", "Context", ",", "col", "AccessTarget", ",", "access", "Grant", ")", "error", "{", "dbName", ",", "colName", ",", "err", ":=", "getDatabaseAndCollectionName", "(", "col", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "escapedDbName", ":=", "pathEscape", "(", "dbName", ")", "\n", "escapedColName", ":=", "pathEscape", "(", "colName", ")", "\n", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedDbName", ",", "escapedColName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "struct", "{", "Grant", "Grant", "`json:\"grant\"`", "\n", "}", "{", "Grant", ":", "access", ",", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetCollectionAccess sets the access this user has to a collection. // If you pass a `Collection`, it will set access for that collection. // If you pass a `Database`, it will set the default collection access for that database. // If you pass `nil`, it will set the default collection access for the default database. // This function requires ArangoDB 3.2 and up.
[ "SetCollectionAccess", "sets", "the", "access", "this", "user", "has", "to", "a", "collection", ".", "If", "you", "pass", "a", "Collection", "it", "will", "set", "access", "for", "that", "collection", ".", "If", "you", "pass", "a", "Database", "it", "will", "set", "the", "default", "collection", "access", "for", "that", "database", ".", "If", "you", "pass", "nil", "it", "will", "set", "the", "default", "collection", "access", "for", "the", "default", "database", ".", "This", "function", "requires", "ArangoDB", "3", ".", "2", "and", "up", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L282-L309
5,656
arangodb/go-driver
user_impl.go
GetCollectionAccess
func (u *user) GetCollectionAccess(ctx context.Context, col AccessTarget) (Grant, error) { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return GrantNone, WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return GrantNone, WithStack(err) } applyContextSettings(ctx, req) resp, err := u.conn.Do(ctx, req) if err != nil { return GrantNone, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return GrantNone, WithStack(err) } var data getAccessResponse if err := resp.ParseBody("", &data); err != nil { return GrantNone, WithStack(err) } return Grant(data.Result), nil }
go
func (u *user) GetCollectionAccess(ctx context.Context, col AccessTarget) (Grant, error) { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return GrantNone, WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("GET", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return GrantNone, WithStack(err) } applyContextSettings(ctx, req) resp, err := u.conn.Do(ctx, req) if err != nil { return GrantNone, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return GrantNone, WithStack(err) } var data getAccessResponse if err := resp.ParseBody("", &data); err != nil { return GrantNone, WithStack(err) } return Grant(data.Result), nil }
[ "func", "(", "u", "*", "user", ")", "GetCollectionAccess", "(", "ctx", "context", ".", "Context", ",", "col", "AccessTarget", ")", "(", "Grant", ",", "error", ")", "{", "dbName", ",", "colName", ",", "err", ":=", "getDatabaseAndCollectionName", "(", "col", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "escapedDbName", ":=", "pathEscape", "(", "dbName", ")", "\n", "escapedColName", ":=", "pathEscape", "(", "colName", ")", "\n", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedDbName", ",", "escapedColName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "var", "data", "getAccessResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "GrantNone", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "Grant", "(", "data", ".", "Result", ")", ",", "nil", "\n", "}" ]
// GetCollectionAccess gets the access rights for this user to the given collection. // If you pass a `Collection`, it will get access for that collection. // If you pass a `Database`, it will get the default collection access for that database. // If you pass `nil`, it will get the default collection access for the default database.
[ "GetCollectionAccess", "gets", "the", "access", "rights", "for", "this", "user", "to", "the", "given", "collection", ".", "If", "you", "pass", "a", "Collection", "it", "will", "get", "access", "for", "that", "collection", ".", "If", "you", "pass", "a", "Database", "it", "will", "get", "the", "default", "collection", "access", "for", "that", "database", ".", "If", "you", "pass", "nil", "it", "will", "get", "the", "default", "collection", "access", "for", "the", "default", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L315-L340
5,657
arangodb/go-driver
user_impl.go
RemoveCollectionAccess
func (u *user) RemoveCollectionAccess(ctx context.Context, col AccessTarget) error { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("DELETE", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } return nil }
go
func (u *user) RemoveCollectionAccess(ctx context.Context, col AccessTarget) error { dbName, colName, err := getDatabaseAndCollectionName(col) if err != nil { return WithStack(err) } escapedDbName := pathEscape(dbName) escapedColName := pathEscape(colName) req, err := u.conn.NewRequest("DELETE", path.Join(u.relPath(), "database", escapedDbName, escapedColName)) if err != nil { return WithStack(err) } resp, err := u.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } return nil }
[ "func", "(", "u", "*", "user", ")", "RemoveCollectionAccess", "(", "ctx", "context", ".", "Context", ",", "col", "AccessTarget", ")", "error", "{", "dbName", ",", "colName", ",", "err", ":=", "getDatabaseAndCollectionName", "(", "col", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "escapedDbName", ":=", "pathEscape", "(", "dbName", ")", "\n", "escapedColName", ":=", "pathEscape", "(", "colName", ")", "\n", "req", ",", "err", ":=", "u", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "u", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedDbName", ",", "escapedColName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "u", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveCollectionAccess removes the access this user has to a collection. // If you pass a `Collection`, it will removes access for that collection. // If you pass a `Database`, it will removes the default collection access for that database. // If you pass `nil`, it will removes the default collection access for the default database. // This function requires ArangoDB 3.2 and up.
[ "RemoveCollectionAccess", "removes", "the", "access", "this", "user", "has", "to", "a", "collection", ".", "If", "you", "pass", "a", "Collection", "it", "will", "removes", "access", "for", "that", "collection", ".", "If", "you", "pass", "a", "Database", "it", "will", "removes", "the", "default", "collection", "access", "for", "that", "database", ".", "If", "you", "pass", "nil", "it", "will", "removes", "the", "default", "collection", "access", "for", "the", "default", "database", ".", "This", "function", "requires", "ArangoDB", "3", ".", "2", "and", "up", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L347-L366
5,658
arangodb/go-driver
user_impl.go
getDatabaseAndCollectionName
func getDatabaseAndCollectionName(col AccessTarget) (string, string, error) { if col == nil { return "*", "*", nil } if x, ok := col.(Collection); ok { return x.Database().Name(), x.Name(), nil } if x, ok := col.(Database); ok { return x.Name(), "*", nil } return "", "", WithStack(InvalidArgumentError{"Need Collection or Database or nil"}) }
go
func getDatabaseAndCollectionName(col AccessTarget) (string, string, error) { if col == nil { return "*", "*", nil } if x, ok := col.(Collection); ok { return x.Database().Name(), x.Name(), nil } if x, ok := col.(Database); ok { return x.Name(), "*", nil } return "", "", WithStack(InvalidArgumentError{"Need Collection or Database or nil"}) }
[ "func", "getDatabaseAndCollectionName", "(", "col", "AccessTarget", ")", "(", "string", ",", "string", ",", "error", ")", "{", "if", "col", "==", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "nil", "\n", "}", "\n", "if", "x", ",", "ok", ":=", "col", ".", "(", "Collection", ")", ";", "ok", "{", "return", "x", ".", "Database", "(", ")", ".", "Name", "(", ")", ",", "x", ".", "Name", "(", ")", ",", "nil", "\n", "}", "\n", "if", "x", ",", "ok", ":=", "col", ".", "(", "Database", ")", ";", "ok", "{", "return", "x", ".", "Name", "(", ")", ",", "\"", "\"", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "\"", "\"", "}", ")", "\n", "}" ]
// getDatabaseAndCollectionName returns database-name, collection-name from given access target.
[ "getDatabaseAndCollectionName", "returns", "database", "-", "name", "collection", "-", "name", "from", "given", "access", "target", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/user_impl.go#L369-L380
5,659
arangodb/go-driver
query.go
WithQueryCount
func WithQueryCount(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryCount, v) }
go
func WithQueryCount(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryCount, v) }
[ "func", "WithQueryCount", "(", "parent", "context", ".", "Context", ",", "value", "...", "bool", ")", "context", ".", "Context", "{", "v", ":=", "true", "\n", "if", "len", "(", "value", ")", ">", "0", "{", "v", "=", "value", "[", "0", "]", "\n", "}", "\n", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryCount", ",", "v", ")", "\n", "}" ]
// WithQueryCount is used to configure a context that will set the Count of a query request, // If value is not given it defaults to true.
[ "WithQueryCount", "is", "used", "to", "configure", "a", "context", "that", "will", "set", "the", "Count", "of", "a", "query", "request", "If", "value", "is", "not", "given", "it", "defaults", "to", "true", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L43-L49
5,660
arangodb/go-driver
query.go
WithQueryBatchSize
func WithQueryBatchSize(parent context.Context, value int) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryBatchSize, value) }
go
func WithQueryBatchSize(parent context.Context, value int) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryBatchSize, value) }
[ "func", "WithQueryBatchSize", "(", "parent", "context", ".", "Context", ",", "value", "int", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryBatchSize", ",", "value", ")", "\n", "}" ]
// WithQueryBatchSize is used to configure a context that will set the BatchSize of a query request,
[ "WithQueryBatchSize", "is", "used", "to", "configure", "a", "context", "that", "will", "set", "the", "BatchSize", "of", "a", "query", "request" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L52-L54
5,661
arangodb/go-driver
query.go
WithQueryCache
func WithQueryCache(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryCache, v) }
go
func WithQueryCache(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryCache, v) }
[ "func", "WithQueryCache", "(", "parent", "context", ".", "Context", ",", "value", "...", "bool", ")", "context", ".", "Context", "{", "v", ":=", "true", "\n", "if", "len", "(", "value", ")", ">", "0", "{", "v", "=", "value", "[", "0", "]", "\n", "}", "\n", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryCache", ",", "v", ")", "\n", "}" ]
// WithQueryCache is used to configure a context that will set the Cache of a query request, // If value is not given it defaults to true.
[ "WithQueryCache", "is", "used", "to", "configure", "a", "context", "that", "will", "set", "the", "Cache", "of", "a", "query", "request", "If", "value", "is", "not", "given", "it", "defaults", "to", "true", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L58-L64
5,662
arangodb/go-driver
query.go
WithQueryMemoryLimit
func WithQueryMemoryLimit(parent context.Context, value int64) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryMemoryLimit, value) }
go
func WithQueryMemoryLimit(parent context.Context, value int64) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryMemoryLimit, value) }
[ "func", "WithQueryMemoryLimit", "(", "parent", "context", ".", "Context", ",", "value", "int64", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryMemoryLimit", ",", "value", ")", "\n", "}" ]
// WithQueryMemoryLimit is used to configure a context that will set the MemoryList of a query request,
[ "WithQueryMemoryLimit", "is", "used", "to", "configure", "a", "context", "that", "will", "set", "the", "MemoryList", "of", "a", "query", "request" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L67-L69
5,663
arangodb/go-driver
query.go
WithQueryTTL
func WithQueryTTL(parent context.Context, value time.Duration) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryTTL, value) }
go
func WithQueryTTL(parent context.Context, value time.Duration) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryTTL, value) }
[ "func", "WithQueryTTL", "(", "parent", "context", ".", "Context", ",", "value", "time", ".", "Duration", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryTTL", ",", "value", ")", "\n", "}" ]
// WithQueryTTL is used to configure a context that will set the TTL of a query request,
[ "WithQueryTTL", "is", "used", "to", "configure", "a", "context", "that", "will", "set", "the", "TTL", "of", "a", "query", "request" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L72-L74
5,664
arangodb/go-driver
query.go
WithQuerySatelliteSyncWait
func WithQuerySatelliteSyncWait(parent context.Context, value time.Duration) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryOptSatSyncWait, value) }
go
func WithQuerySatelliteSyncWait(parent context.Context, value time.Duration) context.Context { return context.WithValue(contextOrBackground(parent), keyQueryOptSatSyncWait, value) }
[ "func", "WithQuerySatelliteSyncWait", "(", "parent", "context", ".", "Context", ",", "value", "time", ".", "Duration", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryOptSatSyncWait", ",", "value", ")", "\n", "}" ]
// WithQuerySatelliteSyncWait sets the satelliteSyncWait query value on the query cursor request
[ "WithQuerySatelliteSyncWait", "sets", "the", "satelliteSyncWait", "query", "value", "on", "the", "query", "cursor", "request" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L77-L79
5,665
arangodb/go-driver
query.go
WithQueryFullCount
func WithQueryFullCount(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryOptFullCount, v) }
go
func WithQueryFullCount(parent context.Context, value ...bool) context.Context { v := true if len(value) > 0 { v = value[0] } return context.WithValue(contextOrBackground(parent), keyQueryOptFullCount, v) }
[ "func", "WithQueryFullCount", "(", "parent", "context", ".", "Context", ",", "value", "...", "bool", ")", "context", ".", "Context", "{", "v", ":=", "true", "\n", "if", "len", "(", "value", ")", ">", "0", "{", "v", "=", "value", "[", "0", "]", "\n", "}", "\n", "return", "context", ".", "WithValue", "(", "contextOrBackground", "(", "parent", ")", ",", "keyQueryOptFullCount", ",", "v", ")", "\n", "}" ]
// WithQueryFullCount is used to configure whether the query returns the full count of results // before the last LIMIT statement
[ "WithQueryFullCount", "is", "used", "to", "configure", "whether", "the", "query", "returns", "the", "full", "count", "of", "results", "before", "the", "last", "LIMIT", "statement" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L83-L89
5,666
arangodb/go-driver
query.go
applyContextSettings
func (q *queryRequest) applyContextSettings(ctx context.Context) { if ctx == nil { return } if rawValue := ctx.Value(keyQueryCount); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Count = value } } if rawValue := ctx.Value(keyQueryBatchSize); rawValue != nil { if value, ok := rawValue.(int); ok { q.BatchSize = value } } if rawValue := ctx.Value(keyQueryCache); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Cache = value } } if rawValue := ctx.Value(keyQueryMemoryLimit); rawValue != nil { if value, ok := rawValue.(int64); ok { q.MemoryLimit = value } } if rawValue := ctx.Value(keyQueryTTL); rawValue != nil { if value, ok := rawValue.(time.Duration); ok { q.TTL = value.Seconds() } } if rawValue := ctx.Value(keyQueryOptSatSyncWait); rawValue != nil { if value, ok := rawValue.(time.Duration); ok { q.Options.SatelliteSyncWait = value.Seconds() } } if rawValue := ctx.Value(keyQueryOptFullCount); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Options.FullCount = value } } if rawValue := ctx.Value(keyQueryOptStream); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Options.Stream = value } } }
go
func (q *queryRequest) applyContextSettings(ctx context.Context) { if ctx == nil { return } if rawValue := ctx.Value(keyQueryCount); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Count = value } } if rawValue := ctx.Value(keyQueryBatchSize); rawValue != nil { if value, ok := rawValue.(int); ok { q.BatchSize = value } } if rawValue := ctx.Value(keyQueryCache); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Cache = value } } if rawValue := ctx.Value(keyQueryMemoryLimit); rawValue != nil { if value, ok := rawValue.(int64); ok { q.MemoryLimit = value } } if rawValue := ctx.Value(keyQueryTTL); rawValue != nil { if value, ok := rawValue.(time.Duration); ok { q.TTL = value.Seconds() } } if rawValue := ctx.Value(keyQueryOptSatSyncWait); rawValue != nil { if value, ok := rawValue.(time.Duration); ok { q.Options.SatelliteSyncWait = value.Seconds() } } if rawValue := ctx.Value(keyQueryOptFullCount); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Options.FullCount = value } } if rawValue := ctx.Value(keyQueryOptStream); rawValue != nil { if value, ok := rawValue.(bool); ok { q.Options.Stream = value } } }
[ "func", "(", "q", "*", "queryRequest", ")", "applyContextSettings", "(", "ctx", "context", ".", "Context", ")", "{", "if", "ctx", "==", "nil", "{", "return", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryCount", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "bool", ")", ";", "ok", "{", "q", ".", "Count", "=", "value", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryBatchSize", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "int", ")", ";", "ok", "{", "q", ".", "BatchSize", "=", "value", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryCache", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "bool", ")", ";", "ok", "{", "q", ".", "Cache", "=", "value", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryMemoryLimit", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "int64", ")", ";", "ok", "{", "q", ".", "MemoryLimit", "=", "value", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryTTL", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "time", ".", "Duration", ")", ";", "ok", "{", "q", ".", "TTL", "=", "value", ".", "Seconds", "(", ")", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryOptSatSyncWait", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "time", ".", "Duration", ")", ";", "ok", "{", "q", ".", "Options", ".", "SatelliteSyncWait", "=", "value", ".", "Seconds", "(", ")", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryOptFullCount", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "bool", ")", ";", "ok", "{", "q", ".", "Options", ".", "FullCount", "=", "value", "\n", "}", "\n", "}", "\n", "if", "rawValue", ":=", "ctx", ".", "Value", "(", "keyQueryOptStream", ")", ";", "rawValue", "!=", "nil", "{", "if", "value", ",", "ok", ":=", "rawValue", ".", "(", "bool", ")", ";", "ok", "{", "q", ".", "Options", ".", "Stream", "=", "value", "\n", "}", "\n", "}", "\n", "}" ]
// applyContextSettings fills fields in the queryRequest from the given context.
[ "applyContextSettings", "fills", "fields", "in", "the", "queryRequest", "from", "the", "given", "context", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/query.go#L156-L200
5,667
arangodb/go-driver
database_graphs_impl.go
Graph
func (d *database) Graph(ctx context.Context, name string) (Graph, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/gharial", escapedName)) if err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } g, err := newGraph(name, d) if err != nil { return nil, WithStack(err) } return g, nil }
go
func (d *database) Graph(ctx context.Context, name string) (Graph, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/gharial", escapedName)) if err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } g, err := newGraph(name, d) if err != nil { return nil, WithStack(err) } return g, nil }
[ "func", "(", "d", "*", "database", ")", "Graph", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "Graph", ",", "error", ")", "{", "escapedName", ":=", "pathEscape", "(", "name", ")", "\n", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "d", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "g", ",", "err", ":=", "newGraph", "(", "name", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "g", ",", "nil", "\n", "}" ]
// Graph opens a connection to an existing graph within the database. // If no graph with given name exists, an NotFoundError is returned.
[ "Graph", "opens", "a", "connection", "to", "an", "existing", "graph", "within", "the", "database", ".", "If", "no", "graph", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_graphs_impl.go#L32-L50
5,668
arangodb/go-driver
database_graphs_impl.go
Graphs
func (d *database) Graphs(ctx context.Context) ([]Graph, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/gharial")) if err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data getGraphsResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Graph, 0, len(data.Graphs)) for _, info := range data.Graphs { g, err := newGraph(info.Key, d) if err != nil { return nil, WithStack(err) } result = append(result, g) } return result, nil }
go
func (d *database) Graphs(ctx context.Context) ([]Graph, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/gharial")) if err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data getGraphsResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Graph, 0, len(data.Graphs)) for _, info := range data.Graphs { g, err := newGraph(info.Key, d) if err != nil { return nil, WithStack(err) } result = append(result, g) } return result, nil }
[ "func", "(", "d", "*", "database", ")", "Graphs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Graph", ",", "error", ")", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "d", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "getGraphsResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Graph", ",", "0", ",", "len", "(", "data", ".", "Graphs", ")", ")", "\n", "for", "_", ",", "info", ":=", "range", "data", ".", "Graphs", "{", "g", ",", "err", ":=", "newGraph", "(", "info", ".", "Key", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "g", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Graphs returns a list of all graphs in the database.
[ "Graphs", "returns", "a", "list", "of", "all", "graphs", "in", "the", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_graphs_impl.go#L77-L102
5,669
arangodb/go-driver
database_graphs_impl.go
CreateGraph
func (d *database) CreateGraph(ctx context.Context, name string, options *CreateGraphOptions) (Graph, error) { input := createGraphOptions{ Name: name, } if options != nil { input.OrphanVertexCollections = options.OrphanVertexCollections input.EdgeDefinitions = options.EdgeDefinitions input.IsSmart = options.IsSmart if options.SmartGraphAttribute != "" || options.NumberOfShards != 0 { input.Options = &createGraphAdditionalOptions{ SmartGraphAttribute: options.SmartGraphAttribute, NumberOfShards: options.NumberOfShards, } } } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/gharial")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201, 202); err != nil { return nil, WithStack(err) } g, err := newGraph(name, d) if err != nil { return nil, WithStack(err) } return g, nil }
go
func (d *database) CreateGraph(ctx context.Context, name string, options *CreateGraphOptions) (Graph, error) { input := createGraphOptions{ Name: name, } if options != nil { input.OrphanVertexCollections = options.OrphanVertexCollections input.EdgeDefinitions = options.EdgeDefinitions input.IsSmart = options.IsSmart if options.SmartGraphAttribute != "" || options.NumberOfShards != 0 { input.Options = &createGraphAdditionalOptions{ SmartGraphAttribute: options.SmartGraphAttribute, NumberOfShards: options.NumberOfShards, } } } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/gharial")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201, 202); err != nil { return nil, WithStack(err) } g, err := newGraph(name, d) if err != nil { return nil, WithStack(err) } return g, nil }
[ "func", "(", "d", "*", "database", ")", "CreateGraph", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "options", "*", "CreateGraphOptions", ")", "(", "Graph", ",", "error", ")", "{", "input", ":=", "createGraphOptions", "{", "Name", ":", "name", ",", "}", "\n", "if", "options", "!=", "nil", "{", "input", ".", "OrphanVertexCollections", "=", "options", ".", "OrphanVertexCollections", "\n", "input", ".", "EdgeDefinitions", "=", "options", ".", "EdgeDefinitions", "\n", "input", ".", "IsSmart", "=", "options", ".", "IsSmart", "\n", "if", "options", ".", "SmartGraphAttribute", "!=", "\"", "\"", "||", "options", ".", "NumberOfShards", "!=", "0", "{", "input", ".", "Options", "=", "&", "createGraphAdditionalOptions", "{", "SmartGraphAttribute", ":", "options", ".", "SmartGraphAttribute", ",", "NumberOfShards", ":", "options", ".", "NumberOfShards", ",", "}", "\n", "}", "\n", "}", "\n", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "d", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "g", ",", "err", ":=", "newGraph", "(", "name", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "g", ",", "nil", "\n", "}" ]
// CreateGraph creates a new graph with given name and options, and opens a connection to it. // If a graph with given name already exists within the database, a DuplicateError is returned.
[ "CreateGraph", "creates", "a", "new", "graph", "with", "given", "name", "and", "options", "and", "opens", "a", "connection", "to", "it", ".", "If", "a", "graph", "with", "given", "name", "already", "exists", "within", "the", "database", "a", "DuplicateError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_graphs_impl.go#L124-L158
5,670
arangodb/go-driver
http/request_vpack.go
Clone
func (r *httpVPackRequest) Clone() driver.Request { clone := *r clone.q = url.Values{} for k, v := range r.q { for _, x := range v { clone.q.Add(k, x) } } if clone.hdr != nil { clone.hdr = make(map[string]string) for k, v := range r.hdr { clone.hdr[k] = v } } return &clone }
go
func (r *httpVPackRequest) Clone() driver.Request { clone := *r clone.q = url.Values{} for k, v := range r.q { for _, x := range v { clone.q.Add(k, x) } } if clone.hdr != nil { clone.hdr = make(map[string]string) for k, v := range r.hdr { clone.hdr[k] = v } } return &clone }
[ "func", "(", "r", "*", "httpVPackRequest", ")", "Clone", "(", ")", "driver", ".", "Request", "{", "clone", ":=", "*", "r", "\n", "clone", ".", "q", "=", "url", ".", "Values", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "q", "{", "for", "_", ",", "x", ":=", "range", "v", "{", "clone", ".", "q", ".", "Add", "(", "k", ",", "x", ")", "\n", "}", "\n", "}", "\n", "if", "clone", ".", "hdr", "!=", "nil", "{", "clone", ".", "hdr", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "hdr", "{", "clone", ".", "hdr", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "&", "clone", "\n", "}" ]
// Clone creates a new request containing the same data as this request
[ "Clone", "creates", "a", "new", "request", "containing", "the", "same", "data", "as", "this", "request" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/request_vpack.go#L61-L76
5,671
arangodb/go-driver
http/request_vpack.go
SetBody
func (r *httpVPackRequest) SetBody(body ...interface{}) (driver.Request, error) { switch len(body) { case 0: return r, driver.WithStack(fmt.Errorf("Must provide at least 1 body")) case 1: if data, err := velocypack.Marshal(body[0]); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil case 2: mo := mergeObject{Object: body[1], Merge: body[0]} if data, err := velocypack.Marshal(mo); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil default: return r, driver.WithStack(fmt.Errorf("Must provide at most 2 bodies")) } }
go
func (r *httpVPackRequest) SetBody(body ...interface{}) (driver.Request, error) { switch len(body) { case 0: return r, driver.WithStack(fmt.Errorf("Must provide at least 1 body")) case 1: if data, err := velocypack.Marshal(body[0]); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil case 2: mo := mergeObject{Object: body[1], Merge: body[0]} if data, err := velocypack.Marshal(mo); err != nil { return r, driver.WithStack(err) } else { r.body = data } return r, nil default: return r, driver.WithStack(fmt.Errorf("Must provide at most 2 bodies")) } }
[ "func", "(", "r", "*", "httpVPackRequest", ")", "SetBody", "(", "body", "...", "interface", "{", "}", ")", "(", "driver", ".", "Request", ",", "error", ")", "{", "switch", "len", "(", "body", ")", "{", "case", "0", ":", "return", "r", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "case", "1", ":", "if", "data", ",", "err", ":=", "velocypack", ".", "Marshal", "(", "body", "[", "0", "]", ")", ";", "err", "!=", "nil", "{", "return", "r", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "r", ".", "body", "=", "data", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "case", "2", ":", "mo", ":=", "mergeObject", "{", "Object", ":", "body", "[", "1", "]", ",", "Merge", ":", "body", "[", "0", "]", "}", "\n", "if", "data", ",", "err", ":=", "velocypack", ".", "Marshal", "(", "mo", ")", ";", "err", "!=", "nil", "{", "return", "r", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "r", ".", "body", "=", "data", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "default", ":", "return", "r", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "}" ]
// SetBody sets the content of the request. // The protocol of the connection determines what kinds of marshalling is taking place.
[ "SetBody", "sets", "the", "content", "of", "the", "request", ".", "The", "protocol", "of", "the", "connection", "determines", "what", "kinds", "of", "marshalling", "is", "taking", "place", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/request_vpack.go#L90-L113
5,672
arangodb/go-driver
protocol.go
Contains
func (ps ProtocolSet) Contains(p Protocol) bool { for _, x := range ps { if x == p { return true } } return false }
go
func (ps ProtocolSet) Contains(p Protocol) bool { for _, x := range ps { if x == p { return true } } return false }
[ "func", "(", "ps", "ProtocolSet", ")", "Contains", "(", "p", "Protocol", ")", "bool", "{", "for", "_", ",", "x", ":=", "range", "ps", "{", "if", "x", "==", "p", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Contains returns true if the given protocol is contained in the given set, false otherwise.
[ "Contains", "returns", "true", "if", "the", "given", "protocol", "is", "contained", "in", "the", "given", "set", "false", "otherwise", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/protocol.go#L37-L44
5,673
arangodb/go-driver
protocol.go
ContainsAny
func (ps ProtocolSet) ContainsAny(p ...Protocol) bool { for _, x := range ps { for _, y := range p { if x == y { return true } } } return false }
go
func (ps ProtocolSet) ContainsAny(p ...Protocol) bool { for _, x := range ps { for _, y := range p { if x == y { return true } } } return false }
[ "func", "(", "ps", "ProtocolSet", ")", "ContainsAny", "(", "p", "...", "Protocol", ")", "bool", "{", "for", "_", ",", "x", ":=", "range", "ps", "{", "for", "_", ",", "y", ":=", "range", "p", "{", "if", "x", "==", "y", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsAny returns true if any of the given protocols is contained in the given set, false otherwise.
[ "ContainsAny", "returns", "true", "if", "any", "of", "the", "given", "protocols", "is", "contained", "in", "the", "given", "set", "false", "otherwise", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/protocol.go#L47-L56
5,674
arangodb/go-driver
client_server_admin_impl.go
Shutdown
func (c *client) Shutdown(ctx context.Context, removeFromCluster bool) error { req, err := c.conn.NewRequest("DELETE", "_admin/shutdown") if err != nil { return WithStack(err) } if removeFromCluster { req.SetQuery("remove_from_cluster", "1") } resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (c *client) Shutdown(ctx context.Context, removeFromCluster bool) error { req, err := c.conn.NewRequest("DELETE", "_admin/shutdown") if err != nil { return WithStack(err) } if removeFromCluster { req.SetQuery("remove_from_cluster", "1") } resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "c", "*", "client", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ",", "removeFromCluster", "bool", ")", "error", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "removeFromCluster", "{", "req", ".", "SetQuery", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Shutdown a specific server, optionally removing it from its cluster.
[ "Shutdown", "a", "specific", "server", "optionally", "removing", "it", "from", "its", "cluster", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_server_admin_impl.go#L84-L100
5,675
arangodb/go-driver
graph_edge_collections_impl.go
EdgeCollection
func (g *graph) EdgeCollection(ctx context.Context, name string) (Collection, VertexConstraints, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return nil, VertexConstraints{}, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, VertexConstraints{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, VertexConstraints{}, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return nil, VertexConstraints{}, WithStack(err) } for _, n := range data.Graph.EdgeDefinitions { if n.Collection == name { ec, err := newEdgeCollection(name, g) if err != nil { return nil, VertexConstraints{}, WithStack(err) } constraints := VertexConstraints{ From: n.From, To: n.To, } return ec, constraints, nil } } return nil, VertexConstraints{}, WithStack(newArangoError(404, 0, "not found")) }
go
func (g *graph) EdgeCollection(ctx context.Context, name string) (Collection, VertexConstraints, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return nil, VertexConstraints{}, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, VertexConstraints{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, VertexConstraints{}, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return nil, VertexConstraints{}, WithStack(err) } for _, n := range data.Graph.EdgeDefinitions { if n.Collection == name { ec, err := newEdgeCollection(name, g) if err != nil { return nil, VertexConstraints{}, WithStack(err) } constraints := VertexConstraints{ From: n.From, To: n.To, } return ec, constraints, nil } } return nil, VertexConstraints{}, WithStack(newArangoError(404, 0, "not found")) }
[ "func", "(", "g", "*", "graph", ")", "EdgeCollection", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "Collection", ",", "VertexConstraints", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "g", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "getGraphResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "n", ":=", "range", "data", ".", "Graph", ".", "EdgeDefinitions", "{", "if", "n", ".", "Collection", "==", "name", "{", "ec", ",", "err", ":=", "newEdgeCollection", "(", "name", ",", "g", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "constraints", ":=", "VertexConstraints", "{", "From", ":", "n", ".", "From", ",", "To", ":", "n", ".", "To", ",", "}", "\n", "return", "ec", ",", "constraints", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "VertexConstraints", "{", "}", ",", "WithStack", "(", "newArangoError", "(", "404", ",", "0", ",", "\"", "\"", ")", ")", "\n", "}" ]
// EdgeCollection opens a connection to an existing edge-collection within the graph. // If no edge-collection with given name exists, an NotFoundError is returned.
[ "EdgeCollection", "opens", "a", "connection", "to", "an", "existing", "edge", "-", "collection", "within", "the", "graph", ".", "If", "no", "edge", "-", "collection", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_edge_collections_impl.go#L38-L68
5,676
arangodb/go-driver
graph_edge_collections_impl.go
EdgeCollectionExists
func (g *graph) EdgeCollectionExists(ctx context.Context, name string) (bool, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return false, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return false, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return false, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return false, WithStack(err) } for _, n := range data.Graph.EdgeDefinitions { if n.Collection == name { return true, nil } } return false, nil }
go
func (g *graph) EdgeCollectionExists(ctx context.Context, name string) (bool, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return false, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return false, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return false, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return false, WithStack(err) } for _, n := range data.Graph.EdgeDefinitions { if n.Collection == name { return true, nil } } return false, nil }
[ "func", "(", "g", "*", "graph", ")", "EdgeCollectionExists", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "g", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "getGraphResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "n", ":=", "range", "data", ".", "Graph", ".", "EdgeDefinitions", "{", "if", "n", ".", "Collection", "==", "name", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// EdgeCollectionExists returns true if an edge-collection with given name exists within the graph.
[ "EdgeCollectionExists", "returns", "true", "if", "an", "edge", "-", "collection", "with", "given", "name", "exists", "within", "the", "graph", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_edge_collections_impl.go#L71-L93
5,677
arangodb/go-driver
graph_edge_collections_impl.go
EdgeCollections
func (g *graph) EdgeCollections(ctx context.Context) ([]Collection, []VertexConstraints, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return nil, nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, nil, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return nil, nil, WithStack(err) } result := make([]Collection, 0, len(data.Graph.EdgeDefinitions)) constraints := make([]VertexConstraints, 0, len(data.Graph.EdgeDefinitions)) for _, n := range data.Graph.EdgeDefinitions { ec, err := newEdgeCollection(n.Collection, g) if err != nil { return nil, nil, WithStack(err) } result = append(result, ec) constraints = append(constraints, VertexConstraints{ From: n.From, To: n.To, }) } return result, constraints, nil }
go
func (g *graph) EdgeCollections(ctx context.Context) ([]Collection, []VertexConstraints, error) { req, err := g.conn.NewRequest("GET", g.relPath()) if err != nil { return nil, nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, nil, WithStack(err) } var data getGraphResponse if err := resp.ParseBody("", &data); err != nil { return nil, nil, WithStack(err) } result := make([]Collection, 0, len(data.Graph.EdgeDefinitions)) constraints := make([]VertexConstraints, 0, len(data.Graph.EdgeDefinitions)) for _, n := range data.Graph.EdgeDefinitions { ec, err := newEdgeCollection(n.Collection, g) if err != nil { return nil, nil, WithStack(err) } result = append(result, ec) constraints = append(constraints, VertexConstraints{ From: n.From, To: n.To, }) } return result, constraints, nil }
[ "func", "(", "g", "*", "graph", ")", "EdgeCollections", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Collection", ",", "[", "]", "VertexConstraints", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "g", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "getGraphResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Collection", ",", "0", ",", "len", "(", "data", ".", "Graph", ".", "EdgeDefinitions", ")", ")", "\n", "constraints", ":=", "make", "(", "[", "]", "VertexConstraints", ",", "0", ",", "len", "(", "data", ".", "Graph", ".", "EdgeDefinitions", ")", ")", "\n", "for", "_", ",", "n", ":=", "range", "data", ".", "Graph", ".", "EdgeDefinitions", "{", "ec", ",", "err", ":=", "newEdgeCollection", "(", "n", ".", "Collection", ",", "g", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "ec", ")", "\n", "constraints", "=", "append", "(", "constraints", ",", "VertexConstraints", "{", "From", ":", "n", ".", "From", ",", "To", ":", "n", ".", "To", ",", "}", ")", "\n", "}", "\n", "return", "result", ",", "constraints", ",", "nil", "\n", "}" ]
// EdgeCollections returns all edge collections of this graph
[ "EdgeCollections", "returns", "all", "edge", "collections", "of", "this", "graph" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_edge_collections_impl.go#L96-L126
5,678
arangodb/go-driver
view_impl.go
newView
func newView(name string, viewType ViewType, db *database) (View, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if viewType == "" { return nil, WithStack(InvalidArgumentError{Message: "viewType is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &view{ name: name, viewType: viewType, db: db, conn: db.conn, }, nil }
go
func newView(name string, viewType ViewType, db *database) (View, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if viewType == "" { return nil, WithStack(InvalidArgumentError{Message: "viewType is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &view{ name: name, viewType: viewType, db: db, conn: db.conn, }, nil }
[ "func", "newView", "(", "name", "string", ",", "viewType", "ViewType", ",", "db", "*", "database", ")", "(", "View", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "viewType", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "db", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "view", "{", "name", ":", "name", ",", "viewType", ":", "viewType", ",", "db", ":", "db", ",", "conn", ":", "db", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newView creates a new View implementation.
[ "newView", "creates", "a", "new", "View", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/view_impl.go#L33-L49
5,679
arangodb/go-driver
view_impl.go
ArangoSearchView
func (v *view) ArangoSearchView() (ArangoSearchView, error) { if v.viewType != ViewTypeArangoSearch { return nil, WithStack(newArangoError(http.StatusConflict, 0, fmt.Sprintf("Type must be '%s', got '%s'", ViewTypeArangoSearch, v.viewType))) } return &viewArangoSearch{view: *v}, nil }
go
func (v *view) ArangoSearchView() (ArangoSearchView, error) { if v.viewType != ViewTypeArangoSearch { return nil, WithStack(newArangoError(http.StatusConflict, 0, fmt.Sprintf("Type must be '%s', got '%s'", ViewTypeArangoSearch, v.viewType))) } return &viewArangoSearch{view: *v}, nil }
[ "func", "(", "v", "*", "view", ")", "ArangoSearchView", "(", ")", "(", "ArangoSearchView", ",", "error", ")", "{", "if", "v", ".", "viewType", "!=", "ViewTypeArangoSearch", "{", "return", "nil", ",", "WithStack", "(", "newArangoError", "(", "http", ".", "StatusConflict", ",", "0", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ViewTypeArangoSearch", ",", "v", ".", "viewType", ")", ")", ")", "\n", "}", "\n", "return", "&", "viewArangoSearch", "{", "view", ":", "*", "v", "}", ",", "nil", "\n", "}" ]
// ArangoSearchView returns this view as an ArangoSearch view. // When the type of the view is not ArangoSearch, an error is returned.
[ "ArangoSearchView", "returns", "this", "view", "as", "an", "ArangoSearch", "view", ".", "When", "the", "type", "of", "the", "view", "is", "not", "ArangoSearch", "an", "error", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/view_impl.go#L76-L81
5,680
arangodb/go-driver
view_impl.go
Remove
func (v *view) Remove(ctx context.Context) error { req, err := v.conn.NewRequest("DELETE", v.relPath()) if err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := v.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (v *view) Remove(ctx context.Context) error { req, err := v.conn.NewRequest("DELETE", v.relPath()) if err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := v.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "v", "*", "view", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "v", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "v", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "v", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Remove removes the entire view. // If the view does not exist, a NotFoundError is returned.
[ "Remove", "removes", "the", "entire", "view", ".", "If", "the", "view", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/view_impl.go#L90-L104
5,681
arangodb/go-driver
cluster_impl.go
newCluster
func newCluster(conn Connection) (Cluster, error) { if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &cluster{ conn: conn, }, nil }
go
func newCluster(conn Connection) (Cluster, error) { if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &cluster{ conn: conn, }, nil }
[ "func", "newCluster", "(", "conn", "Connection", ")", "(", "Cluster", ",", "error", ")", "{", "if", "conn", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "cluster", "{", "conn", ":", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newCluster creates a new Cluster implementation.
[ "newCluster", "creates", "a", "new", "Cluster", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L33-L40
5,682
arangodb/go-driver
cluster_impl.go
MoveShard
func (c *cluster) MoveShard(ctx context.Context, col Collection, shard ShardID, fromServer, toServer ServerID) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/moveShard") if err != nil { return WithStack(err) } input := moveShardRequest{ Database: col.Database().Name(), Collection: col.Name(), Shard: shard, FromServer: fromServer, ToServer: toServer, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } return nil }
go
func (c *cluster) MoveShard(ctx context.Context, col Collection, shard ShardID, fromServer, toServer ServerID) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/moveShard") if err != nil { return WithStack(err) } input := moveShardRequest{ Database: col.Database().Name(), Collection: col.Name(), Shard: shard, FromServer: fromServer, ToServer: toServer, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(202); err != nil { return WithStack(err) } return nil }
[ "func", "(", "c", "*", "cluster", ")", "MoveShard", "(", "ctx", "context", ".", "Context", ",", "col", "Collection", ",", "shard", "ShardID", ",", "fromServer", ",", "toServer", "ServerID", ")", "error", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "moveShardRequest", "{", "Database", ":", "col", ".", "Database", "(", ")", ".", "Name", "(", ")", ",", "Collection", ":", "col", ".", "Name", "(", ")", ",", "Shard", ":", "shard", ",", "FromServer", ":", "fromServer", ",", "ToServer", ":", "toServer", ",", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MoveShard moves a single shard of the given collection from server `fromServer` to // server `toServer`.
[ "MoveShard", "moves", "a", "single", "shard", "of", "the", "given", "collection", "from", "server", "fromServer", "to", "server", "toServer", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L98-L122
5,683
arangodb/go-driver
cluster_impl.go
CleanOutServer
func (c *cluster) CleanOutServer(ctx context.Context, serverID string) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/cleanOutServer") if err != nil { return WithStack(err) } input := cleanOutServerRequest{ Server: serverID, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } cs := applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } var result cleanOutServerResponse if err := resp.ParseBody("", &result); err != nil { return WithStack(err) } if cs.JobIDResponse != nil { *cs.JobIDResponse = result.JobID } return nil }
go
func (c *cluster) CleanOutServer(ctx context.Context, serverID string) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/cleanOutServer") if err != nil { return WithStack(err) } input := cleanOutServerRequest{ Server: serverID, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } cs := applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } var result cleanOutServerResponse if err := resp.ParseBody("", &result); err != nil { return WithStack(err) } if cs.JobIDResponse != nil { *cs.JobIDResponse = result.JobID } return nil }
[ "func", "(", "c", "*", "cluster", ")", "CleanOutServer", "(", "ctx", "context", ".", "Context", ",", "serverID", "string", ")", "error", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "cleanOutServerRequest", "{", "Server", ":", "serverID", ",", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "cs", ":=", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "result", "cleanOutServerResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "cs", ".", "JobIDResponse", "!=", "nil", "{", "*", "cs", ".", "JobIDResponse", "=", "result", ".", "JobID", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CleanOutServer triggers activities to clean out a DBServers.
[ "CleanOutServer", "triggers", "activities", "to", "clean", "out", "a", "DBServers", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L133-L160
5,684
arangodb/go-driver
cluster_impl.go
IsCleanedOut
func (c *cluster) IsCleanedOut(ctx context.Context, serverID string) (bool, error) { r, err := c.NumberOfServers(ctx) if err != nil { return false, WithStack(err) } for _, id := range r.CleanedServerIDs { if id == serverID { return true, nil } } return false, nil }
go
func (c *cluster) IsCleanedOut(ctx context.Context, serverID string) (bool, error) { r, err := c.NumberOfServers(ctx) if err != nil { return false, WithStack(err) } for _, id := range r.CleanedServerIDs { if id == serverID { return true, nil } } return false, nil }
[ "func", "(", "c", "*", "cluster", ")", "IsCleanedOut", "(", "ctx", "context", ".", "Context", ",", "serverID", "string", ")", "(", "bool", ",", "error", ")", "{", "r", ",", "err", ":=", "c", ".", "NumberOfServers", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "id", ":=", "range", "r", ".", "CleanedServerIDs", "{", "if", "id", "==", "serverID", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// IsCleanedOut checks if the dbserver with given ID has been cleaned out.
[ "IsCleanedOut", "checks", "if", "the", "dbserver", "with", "given", "ID", "has", "been", "cleaned", "out", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L163-L174
5,685
arangodb/go-driver
cluster_impl.go
NumberOfServers
func (c *cluster) NumberOfServers(ctx context.Context) (NumberOfServersResponse, error) { req, err := c.conn.NewRequest("GET", "_admin/cluster/numberOfServers") if err != nil { return NumberOfServersResponse{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return NumberOfServersResponse{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return NumberOfServersResponse{}, WithStack(err) } var result NumberOfServersResponse if err := resp.ParseBody("", &result); err != nil { return NumberOfServersResponse{}, WithStack(err) } return result, nil }
go
func (c *cluster) NumberOfServers(ctx context.Context) (NumberOfServersResponse, error) { req, err := c.conn.NewRequest("GET", "_admin/cluster/numberOfServers") if err != nil { return NumberOfServersResponse{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return NumberOfServersResponse{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return NumberOfServersResponse{}, WithStack(err) } var result NumberOfServersResponse if err := resp.ParseBody("", &result); err != nil { return NumberOfServersResponse{}, WithStack(err) } return result, nil }
[ "func", "(", "c", "*", "cluster", ")", "NumberOfServers", "(", "ctx", "context", ".", "Context", ")", "(", "NumberOfServersResponse", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "NumberOfServersResponse", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "NumberOfServersResponse", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "NumberOfServersResponse", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "result", "NumberOfServersResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "NumberOfServersResponse", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// NumberOfServers returns the number of coordinator & dbservers in a clusters and the // ID's of cleaned out servers.
[ "NumberOfServers", "returns", "the", "number", "of", "coordinator", "&", "dbservers", "in", "a", "clusters", "and", "the", "ID", "s", "of", "cleaned", "out", "servers", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L185-L203
5,686
arangodb/go-driver
cluster_impl.go
RemoveServer
func (c *cluster) RemoveServer(ctx context.Context, serverID ServerID) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/removeServer") if err != nil { return WithStack(err) } if _, err := req.SetBody(serverID); err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } return nil }
go
func (c *cluster) RemoveServer(ctx context.Context, serverID ServerID) error { req, err := c.conn.NewRequest("POST", "_admin/cluster/removeServer") if err != nil { return WithStack(err) } if _, err := req.SetBody(serverID); err != nil { return WithStack(err) } applyContextSettings(ctx, req) resp, err := c.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200, 202); err != nil { return WithStack(err) } return nil }
[ "func", "(", "c", "*", "cluster", ")", "RemoveServer", "(", "ctx", "context", ".", "Context", ",", "serverID", "ServerID", ")", "error", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "serverID", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "c", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveServer is a low-level option to remove a server from a cluster. // This function is suitable for servers of type coordinator or dbserver. // The use of `ClientServerAdmin.Shutdown` is highly recommended above this function.
[ "RemoveServer", "is", "a", "low", "-", "level", "option", "to", "remove", "a", "server", "from", "a", "cluster", ".", "This", "function", "is", "suitable", "for", "servers", "of", "type", "coordinator", "or", "dbserver", ".", "The", "use", "of", "ClientServerAdmin", ".", "Shutdown", "is", "highly", "recommended", "above", "this", "function", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L208-L225
5,687
arangodb/go-driver
cluster_impl.go
UnmarshalJSON
func (p *InventoryCollectionParameters) UnmarshalJSON(d []byte) error { var internal inventoryCollectionParametersInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(internal) return nil }
go
func (p *InventoryCollectionParameters) UnmarshalJSON(d []byte) error { var internal inventoryCollectionParametersInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(internal) return nil }
[ "func", "(", "p", "*", "InventoryCollectionParameters", ")", "UnmarshalJSON", "(", "d", "[", "]", "byte", ")", "error", "{", "var", "internal", "inventoryCollectionParametersInternal", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "d", ",", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "fromInternal", "(", "internal", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON loads InventoryCollectionParameters from json
[ "UnmarshalJSON", "loads", "InventoryCollectionParameters", "from", "json" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L330-L338
5,688
arangodb/go-driver
cluster_impl.go
MarshalJSON
func (r replicationFactor) MarshalJSON() ([]byte, error) { var replicationFactor interface{} if int(r) == ReplicationFactorSatellite { replicationFactor = replicationFactorSatelliteString } else { replicationFactor = int(r) } return json.Marshal(replicationFactor) }
go
func (r replicationFactor) MarshalJSON() ([]byte, error) { var replicationFactor interface{} if int(r) == ReplicationFactorSatellite { replicationFactor = replicationFactorSatelliteString } else { replicationFactor = int(r) } return json.Marshal(replicationFactor) }
[ "func", "(", "r", "replicationFactor", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "replicationFactor", "interface", "{", "}", "\n\n", "if", "int", "(", "r", ")", "==", "ReplicationFactorSatellite", "{", "replicationFactor", "=", "replicationFactorSatelliteString", "\n", "}", "else", "{", "replicationFactor", "=", "int", "(", "r", ")", "\n", "}", "\n\n", "return", "json", ".", "Marshal", "(", "replicationFactor", ")", "\n", "}" ]
// MarshalJSON marshals InventoryCollectionParameters to arangodb json representation
[ "MarshalJSON", "marshals", "InventoryCollectionParameters", "to", "arangodb", "json", "representation" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L345-L355
5,689
arangodb/go-driver
cluster_impl.go
UnmarshalJSON
func (r *replicationFactor) UnmarshalJSON(d []byte) error { var internal interface{} if err := json.Unmarshal(d, &internal); err != nil { return err } if i, ok := internal.(float64); ok { *r = replicationFactor(i) return nil } else if str, ok := internal.(string); ok { if ok && str == replicationFactorSatelliteString { *r = replicationFactor(ReplicationFactorSatellite) return nil } } return &json.UnmarshalTypeError{ Value: string(d), Type: reflect.TypeOf(r).Elem(), } }
go
func (r *replicationFactor) UnmarshalJSON(d []byte) error { var internal interface{} if err := json.Unmarshal(d, &internal); err != nil { return err } if i, ok := internal.(float64); ok { *r = replicationFactor(i) return nil } else if str, ok := internal.(string); ok { if ok && str == replicationFactorSatelliteString { *r = replicationFactor(ReplicationFactorSatellite) return nil } } return &json.UnmarshalTypeError{ Value: string(d), Type: reflect.TypeOf(r).Elem(), } }
[ "func", "(", "r", "*", "replicationFactor", ")", "UnmarshalJSON", "(", "d", "[", "]", "byte", ")", "error", "{", "var", "internal", "interface", "{", "}", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "d", ",", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "i", ",", "ok", ":=", "internal", ".", "(", "float64", ")", ";", "ok", "{", "*", "r", "=", "replicationFactor", "(", "i", ")", "\n", "return", "nil", "\n", "}", "else", "if", "str", ",", "ok", ":=", "internal", ".", "(", "string", ")", ";", "ok", "{", "if", "ok", "&&", "str", "==", "replicationFactorSatelliteString", "{", "*", "r", "=", "replicationFactor", "(", "ReplicationFactorSatellite", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n\n", "return", "&", "json", ".", "UnmarshalTypeError", "{", "Value", ":", "string", "(", "d", ")", ",", "Type", ":", "reflect", ".", "TypeOf", "(", "r", ")", ".", "Elem", "(", ")", ",", "}", "\n", "}" ]
// UnmarshalJSON marshals InventoryCollectionParameters to arangodb json representation
[ "UnmarshalJSON", "marshals", "InventoryCollectionParameters", "to", "arangodb", "json", "representation" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster_impl.go#L358-L379
5,690
arangodb/go-driver
agency/agency_impl.go
NewAgency
func NewAgency(conn driver.Connection) (Agency, error) { return &agency{ conn: conn, }, nil }
go
func NewAgency(conn driver.Connection) (Agency, error) { return &agency{ conn: conn, }, nil }
[ "func", "NewAgency", "(", "conn", "driver", ".", "Connection", ")", "(", "Agency", ",", "error", ")", "{", "return", "&", "agency", "{", "conn", ":", "conn", ",", "}", ",", "nil", "\n", "}" ]
// NewAgency creates an Agency accessor for the given connection. // The connection must contain the endpoints of one or more agents, and only agents.
[ "NewAgency", "creates", "an", "Agency", "accessor", "for", "the", "given", "connection", ".", "The", "connection", "must", "contain", "the", "endpoints", "of", "one", "or", "more", "agents", "and", "only", "agents", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L46-L50
5,691
arangodb/go-driver
agency/agency_impl.go
ReadKey
func (c *agency) ReadKey(ctx context.Context, key []string, value interface{}) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/read") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) input := [][]string{{fullKey}} req, err = req.SetBody(input) if err != nil { return driver.WithStack(err) } //var raw []byte //ctx = driver.WithRawResponse(ctx, &raw) resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } //fmt.Printf("Agent response: %s\n", string(raw)) elems, err := resp.ParseArrayBody() if err != nil { return driver.WithStack(err) } if len(elems) != 1 { return driver.WithStack(fmt.Errorf("Expected 1 element, got %d", len(elems))) } // If empty key parse directly if len(key) == 0 { if err := elems[0].ParseBody("", &value); err != nil { return driver.WithStack(err) } } else { // Now remove all wrapping objects for each key element var rawObject map[string]interface{} if err := elems[0].ParseBody("", &rawObject); err != nil { return driver.WithStack(err) } var rawMsg interface{} for keyIndex := 0; keyIndex < len(key); keyIndex++ { if keyIndex > 0 { var ok bool rawObject, ok = rawMsg.(map[string]interface{}) if !ok { return driver.WithStack(fmt.Errorf("Data is not an object at key %s", key[:keyIndex+1])) } } var found bool rawMsg, found = rawObject[key[keyIndex]] if !found { return driver.WithStack(KeyNotFoundError{Key: key[:keyIndex+1]}) } } // Encode to json ... encoded, err := json.Marshal(rawMsg) if err != nil { return driver.WithStack(err) } // and decode back into result if err := json.Unmarshal(encoded, &value); err != nil { return driver.WithStack(err) } } // fmt.Printf("result as JSON: %s\n", rawResult) return nil }
go
func (c *agency) ReadKey(ctx context.Context, key []string, value interface{}) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/read") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) input := [][]string{{fullKey}} req, err = req.SetBody(input) if err != nil { return driver.WithStack(err) } //var raw []byte //ctx = driver.WithRawResponse(ctx, &raw) resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } //fmt.Printf("Agent response: %s\n", string(raw)) elems, err := resp.ParseArrayBody() if err != nil { return driver.WithStack(err) } if len(elems) != 1 { return driver.WithStack(fmt.Errorf("Expected 1 element, got %d", len(elems))) } // If empty key parse directly if len(key) == 0 { if err := elems[0].ParseBody("", &value); err != nil { return driver.WithStack(err) } } else { // Now remove all wrapping objects for each key element var rawObject map[string]interface{} if err := elems[0].ParseBody("", &rawObject); err != nil { return driver.WithStack(err) } var rawMsg interface{} for keyIndex := 0; keyIndex < len(key); keyIndex++ { if keyIndex > 0 { var ok bool rawObject, ok = rawMsg.(map[string]interface{}) if !ok { return driver.WithStack(fmt.Errorf("Data is not an object at key %s", key[:keyIndex+1])) } } var found bool rawMsg, found = rawObject[key[keyIndex]] if !found { return driver.WithStack(KeyNotFoundError{Key: key[:keyIndex+1]}) } } // Encode to json ... encoded, err := json.Marshal(rawMsg) if err != nil { return driver.WithStack(err) } // and decode back into result if err := json.Unmarshal(encoded, &value); err != nil { return driver.WithStack(err) } } // fmt.Printf("result as JSON: %s\n", rawResult) return nil }
[ "func", "(", "c", "*", "agency", ")", "ReadKey", "(", "ctx", "context", ".", "Context", ",", "key", "[", "]", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "conn", ":=", "c", ".", "conn", "\n", "req", ",", "err", ":=", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "fullKey", ":=", "createFullKey", "(", "key", ")", "\n", "input", ":=", "[", "]", "[", "]", "string", "{", "{", "fullKey", "}", "}", "\n", "req", ",", "err", "=", "req", ".", "SetBody", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "//var raw []byte", "//ctx = driver.WithRawResponse(ctx, &raw)", "resp", ",", "err", ":=", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "//fmt.Printf(\"Agent response: %s\\n\", string(raw))", "elems", ",", "err", ":=", "resp", ".", "ParseArrayBody", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "len", "(", "elems", ")", "!=", "1", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "elems", ")", ")", ")", "\n", "}", "\n", "// If empty key parse directly", "if", "len", "(", "key", ")", "==", "0", "{", "if", "err", ":=", "elems", "[", "0", "]", ".", "ParseBody", "(", "\"", "\"", ",", "&", "value", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "else", "{", "// Now remove all wrapping objects for each key element", "var", "rawObject", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "err", ":=", "elems", "[", "0", "]", ".", "ParseBody", "(", "\"", "\"", ",", "&", "rawObject", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "rawMsg", "interface", "{", "}", "\n", "for", "keyIndex", ":=", "0", ";", "keyIndex", "<", "len", "(", "key", ")", ";", "keyIndex", "++", "{", "if", "keyIndex", ">", "0", "{", "var", "ok", "bool", "\n", "rawObject", ",", "ok", "=", "rawMsg", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "!", "ok", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", "[", ":", "keyIndex", "+", "1", "]", ")", ")", "\n", "}", "\n", "}", "\n", "var", "found", "bool", "\n", "rawMsg", ",", "found", "=", "rawObject", "[", "key", "[", "keyIndex", "]", "]", "\n", "if", "!", "found", "{", "return", "driver", ".", "WithStack", "(", "KeyNotFoundError", "{", "Key", ":", "key", "[", ":", "keyIndex", "+", "1", "]", "}", ")", "\n", "}", "\n", "}", "\n", "// Encode to json ...", "encoded", ",", "err", ":=", "json", ".", "Marshal", "(", "rawMsg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "// and decode back into result", "if", "err", ":=", "json", ".", "Unmarshal", "(", "encoded", ",", "&", "value", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n\n", "//\tfmt.Printf(\"result as JSON: %s\\n\", rawResult)", "return", "nil", "\n", "}" ]
// ReadKey reads the value of a given key in the agency.
[ "ReadKey", "reads", "the", "value", "of", "a", "given", "key", "in", "the", "agency", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L58-L126
5,692
arangodb/go-driver
agency/agency_impl.go
WriteKeyIfEmpty
func (c *agency) WriteKeyIfEmpty(ctx context.Context, key []string, value interface{}, ttl time.Duration) error { var cond WriteCondition cond = cond.IfEmpty(key) if err := c.write(ctx, "set", key, value, cond, ttl); err != nil { return driver.WithStack(err) } return nil }
go
func (c *agency) WriteKeyIfEmpty(ctx context.Context, key []string, value interface{}, ttl time.Duration) error { var cond WriteCondition cond = cond.IfEmpty(key) if err := c.write(ctx, "set", key, value, cond, ttl); err != nil { return driver.WithStack(err) } return nil }
[ "func", "(", "c", "*", "agency", ")", "WriteKeyIfEmpty", "(", "ctx", "context", ".", "Context", ",", "key", "[", "]", "string", ",", "value", "interface", "{", "}", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "var", "cond", "WriteCondition", "\n", "cond", "=", "cond", ".", "IfEmpty", "(", "key", ")", "\n", "if", "err", ":=", "c", ".", "write", "(", "ctx", ",", "\"", "\"", ",", "key", ",", "value", ",", "cond", ",", "ttl", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteKeyIfEmpty writes the given value with the given key only if the key was empty before.
[ "WriteKeyIfEmpty", "writes", "the", "given", "value", "with", "the", "given", "key", "only", "if", "the", "key", "was", "empty", "before", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L168-L175
5,693
arangodb/go-driver
agency/agency_impl.go
WriteKeyIfEqualTo
func (c *agency) WriteKeyIfEqualTo(ctx context.Context, key []string, newValue, oldValue interface{}, ttl time.Duration) error { var cond WriteCondition cond = cond.IfEqualTo(key, oldValue) if err := c.write(ctx, "set", key, newValue, cond, ttl); err != nil { return driver.WithStack(err) } return nil }
go
func (c *agency) WriteKeyIfEqualTo(ctx context.Context, key []string, newValue, oldValue interface{}, ttl time.Duration) error { var cond WriteCondition cond = cond.IfEqualTo(key, oldValue) if err := c.write(ctx, "set", key, newValue, cond, ttl); err != nil { return driver.WithStack(err) } return nil }
[ "func", "(", "c", "*", "agency", ")", "WriteKeyIfEqualTo", "(", "ctx", "context", ".", "Context", ",", "key", "[", "]", "string", ",", "newValue", ",", "oldValue", "interface", "{", "}", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "var", "cond", "WriteCondition", "\n", "cond", "=", "cond", ".", "IfEqualTo", "(", "key", ",", "oldValue", ")", "\n", "if", "err", ":=", "c", ".", "write", "(", "ctx", ",", "\"", "\"", ",", "key", ",", "newValue", ",", "cond", ",", "ttl", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteKeyIfEqualTo writes the given new value with the given key only if the existing value for that key equals // to the given old value.
[ "WriteKeyIfEqualTo", "writes", "the", "given", "new", "value", "with", "the", "given", "key", "only", "if", "the", "existing", "value", "for", "that", "key", "equals", "to", "the", "given", "old", "value", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L179-L186
5,694
arangodb/go-driver
agency/agency_impl.go
write
func (c *agency) write(ctx context.Context, operation string, key []string, value interface{}, condition WriteCondition, ttl time.Duration) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/write") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) writeTxs := writeTransactions{ writeTransaction{ // Update map[string]interface{}{ fullKey: writeUpdate{ Operation: operation, New: value, TTL: int64(ttl.Seconds()), }, }, // Condition condition.toMap(), }, } req, err = req.SetBody(writeTxs) if err != nil { return driver.WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } var result writeResult if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } if err := resp.ParseBody("", &result); err != nil { return driver.WithStack(err) } // "results" should be 1 long if len(result.Results) != 1 { return driver.WithStack(fmt.Errorf("Expected results of 1 long, got %d", len(result.Results))) } // If results[0] == 0, condition failed, otherwise success if result.Results[0] == 0 { // Condition failed return driver.WithStack(preconditionFailedError) } // Success return nil }
go
func (c *agency) write(ctx context.Context, operation string, key []string, value interface{}, condition WriteCondition, ttl time.Duration) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/write") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) writeTxs := writeTransactions{ writeTransaction{ // Update map[string]interface{}{ fullKey: writeUpdate{ Operation: operation, New: value, TTL: int64(ttl.Seconds()), }, }, // Condition condition.toMap(), }, } req, err = req.SetBody(writeTxs) if err != nil { return driver.WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } var result writeResult if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } if err := resp.ParseBody("", &result); err != nil { return driver.WithStack(err) } // "results" should be 1 long if len(result.Results) != 1 { return driver.WithStack(fmt.Errorf("Expected results of 1 long, got %d", len(result.Results))) } // If results[0] == 0, condition failed, otherwise success if result.Results[0] == 0 { // Condition failed return driver.WithStack(preconditionFailedError) } // Success return nil }
[ "func", "(", "c", "*", "agency", ")", "write", "(", "ctx", "context", ".", "Context", ",", "operation", "string", ",", "key", "[", "]", "string", ",", "value", "interface", "{", "}", ",", "condition", "WriteCondition", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "conn", ":=", "c", ".", "conn", "\n", "req", ",", "err", ":=", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "fullKey", ":=", "createFullKey", "(", "key", ")", "\n", "writeTxs", ":=", "writeTransactions", "{", "writeTransaction", "{", "// Update", "map", "[", "string", "]", "interface", "{", "}", "{", "fullKey", ":", "writeUpdate", "{", "Operation", ":", "operation", ",", "New", ":", "value", ",", "TTL", ":", "int64", "(", "ttl", ".", "Seconds", "(", ")", ")", ",", "}", ",", "}", ",", "// Condition", "condition", ".", "toMap", "(", ")", ",", "}", ",", "}", "\n", "req", ",", "err", "=", "req", ".", "SetBody", "(", "writeTxs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "var", "result", "writeResult", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// \"results\" should be 1 long", "if", "len", "(", "result", ".", "Results", ")", "!=", "1", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "result", ".", "Results", ")", ")", ")", "\n", "}", "\n\n", "// If results[0] == 0, condition failed, otherwise success", "if", "result", ".", "Results", "[", "0", "]", "==", "0", "{", "// Condition failed", "return", "driver", ".", "WithStack", "(", "preconditionFailedError", ")", "\n", "}", "\n\n", "// Success", "return", "nil", "\n", "}" ]
// write writes the given value with the given key only if the given condition is fullfilled.
[ "write", "writes", "the", "given", "value", "with", "the", "given", "key", "only", "if", "the", "given", "condition", "is", "fullfilled", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L189-L241
5,695
arangodb/go-driver
agency/agency_impl.go
RemoveKeyIfEqualTo
func (c *agency) RemoveKeyIfEqualTo(ctx context.Context, key []string, oldValue interface{}) error { var cond WriteCondition cond = cond.IfEqualTo(key, oldValue) if err := c.write(ctx, "delete", key, nil, cond, 0); err != nil { return driver.WithStack(err) } return nil }
go
func (c *agency) RemoveKeyIfEqualTo(ctx context.Context, key []string, oldValue interface{}) error { var cond WriteCondition cond = cond.IfEqualTo(key, oldValue) if err := c.write(ctx, "delete", key, nil, cond, 0); err != nil { return driver.WithStack(err) } return nil }
[ "func", "(", "c", "*", "agency", ")", "RemoveKeyIfEqualTo", "(", "ctx", "context", ".", "Context", ",", "key", "[", "]", "string", ",", "oldValue", "interface", "{", "}", ")", "error", "{", "var", "cond", "WriteCondition", "\n", "cond", "=", "cond", ".", "IfEqualTo", "(", "key", ",", "oldValue", ")", "\n", "if", "err", ":=", "c", ".", "write", "(", "ctx", ",", "\"", "\"", ",", "key", ",", "nil", ",", "cond", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveKeyIfEqualTo removes the given key only if the existing value for that key equals // to the given old value.
[ "RemoveKeyIfEqualTo", "removes", "the", "given", "key", "only", "if", "the", "existing", "value", "for", "that", "key", "equals", "to", "the", "given", "old", "value", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L264-L271
5,696
arangodb/go-driver
agency/agency_impl.go
RegisterChangeCallback
func (c *agency) RegisterChangeCallback(ctx context.Context, key []string, cbURL string) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/write") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) writeTxs := writeTransactions{ writeTransaction{ // Update map[string]interface{}{ fullKey: writeUpdate{ Operation: "observe", URL: cbURL, }, }, }, } req, err = req.SetBody(writeTxs) if err != nil { return driver.WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } var result writeResult if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } if err := resp.ParseBody("", &result); err != nil { return driver.WithStack(err) } // "results" should be 1 long if len(result.Results) != 1 { return driver.WithStack(fmt.Errorf("Expected results of 1 long, got %d", len(result.Results))) } // Success return nil }
go
func (c *agency) RegisterChangeCallback(ctx context.Context, key []string, cbURL string) error { conn := c.conn req, err := conn.NewRequest("POST", "_api/agency/write") if err != nil { return driver.WithStack(err) } fullKey := createFullKey(key) writeTxs := writeTransactions{ writeTransaction{ // Update map[string]interface{}{ fullKey: writeUpdate{ Operation: "observe", URL: cbURL, }, }, }, } req, err = req.SetBody(writeTxs) if err != nil { return driver.WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return driver.WithStack(err) } var result writeResult if err := resp.CheckStatus(200, 201, 202); err != nil { return driver.WithStack(err) } if err := resp.ParseBody("", &result); err != nil { return driver.WithStack(err) } // "results" should be 1 long if len(result.Results) != 1 { return driver.WithStack(fmt.Errorf("Expected results of 1 long, got %d", len(result.Results))) } // Success return nil }
[ "func", "(", "c", "*", "agency", ")", "RegisterChangeCallback", "(", "ctx", "context", ".", "Context", ",", "key", "[", "]", "string", ",", "cbURL", "string", ")", "error", "{", "conn", ":=", "c", ".", "conn", "\n", "req", ",", "err", ":=", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "fullKey", ":=", "createFullKey", "(", "key", ")", "\n", "writeTxs", ":=", "writeTransactions", "{", "writeTransaction", "{", "// Update", "map", "[", "string", "]", "interface", "{", "}", "{", "fullKey", ":", "writeUpdate", "{", "Operation", ":", "\"", "\"", ",", "URL", ":", "cbURL", ",", "}", ",", "}", ",", "}", ",", "}", "\n\n", "req", ",", "err", "=", "req", ".", "SetBody", "(", "writeTxs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "var", "result", "writeResult", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// \"results\" should be 1 long", "if", "len", "(", "result", ".", "Results", ")", "!=", "1", "{", "return", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "result", ".", "Results", ")", ")", ")", "\n", "}", "\n\n", "// Success", "return", "nil", "\n", "}" ]
// Register a URL to receive notification callbacks when the value of the given key changes
[ "Register", "a", "URL", "to", "receive", "notification", "callbacks", "when", "the", "value", "of", "the", "given", "key", "changes" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_impl.go#L274-L318
5,697
arangodb/go-driver
jwt/jwt.go
CreateArangodJwtAuthorizationHeader
func CreateArangodJwtAuthorizationHeader(jwtSecret, serverID string) (string, error) { if jwtSecret == "" || serverID == "" { return "", nil } // Create a new token object, specifying signing method and the claims // you would like it to contain. token := jg.NewWithClaims(jg.SigningMethodHS256, jg.MapClaims{ "iss": issArangod, "server_id": serverID, }) // Sign and get the complete encoded token as a string using the secret signedToken, err := token.SignedString([]byte(jwtSecret)) if err != nil { return "", driver.WithStack(err) } return "bearer " + signedToken, nil }
go
func CreateArangodJwtAuthorizationHeader(jwtSecret, serverID string) (string, error) { if jwtSecret == "" || serverID == "" { return "", nil } // Create a new token object, specifying signing method and the claims // you would like it to contain. token := jg.NewWithClaims(jg.SigningMethodHS256, jg.MapClaims{ "iss": issArangod, "server_id": serverID, }) // Sign and get the complete encoded token as a string using the secret signedToken, err := token.SignedString([]byte(jwtSecret)) if err != nil { return "", driver.WithStack(err) } return "bearer " + signedToken, nil }
[ "func", "CreateArangodJwtAuthorizationHeader", "(", "jwtSecret", ",", "serverID", "string", ")", "(", "string", ",", "error", ")", "{", "if", "jwtSecret", "==", "\"", "\"", "||", "serverID", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "// Create a new token object, specifying signing method and the claims", "// you would like it to contain.", "token", ":=", "jg", ".", "NewWithClaims", "(", "jg", ".", "SigningMethodHS256", ",", "jg", ".", "MapClaims", "{", "\"", "\"", ":", "issArangod", ",", "\"", "\"", ":", "serverID", ",", "}", ")", "\n\n", "// Sign and get the complete encoded token as a string using the secret", "signedToken", ",", "err", ":=", "token", ".", "SignedString", "(", "[", "]", "byte", "(", "jwtSecret", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "return", "\"", "\"", "+", "signedToken", ",", "nil", "\n", "}" ]
// CreateArangodJwtAuthorizationHeader calculates a JWT authorization header, for authorization // of a request to an arangod server, based on the given secret. // If the secret is empty, nothing is done. // Use the result of this function as input for driver.RawAuthentication.
[ "CreateArangodJwtAuthorizationHeader", "calculates", "a", "JWT", "authorization", "header", "for", "authorization", "of", "a", "request", "to", "an", "arangod", "server", "based", "on", "the", "given", "secret", ".", "If", "the", "secret", "is", "empty", "nothing", "is", "done", ".", "Use", "the", "result", "of", "this", "function", "as", "input", "for", "driver", ".", "RawAuthentication", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/jwt/jwt.go#L38-L56
5,698
arangodb/go-driver
http/response_json.go
decodeObjectFields
func decodeObjectFields(objValue reflect.Value, body map[string]*json.RawMessage) error { objValueType := objValue.Type() for i := 0; i != objValue.NumField(); i++ { f := objValueType.Field(i) if f.Anonymous { // Recurse into fields of anonymous field if err := decodeObjectFields(objValue.Field(i), body); err != nil { return driver.WithStack(err) } } else { // Decode individual field jsonName := strings.Split(f.Tag.Get("json"), ",")[0] if jsonName == "" { jsonName = f.Name } else if jsonName == "-" { continue } raw, ok := body[jsonName] if ok && raw != nil { field := objValue.Field(i) if err := json.Unmarshal(*raw, field.Addr().Interface()); err != nil { return driver.WithStack(err) } } } } return nil }
go
func decodeObjectFields(objValue reflect.Value, body map[string]*json.RawMessage) error { objValueType := objValue.Type() for i := 0; i != objValue.NumField(); i++ { f := objValueType.Field(i) if f.Anonymous { // Recurse into fields of anonymous field if err := decodeObjectFields(objValue.Field(i), body); err != nil { return driver.WithStack(err) } } else { // Decode individual field jsonName := strings.Split(f.Tag.Get("json"), ",")[0] if jsonName == "" { jsonName = f.Name } else if jsonName == "-" { continue } raw, ok := body[jsonName] if ok && raw != nil { field := objValue.Field(i) if err := json.Unmarshal(*raw, field.Addr().Interface()); err != nil { return driver.WithStack(err) } } } } return nil }
[ "func", "decodeObjectFields", "(", "objValue", "reflect", ".", "Value", ",", "body", "map", "[", "string", "]", "*", "json", ".", "RawMessage", ")", "error", "{", "objValueType", ":=", "objValue", ".", "Type", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "!=", "objValue", ".", "NumField", "(", ")", ";", "i", "++", "{", "f", ":=", "objValueType", ".", "Field", "(", "i", ")", "\n", "if", "f", ".", "Anonymous", "{", "// Recurse into fields of anonymous field", "if", "err", ":=", "decodeObjectFields", "(", "objValue", ".", "Field", "(", "i", ")", ",", "body", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "else", "{", "// Decode individual field", "jsonName", ":=", "strings", ".", "Split", "(", "f", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "[", "0", "]", "\n", "if", "jsonName", "==", "\"", "\"", "{", "jsonName", "=", "f", ".", "Name", "\n", "}", "else", "if", "jsonName", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "raw", ",", "ok", ":=", "body", "[", "jsonName", "]", "\n", "if", "ok", "&&", "raw", "!=", "nil", "{", "field", ":=", "objValue", ".", "Field", "(", "i", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "*", "raw", ",", "field", ".", "Addr", "(", ")", ".", "Interface", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// decodeObjectFields decodes fields from the given body into a objValue of kind struct.
[ "decodeObjectFields", "decodes", "fields", "from", "the", "given", "body", "into", "a", "objValue", "of", "kind", "struct", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/response_json.go#L157-L184
5,699
arangodb/go-driver
http/response_json.go
decodeMapFields
func decodeMapFields(val reflect.Value, body map[string]*json.RawMessage) error { mapVal := val if mapVal.IsNil() { valType := val.Type() mapType := reflect.MapOf(valType.Key(), valType.Elem()) mapVal = reflect.MakeMap(mapType) } for jsonName, raw := range body { var value interface{} if raw != nil { if err := json.Unmarshal(*raw, &value); err != nil { return driver.WithStack(err) } } mapVal.SetMapIndex(reflect.ValueOf(jsonName), reflect.ValueOf(value)) } val.Set(mapVal) return nil }
go
func decodeMapFields(val reflect.Value, body map[string]*json.RawMessage) error { mapVal := val if mapVal.IsNil() { valType := val.Type() mapType := reflect.MapOf(valType.Key(), valType.Elem()) mapVal = reflect.MakeMap(mapType) } for jsonName, raw := range body { var value interface{} if raw != nil { if err := json.Unmarshal(*raw, &value); err != nil { return driver.WithStack(err) } } mapVal.SetMapIndex(reflect.ValueOf(jsonName), reflect.ValueOf(value)) } val.Set(mapVal) return nil }
[ "func", "decodeMapFields", "(", "val", "reflect", ".", "Value", ",", "body", "map", "[", "string", "]", "*", "json", ".", "RawMessage", ")", "error", "{", "mapVal", ":=", "val", "\n", "if", "mapVal", ".", "IsNil", "(", ")", "{", "valType", ":=", "val", ".", "Type", "(", ")", "\n", "mapType", ":=", "reflect", ".", "MapOf", "(", "valType", ".", "Key", "(", ")", ",", "valType", ".", "Elem", "(", ")", ")", "\n", "mapVal", "=", "reflect", ".", "MakeMap", "(", "mapType", ")", "\n", "}", "\n", "for", "jsonName", ",", "raw", ":=", "range", "body", "{", "var", "value", "interface", "{", "}", "\n", "if", "raw", "!=", "nil", "{", "if", "err", ":=", "json", ".", "Unmarshal", "(", "*", "raw", ",", "&", "value", ")", ";", "err", "!=", "nil", "{", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "mapVal", ".", "SetMapIndex", "(", "reflect", ".", "ValueOf", "(", "jsonName", ")", ",", "reflect", ".", "ValueOf", "(", "value", ")", ")", "\n", "}", "\n", "val", ".", "Set", "(", "mapVal", ")", "\n", "return", "nil", "\n", "}" ]
// decodeMapFields decodes fields from the given body into a mapValue of kind map.
[ "decodeMapFields", "decodes", "fields", "from", "the", "given", "body", "into", "a", "mapValue", "of", "kind", "map", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/response_json.go#L187-L205