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,700
arangodb/go-driver
database_impl.go
newDatabase
func newDatabase(name string, conn Connection) (Database, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &database{ name: name, conn: conn, }, nil }
go
func newDatabase(name string, conn Connection) (Database, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if conn == nil { return nil, WithStack(InvalidArgumentError{Message: "conn is nil"}) } return &database{ name: name, conn: conn, }, nil }
[ "func", "newDatabase", "(", "name", "string", ",", "conn", "Connection", ")", "(", "Database", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "conn", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "database", "{", "name", ":", "name", ",", "conn", ":", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newDatabase creates a new Database implementation.
[ "newDatabase", "creates", "a", "new", "Database", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_impl.go#L32-L43
5,701
arangodb/go-driver
database_impl.go
Info
func (d *database) Info(ctx context.Context) (DatabaseInfo, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/database/current")) if err != nil { return DatabaseInfo{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return DatabaseInfo{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return DatabaseInfo{}, WithStack(err) } var data DatabaseInfo if err := resp.ParseBody("result", &data); err != nil { return DatabaseInfo{}, WithStack(err) } return data, nil }
go
func (d *database) Info(ctx context.Context) (DatabaseInfo, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/database/current")) if err != nil { return DatabaseInfo{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return DatabaseInfo{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return DatabaseInfo{}, WithStack(err) } var data DatabaseInfo if err := resp.ParseBody("result", &data); err != nil { return DatabaseInfo{}, WithStack(err) } return data, nil }
[ "func", "(", "d", "*", "database", ")", "Info", "(", "ctx", "context", ".", "Context", ")", "(", "DatabaseInfo", ",", "error", ")", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DatabaseInfo", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "d", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DatabaseInfo", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "DatabaseInfo", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "DatabaseInfo", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "DatabaseInfo", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// Info fetches information about the database.
[ "Info", "fetches", "information", "about", "the", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_impl.go#L63-L81
5,702
arangodb/go-driver
database_impl.go
Remove
func (d *database) Remove(ctx context.Context) error { req, err := d.conn.NewRequest("DELETE", path.Join("_db/_system/_api/database", pathEscape(d.name))) if err != nil { return WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (d *database) Remove(ctx context.Context) error { req, err := d.conn.NewRequest("DELETE", path.Join("_db/_system/_api/database", pathEscape(d.name))) if err != nil { return WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "d", "*", "database", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "pathEscape", "(", "d", ".", "name", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "d", ".", "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 database. // If the database does not exist, a NotFoundError is returned.
[ "Remove", "removes", "the", "entire", "database", ".", "If", "the", "database", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_impl.go#L113-L126
5,703
arangodb/go-driver
database_impl.go
Query
func (d *database) Query(ctx context.Context, query string, bindVars map[string]interface{}) (Cursor, error) { req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/cursor")) if err != nil { return nil, WithStack(err) } input := queryRequest{ Query: query, BindVars: bindVars, } input.applyContextSettings(ctx) if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } cs := applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } var data cursorData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } col, err := newCursor(data, resp.Endpoint(), d, cs.AllowDirtyReads) if err != nil { return nil, WithStack(err) } return col, nil }
go
func (d *database) Query(ctx context.Context, query string, bindVars map[string]interface{}) (Cursor, error) { req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/cursor")) if err != nil { return nil, WithStack(err) } input := queryRequest{ Query: query, BindVars: bindVars, } input.applyContextSettings(ctx) if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } cs := applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } var data cursorData if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } col, err := newCursor(data, resp.Endpoint(), d, cs.AllowDirtyReads) if err != nil { return nil, WithStack(err) } return col, nil }
[ "func", "(", "d", "*", "database", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "query", "string", ",", "bindVars", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "Cursor", ",", "error", ")", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "queryRequest", "{", "Query", ":", "query", ",", "BindVars", ":", "bindVars", ",", "}", "\n", "input", ".", "applyContextSettings", "(", "ctx", ")", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "cs", ":=", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "d", ".", "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", "cursorData", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "col", ",", "err", ":=", "newCursor", "(", "data", ",", "resp", ".", "Endpoint", "(", ")", ",", "d", ",", "cs", ".", "AllowDirtyReads", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "col", ",", "nil", "\n", "}" ]
// Query performs an AQL query, returning a cursor used to iterate over the returned documents.
[ "Query", "performs", "an", "AQL", "query", "returning", "a", "cursor", "used", "to", "iterate", "over", "the", "returned", "documents", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_impl.go#L129-L159
5,704
arangodb/go-driver
database_impl.go
ValidateQuery
func (d *database) ValidateQuery(ctx context.Context, query string) error { req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/query")) if err != nil { return WithStack(err) } input := parseQueryRequest{ Query: query, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
go
func (d *database) ValidateQuery(ctx context.Context, query string) error { req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/query")) if err != nil { return WithStack(err) } input := parseQueryRequest{ Query: query, } if _, err := req.SetBody(input); err != nil { return WithStack(err) } resp, err := d.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(200); err != nil { return WithStack(err) } return nil }
[ "func", "(", "d", "*", "database", ")", "ValidateQuery", "(", "ctx", "context", ".", "Context", ",", "query", "string", ")", "error", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "input", ":=", "parseQueryRequest", "{", "Query", ":", "query", ",", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "input", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "d", ".", "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", "}" ]
// ValidateQuery validates an AQL query. // When the query is valid, nil returned, otherwise an error is returned. // The query is not executed.
[ "ValidateQuery", "validates", "an", "AQL", "query", ".", "When", "the", "query", "is", "valid", "nil", "returned", "otherwise", "an", "error", "is", "returned", ".", "The", "query", "is", "not", "executed", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_impl.go#L164-L183
5,705
arangodb/go-driver
client_databases_impl.go
Database
func (c *client) Database(ctx context.Context, name string) (Database, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_db", escapedName, "_api/database/current")) 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) } db, err := newDatabase(name, c.conn) if err != nil { return nil, WithStack(err) } return db, nil }
go
func (c *client) Database(ctx context.Context, name string) (Database, error) { escapedName := pathEscape(name) req, err := c.conn.NewRequest("GET", path.Join("_db", escapedName, "_api/database/current")) 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) } db, err := newDatabase(name, c.conn) if err != nil { return nil, WithStack(err) } return db, nil }
[ "func", "(", "c", "*", "client", ")", "Database", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "Database", ",", "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", "db", ",", "err", ":=", "newDatabase", "(", "name", ",", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "db", ",", "nil", "\n", "}" ]
// Database opens a connection to an existing database. // If no database with given name exists, an NotFoundError is returned.
[ "Database", "opens", "a", "connection", "to", "an", "existing", "database", ".", "If", "no", "database", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_databases_impl.go#L32-L50
5,706
arangodb/go-driver
client_databases_impl.go
AccessibleDatabases
func (c *client) AccessibleDatabases(ctx context.Context) ([]Database, error) { result, err := listDatabases(ctx, c.conn, path.Join("/_db/_system/_api/database/user")) if err != nil { return nil, WithStack(err) } return result, nil }
go
func (c *client) AccessibleDatabases(ctx context.Context) ([]Database, error) { result, err := listDatabases(ctx, c.conn, path.Join("/_db/_system/_api/database/user")) if err != nil { return nil, WithStack(err) } return result, nil }
[ "func", "(", "c", "*", "client", ")", "AccessibleDatabases", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Database", ",", "error", ")", "{", "result", ",", "err", ":=", "listDatabases", "(", "ctx", ",", "c", ".", "conn", ",", "path", ".", "Join", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// AccessibleDatabases returns a list of all databases that can be accessed by the authenticated user.
[ "AccessibleDatabases", "returns", "a", "list", "of", "all", "databases", "that", "can", "be", "accessed", "by", "the", "authenticated", "user", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_databases_impl.go#L86-L92
5,707
arangodb/go-driver
client_databases_impl.go
listDatabases
func listDatabases(ctx context.Context, conn Connection, path string) ([]Database, error) { req, err := conn.NewRequest("GET", path) if err != nil { return nil, WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data getDatabaseResponse 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, conn) if err != nil { return nil, WithStack(err) } result = append(result, db) } return result, nil }
go
func listDatabases(ctx context.Context, conn Connection, path string) ([]Database, error) { req, err := conn.NewRequest("GET", path) if err != nil { return nil, WithStack(err) } resp, err := conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data getDatabaseResponse 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, conn) if err != nil { return nil, WithStack(err) } result = append(result, db) } return result, nil }
[ "func", "listDatabases", "(", "ctx", "context", ".", "Context", ",", "conn", "Connection", ",", "path", "string", ")", "(", "[", "]", "Database", ",", "error", ")", "{", "req", ",", "err", ":=", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "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", "getDatabaseResponse", "\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", ",", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "db", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// listDatabases returns a list of databases using a GET to the given path.
[ "listDatabases", "returns", "a", "list", "of", "databases", "using", "a", "GET", "to", "the", "given", "path", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_databases_impl.go#L95-L120
5,708
arangodb/go-driver
client_databases_impl.go
CreateDatabase
func (c *client) CreateDatabase(ctx context.Context, name string, options *CreateDatabaseOptions) (Database, error) { input := struct { CreateDatabaseOptions Name string `json:"name"` }{ Name: name, } if options != nil { input.CreateDatabaseOptions = *options } req, err := c.conn.NewRequest("POST", path.Join("_db/_system/_api/database")) 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) } db, err := newDatabase(name, c.conn) if err != nil { return nil, WithStack(err) } return db, nil }
go
func (c *client) CreateDatabase(ctx context.Context, name string, options *CreateDatabaseOptions) (Database, error) { input := struct { CreateDatabaseOptions Name string `json:"name"` }{ Name: name, } if options != nil { input.CreateDatabaseOptions = *options } req, err := c.conn.NewRequest("POST", path.Join("_db/_system/_api/database")) 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) } db, err := newDatabase(name, c.conn) if err != nil { return nil, WithStack(err) } return db, nil }
[ "func", "(", "c", "*", "client", ")", "CreateDatabase", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "options", "*", "CreateDatabaseOptions", ")", "(", "Database", ",", "error", ")", "{", "input", ":=", "struct", "{", "CreateDatabaseOptions", "\n", "Name", "string", "`json:\"name\"`", "\n", "}", "{", "Name", ":", "name", ",", "}", "\n", "if", "options", "!=", "nil", "{", "input", ".", "CreateDatabaseOptions", "=", "*", "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", "db", ",", "err", ":=", "newDatabase", "(", "name", ",", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "db", ",", "nil", "\n", "}" ]
// CreateDatabase creates a new database with given name and opens a connection to it. // If the a database with given name already exists, a DuplicateError is returned.
[ "CreateDatabase", "creates", "a", "new", "database", "with", "given", "name", "and", "opens", "a", "connection", "to", "it", ".", "If", "the", "a", "database", "with", "given", "name", "already", "exists", "a", "DuplicateError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_databases_impl.go#L124-L153
5,709
arangodb/go-driver
client_cluster_impl.go
Cluster
func (c *client) Cluster(ctx context.Context) (Cluster, error) { role, err := c.ServerRole(ctx) if err != nil { return nil, WithStack(err) } if role == ServerRoleSingle || role == ServerRoleSingleActive || role == ServerRoleSinglePassive { // Standalone server, this is wrong return nil, WithStack(newArangoError(412, 0, "Cluster expected, found SINGLE server")) } cl, err := newCluster(c.conn) if err != nil { return nil, WithStack(err) } return cl, nil }
go
func (c *client) Cluster(ctx context.Context) (Cluster, error) { role, err := c.ServerRole(ctx) if err != nil { return nil, WithStack(err) } if role == ServerRoleSingle || role == ServerRoleSingleActive || role == ServerRoleSinglePassive { // Standalone server, this is wrong return nil, WithStack(newArangoError(412, 0, "Cluster expected, found SINGLE server")) } cl, err := newCluster(c.conn) if err != nil { return nil, WithStack(err) } return cl, nil }
[ "func", "(", "c", "*", "client", ")", "Cluster", "(", "ctx", "context", ".", "Context", ")", "(", "Cluster", ",", "error", ")", "{", "role", ",", "err", ":=", "c", ".", "ServerRole", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "role", "==", "ServerRoleSingle", "||", "role", "==", "ServerRoleSingleActive", "||", "role", "==", "ServerRoleSinglePassive", "{", "// Standalone server, this is wrong", "return", "nil", ",", "WithStack", "(", "newArangoError", "(", "412", ",", "0", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "cl", ",", "err", ":=", "newCluster", "(", "c", ".", "conn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "cl", ",", "nil", "\n", "}" ]
// Cluster provides access to cluster wide specific operations. // To use this interface, an ArangoDB cluster is required. // If this method is a called without a cluster, a PreconditionFailed error is returned.
[ "Cluster", "provides", "access", "to", "cluster", "wide", "specific", "operations", ".", "To", "use", "this", "interface", "an", "ArangoDB", "cluster", "is", "required", ".", "If", "this", "method", "is", "a", "called", "without", "a", "cluster", "a", "PreconditionFailed", "error", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_cluster_impl.go#L32-L46
5,710
arangodb/go-driver
replication_impl.go
CreateBatch
func (c *client) CreateBatch(ctx context.Context, db Database, serverID int64, ttl time.Duration) (Batch, error) { req, err := c.conn.NewRequest("POST", path.Join("_db", db.Name(), "_api/replication/batch")) if err != nil { return nil, WithStack(err) } req = req.SetQuery("serverId", strconv.FormatInt(serverID, 10)) params := struct { TTL float64 `json:"ttl"` }{TTL: ttl.Seconds()} // just use a default ttl value req, err = req.SetBody(params) 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 batch batchMetadata if err := resp.ParseBody("", &batch); err != nil { return nil, WithStack(err) } batch.cl = c batch.serverID = serverID batch.database = db.Name() return &batch, nil }
go
func (c *client) CreateBatch(ctx context.Context, db Database, serverID int64, ttl time.Duration) (Batch, error) { req, err := c.conn.NewRequest("POST", path.Join("_db", db.Name(), "_api/replication/batch")) if err != nil { return nil, WithStack(err) } req = req.SetQuery("serverId", strconv.FormatInt(serverID, 10)) params := struct { TTL float64 `json:"ttl"` }{TTL: ttl.Seconds()} // just use a default ttl value req, err = req.SetBody(params) 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 batch batchMetadata if err := resp.ParseBody("", &batch); err != nil { return nil, WithStack(err) } batch.cl = c batch.serverID = serverID batch.database = db.Name() return &batch, nil }
[ "func", "(", "c", "*", "client", ")", "CreateBatch", "(", "ctx", "context", ".", "Context", ",", "db", "Database", ",", "serverID", "int64", ",", "ttl", "time", ".", "Duration", ")", "(", "Batch", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "db", ".", "Name", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "req", "=", "req", ".", "SetQuery", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "serverID", ",", "10", ")", ")", "\n", "params", ":=", "struct", "{", "TTL", "float64", "`json:\"ttl\"`", "\n", "}", "{", "TTL", ":", "ttl", ".", "Seconds", "(", ")", "}", "// just use a default ttl value", "\n", "req", ",", "err", "=", "req", ".", "SetBody", "(", "params", ")", "\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", "batch", "batchMetadata", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "batch", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "batch", ".", "cl", "=", "c", "\n", "batch", ".", "serverID", "=", "serverID", "\n", "batch", ".", "database", "=", "db", ".", "Name", "(", ")", "\n", "return", "&", "batch", ",", "nil", "\n", "}" ]
// CreateBatch creates a "batch" to prevent WAL file removal and to take a snapshot
[ "CreateBatch", "creates", "a", "batch", "to", "prevent", "WAL", "file", "removal", "and", "to", "take", "a", "snapshot" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/replication_impl.go#L48-L76
5,711
arangodb/go-driver
replication_impl.go
Extend
func (b batchMetadata) Extend(ctx context.Context, ttl time.Duration) error { if !atomic.CompareAndSwapInt32(&b.closed, 0, 0) { return WithStack(errors.New("Batch already closed")) } req, err := b.cl.conn.NewRequest("PUT", path.Join("_db", b.database, "_api/replication/batch", b.ID)) if err != nil { return WithStack(err) } req = req.SetQuery("serverId", strconv.FormatInt(b.serverID, 10)) input := struct { TTL int64 `json:"ttl"` }{ TTL: int64(ttl.Seconds()), } req, err = req.SetBody(input) if err != nil { return WithStack(err) } resp, err := b.cl.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(204); err != nil { return WithStack(err) } return nil }
go
func (b batchMetadata) Extend(ctx context.Context, ttl time.Duration) error { if !atomic.CompareAndSwapInt32(&b.closed, 0, 0) { return WithStack(errors.New("Batch already closed")) } req, err := b.cl.conn.NewRequest("PUT", path.Join("_db", b.database, "_api/replication/batch", b.ID)) if err != nil { return WithStack(err) } req = req.SetQuery("serverId", strconv.FormatInt(b.serverID, 10)) input := struct { TTL int64 `json:"ttl"` }{ TTL: int64(ttl.Seconds()), } req, err = req.SetBody(input) if err != nil { return WithStack(err) } resp, err := b.cl.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(204); err != nil { return WithStack(err) } return nil }
[ "func", "(", "b", "batchMetadata", ")", "Extend", "(", "ctx", "context", ".", "Context", ",", "ttl", "time", ".", "Duration", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "b", ".", "closed", ",", "0", ",", "0", ")", "{", "return", "WithStack", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "req", ",", "err", ":=", "b", ".", "cl", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "b", ".", "database", ",", "\"", "\"", ",", "b", ".", "ID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "req", "=", "req", ".", "SetQuery", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "b", ".", "serverID", ",", "10", ")", ")", "\n", "input", ":=", "struct", "{", "TTL", "int64", "`json:\"ttl\"`", "\n", "}", "{", "TTL", ":", "int64", "(", "ttl", ".", "Seconds", "(", ")", ")", ",", "}", "\n", "req", ",", "err", "=", "req", ".", "SetBody", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "b", ".", "cl", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "204", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Extend the lifetime of an existing batch on the server
[ "Extend", "the", "lifetime", "of", "an", "existing", "batch", "on", "the", "server" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/replication_impl.go#L110-L137
5,712
arangodb/go-driver
replication_impl.go
Delete
func (b *batchMetadata) Delete(ctx context.Context) error { if !atomic.CompareAndSwapInt32(&b.closed, 0, 1) { return WithStack(errors.New("Batch already closed")) } req, err := b.cl.conn.NewRequest("DELETE", path.Join("_db", b.database, "_api/replication/batch", b.ID)) if err != nil { return WithStack(err) } resp, err := b.cl.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(204); err != nil { return WithStack(err) } return nil }
go
func (b *batchMetadata) Delete(ctx context.Context) error { if !atomic.CompareAndSwapInt32(&b.closed, 0, 1) { return WithStack(errors.New("Batch already closed")) } req, err := b.cl.conn.NewRequest("DELETE", path.Join("_db", b.database, "_api/replication/batch", b.ID)) if err != nil { return WithStack(err) } resp, err := b.cl.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(204); err != nil { return WithStack(err) } return nil }
[ "func", "(", "b", "*", "batchMetadata", ")", "Delete", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "b", ".", "closed", ",", "0", ",", "1", ")", "{", "return", "WithStack", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "req", ",", "err", ":=", "b", ".", "cl", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "\"", "\"", ",", "b", ".", "database", ",", "\"", "\"", ",", "b", ".", "ID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "b", ".", "cl", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "204", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete an existing dump batch
[ "Delete", "an", "existing", "dump", "batch" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/replication_impl.go#L140-L157
5,713
arangodb/go-driver
vst/connection.go
NewConnection
func NewConnection(config ConnectionConfig) (driver.Connection, error) { c, err := cluster.NewConnection(config.ConnectionConfig, func(endpoint string) (driver.Connection, error) { conn, err := newVSTConnection(endpoint, config) if err != nil { return nil, driver.WithStack(err) } return conn, nil }, config.Endpoints) if err != nil { return nil, driver.WithStack(err) } return c, nil }
go
func NewConnection(config ConnectionConfig) (driver.Connection, error) { c, err := cluster.NewConnection(config.ConnectionConfig, func(endpoint string) (driver.Connection, error) { conn, err := newVSTConnection(endpoint, config) if err != nil { return nil, driver.WithStack(err) } return conn, nil }, config.Endpoints) if err != nil { return nil, driver.WithStack(err) } return c, nil }
[ "func", "NewConnection", "(", "config", "ConnectionConfig", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "c", ",", "err", ":=", "cluster", ".", "NewConnection", "(", "config", ".", "ConnectionConfig", ",", "func", "(", "endpoint", "string", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "conn", ",", "err", ":=", "newVSTConnection", "(", "endpoint", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "conn", ",", "nil", "\n", "}", ",", "config", ".", "Endpoints", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewConnection creates a new Velocystream connection based on the given configuration settings.
[ "NewConnection", "creates", "a", "new", "Velocystream", "connection", "based", "on", "the", "given", "configuration", "settings", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/connection.go#L70-L82
5,714
arangodb/go-driver
vst/connection.go
newVSTConnection
func newVSTConnection(endpoint string, config ConnectionConfig) (driver.Connection, error) { endpoint = util.FixupEndpointURLScheme(endpoint) u, err := url.Parse(endpoint) if err != nil { return nil, driver.WithStack(err) } hostAddr := u.Host tlsConfig := config.TLSConfig switch strings.ToLower(u.Scheme) { case "http": tlsConfig = nil case "https": if tlsConfig == nil { tlsConfig = &tls.Config{} } } c := &vstConnection{ endpoint: *u, transport: protocol.NewTransport(hostAddr, tlsConfig, config.Transport), } return c, nil }
go
func newVSTConnection(endpoint string, config ConnectionConfig) (driver.Connection, error) { endpoint = util.FixupEndpointURLScheme(endpoint) u, err := url.Parse(endpoint) if err != nil { return nil, driver.WithStack(err) } hostAddr := u.Host tlsConfig := config.TLSConfig switch strings.ToLower(u.Scheme) { case "http": tlsConfig = nil case "https": if tlsConfig == nil { tlsConfig = &tls.Config{} } } c := &vstConnection{ endpoint: *u, transport: protocol.NewTransport(hostAddr, tlsConfig, config.Transport), } return c, nil }
[ "func", "newVSTConnection", "(", "endpoint", "string", ",", "config", "ConnectionConfig", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "endpoint", "=", "util", ".", "FixupEndpointURLScheme", "(", "endpoint", ")", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "endpoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "hostAddr", ":=", "u", ".", "Host", "\n", "tlsConfig", ":=", "config", ".", "TLSConfig", "\n", "switch", "strings", ".", "ToLower", "(", "u", ".", "Scheme", ")", "{", "case", "\"", "\"", ":", "tlsConfig", "=", "nil", "\n", "case", "\"", "\"", ":", "if", "tlsConfig", "==", "nil", "{", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "}", "\n", "}", "\n", "}", "\n", "c", ":=", "&", "vstConnection", "{", "endpoint", ":", "*", "u", ",", "transport", ":", "protocol", ".", "NewTransport", "(", "hostAddr", ",", "tlsConfig", ",", "config", ".", "Transport", ")", ",", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// newVSTConnection creates a new Velocystream connection for a single endpoint and the remainder of the given configuration settings.
[ "newVSTConnection", "creates", "a", "new", "Velocystream", "connection", "for", "a", "single", "endpoint", "and", "the", "remainder", "of", "the", "given", "configuration", "settings", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/connection.go#L85-L106
5,715
arangodb/go-driver
vst/protocol/message.go
closeResponseChan
func (m *Message) closeResponseChan() { if atomic.CompareAndSwapInt32(&m.responseChanClosed, 0, 1) { if ch := m.responseChan; ch != nil { m.responseChan = nil close(ch) } } }
go
func (m *Message) closeResponseChan() { if atomic.CompareAndSwapInt32(&m.responseChanClosed, 0, 1) { if ch := m.responseChan; ch != nil { m.responseChan = nil close(ch) } } }
[ "func", "(", "m", "*", "Message", ")", "closeResponseChan", "(", ")", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "m", ".", "responseChanClosed", ",", "0", ",", "1", ")", "{", "if", "ch", ":=", "m", ".", "responseChan", ";", "ch", "!=", "nil", "{", "m", ".", "responseChan", "=", "nil", "\n", "close", "(", "ch", ")", "\n", "}", "\n", "}", "\n", "}" ]
// closes the response channel if needed.
[ "closes", "the", "response", "channel", "if", "needed", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message.go#L44-L51
5,716
arangodb/go-driver
vst/protocol/message.go
addChunk
func (m *Message) addChunk(c chunk) { m.chunksMutex.Lock() defer m.chunksMutex.Unlock() m.chunks = append(m.chunks, c) if c.IsFirst() { m.numberOfChunks = c.NumberOfChunks() } }
go
func (m *Message) addChunk(c chunk) { m.chunksMutex.Lock() defer m.chunksMutex.Unlock() m.chunks = append(m.chunks, c) if c.IsFirst() { m.numberOfChunks = c.NumberOfChunks() } }
[ "func", "(", "m", "*", "Message", ")", "addChunk", "(", "c", "chunk", ")", "{", "m", ".", "chunksMutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "chunksMutex", ".", "Unlock", "(", ")", "\n\n", "m", ".", "chunks", "=", "append", "(", "m", ".", "chunks", ",", "c", ")", "\n", "if", "c", ".", "IsFirst", "(", ")", "{", "m", ".", "numberOfChunks", "=", "c", ".", "NumberOfChunks", "(", ")", "\n", "}", "\n", "}" ]
// addChunk adds the given chunks to the list of chunks of the message. // If the given chunk is the first chunk, the expected number of chunks is recorded.
[ "addChunk", "adds", "the", "given", "chunks", "to", "the", "list", "of", "chunks", "of", "the", "message", ".", "If", "the", "given", "chunk", "is", "the", "first", "chunk", "the", "expected", "number", "of", "chunks", "is", "recorded", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message.go#L66-L74
5,717
arangodb/go-driver
vst/protocol/message.go
assemble
func (m *Message) assemble() bool { m.chunksMutex.Lock() defer m.chunksMutex.Unlock() if m.Data != nil { // Already assembled return true } if m.numberOfChunks == 0 { // We don't have the first chunk yet return false } if len(m.chunks) < int(m.numberOfChunks) { // Not all chunks have arrived yet return false } // Fast path, only 1 chunk if m.numberOfChunks == 1 { m.Data = m.chunks[0].Data return true } // Sort chunks by index sort.Sort(chunkByIndex(m.chunks)) // Build data buffer and copy chunks into it data := make([]byte, m.chunks[0].MessageLength) offset := 0 for _, c := range m.chunks { copy(data[offset:], c.Data) offset += len(c.Data) } m.Data = data return true }
go
func (m *Message) assemble() bool { m.chunksMutex.Lock() defer m.chunksMutex.Unlock() if m.Data != nil { // Already assembled return true } if m.numberOfChunks == 0 { // We don't have the first chunk yet return false } if len(m.chunks) < int(m.numberOfChunks) { // Not all chunks have arrived yet return false } // Fast path, only 1 chunk if m.numberOfChunks == 1 { m.Data = m.chunks[0].Data return true } // Sort chunks by index sort.Sort(chunkByIndex(m.chunks)) // Build data buffer and copy chunks into it data := make([]byte, m.chunks[0].MessageLength) offset := 0 for _, c := range m.chunks { copy(data[offset:], c.Data) offset += len(c.Data) } m.Data = data return true }
[ "func", "(", "m", "*", "Message", ")", "assemble", "(", ")", "bool", "{", "m", ".", "chunksMutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "chunksMutex", ".", "Unlock", "(", ")", "\n\n", "if", "m", ".", "Data", "!=", "nil", "{", "// Already assembled", "return", "true", "\n", "}", "\n", "if", "m", ".", "numberOfChunks", "==", "0", "{", "// We don't have the first chunk yet", "return", "false", "\n", "}", "\n", "if", "len", "(", "m", ".", "chunks", ")", "<", "int", "(", "m", ".", "numberOfChunks", ")", "{", "// Not all chunks have arrived yet", "return", "false", "\n", "}", "\n\n", "// Fast path, only 1 chunk", "if", "m", ".", "numberOfChunks", "==", "1", "{", "m", ".", "Data", "=", "m", ".", "chunks", "[", "0", "]", ".", "Data", "\n", "return", "true", "\n", "}", "\n\n", "// Sort chunks by index", "sort", ".", "Sort", "(", "chunkByIndex", "(", "m", ".", "chunks", ")", ")", "\n\n", "// Build data buffer and copy chunks into it", "data", ":=", "make", "(", "[", "]", "byte", ",", "m", ".", "chunks", "[", "0", "]", ".", "MessageLength", ")", "\n", "offset", ":=", "0", "\n", "for", "_", ",", "c", ":=", "range", "m", ".", "chunks", "{", "copy", "(", "data", "[", "offset", ":", "]", ",", "c", ".", "Data", ")", "\n", "offset", "+=", "len", "(", "c", ".", "Data", ")", "\n", "}", "\n", "m", ".", "Data", "=", "data", "\n", "return", "true", "\n", "}" ]
// assemble tries to assemble the message data from all chunks. // If not all chunks are available yet, nothing is done and false // is returned. // If all chunks are available, the Data field is build and set and true is returned.
[ "assemble", "tries", "to", "assemble", "the", "message", "data", "from", "all", "chunks", ".", "If", "not", "all", "chunks", "are", "available", "yet", "nothing", "is", "done", "and", "false", "is", "returned", ".", "If", "all", "chunks", "are", "available", "the", "Data", "field", "is", "build", "and", "set", "and", "true", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message.go#L80-L115
5,718
arangodb/go-driver
cluster.go
IsReady
func (i DatabaseInventory) IsReady() bool { for _, c := range i.Collections { if !c.IsReady { return false } } return true }
go
func (i DatabaseInventory) IsReady() bool { for _, c := range i.Collections { if !c.IsReady { return false } } return true }
[ "func", "(", "i", "DatabaseInventory", ")", "IsReady", "(", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "i", ".", "Collections", "{", "if", "!", "c", ".", "IsReady", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// IsReady returns true if the IsReady flag of all collections is set.
[ "IsReady", "returns", "true", "if", "the", "IsReady", "flag", "of", "all", "collections", "is", "set", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L124-L131
5,719
arangodb/go-driver
cluster.go
PlanVersion
func (i DatabaseInventory) PlanVersion() int64 { if len(i.Collections) == 0 { return 0 } return i.Collections[0].PlanVersion }
go
func (i DatabaseInventory) PlanVersion() int64 { if len(i.Collections) == 0 { return 0 } return i.Collections[0].PlanVersion }
[ "func", "(", "i", "DatabaseInventory", ")", "PlanVersion", "(", ")", "int64", "{", "if", "len", "(", "i", ".", "Collections", ")", "==", "0", "{", "return", "0", "\n", "}", "\n", "return", "i", ".", "Collections", "[", "0", "]", ".", "PlanVersion", "\n", "}" ]
// PlanVersion returns the plan version of the first collection in the given inventory.
[ "PlanVersion", "returns", "the", "plan", "version", "of", "the", "first", "collection", "in", "the", "given", "inventory", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L134-L139
5,720
arangodb/go-driver
cluster.go
CollectionByName
func (i DatabaseInventory) CollectionByName(name string) (InventoryCollection, bool) { for _, c := range i.Collections { if c.Parameters.Name == name { return c, true } } return InventoryCollection{}, false }
go
func (i DatabaseInventory) CollectionByName(name string) (InventoryCollection, bool) { for _, c := range i.Collections { if c.Parameters.Name == name { return c, true } } return InventoryCollection{}, false }
[ "func", "(", "i", "DatabaseInventory", ")", "CollectionByName", "(", "name", "string", ")", "(", "InventoryCollection", ",", "bool", ")", "{", "for", "_", ",", "c", ":=", "range", "i", ".", "Collections", "{", "if", "c", ".", "Parameters", ".", "Name", "==", "name", "{", "return", "c", ",", "true", "\n", "}", "\n", "}", "\n", "return", "InventoryCollection", "{", "}", ",", "false", "\n", "}" ]
// CollectionByName returns the InventoryCollection with given name. // Return false if not found.
[ "CollectionByName", "returns", "the", "InventoryCollection", "with", "given", "name", ".", "Return", "false", "if", "not", "found", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L143-L150
5,721
arangodb/go-driver
cluster.go
ViewByName
func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) { for _, v := range i.Views { if v.Name == name { return v, true } } return InventoryView{}, false }
go
func (i DatabaseInventory) ViewByName(name string) (InventoryView, bool) { for _, v := range i.Views { if v.Name == name { return v, true } } return InventoryView{}, false }
[ "func", "(", "i", "DatabaseInventory", ")", "ViewByName", "(", "name", "string", ")", "(", "InventoryView", ",", "bool", ")", "{", "for", "_", ",", "v", ":=", "range", "i", ".", "Views", "{", "if", "v", ".", "Name", "==", "name", "{", "return", "v", ",", "true", "\n", "}", "\n", "}", "\n", "return", "InventoryView", "{", "}", ",", "false", "\n", "}" ]
// ViewByName returns the InventoryView with given name. // Return false if not found.
[ "ViewByName", "returns", "the", "InventoryView", "with", "given", "name", ".", "Return", "false", "if", "not", "found", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L154-L161
5,722
arangodb/go-driver
cluster.go
IndexByFieldsAndType
func (i InventoryCollection) IndexByFieldsAndType(fields []string, indexType string) (InventoryIndex, bool) { for _, idx := range i.Indexes { if idx.Type == indexType && idx.FieldsEqual(fields) { return idx, true } } return InventoryIndex{}, false }
go
func (i InventoryCollection) IndexByFieldsAndType(fields []string, indexType string) (InventoryIndex, bool) { for _, idx := range i.Indexes { if idx.Type == indexType && idx.FieldsEqual(fields) { return idx, true } } return InventoryIndex{}, false }
[ "func", "(", "i", "InventoryCollection", ")", "IndexByFieldsAndType", "(", "fields", "[", "]", "string", ",", "indexType", "string", ")", "(", "InventoryIndex", ",", "bool", ")", "{", "for", "_", ",", "idx", ":=", "range", "i", ".", "Indexes", "{", "if", "idx", ".", "Type", "==", "indexType", "&&", "idx", ".", "FieldsEqual", "(", "fields", ")", "{", "return", "idx", ",", "true", "\n", "}", "\n", "}", "\n", "return", "InventoryIndex", "{", "}", ",", "false", "\n", "}" ]
// IndexByFieldsAndType returns the InventoryIndex with given fields & type. // Return false if not found.
[ "IndexByFieldsAndType", "returns", "the", "InventoryIndex", "with", "given", "fields", "&", "type", ".", "Return", "false", "if", "not", "found", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L175-L182
5,723
arangodb/go-driver
cluster.go
FieldsEqual
func (i InventoryIndex) FieldsEqual(fields []string) bool { return stringSliceEqualsIgnoreOrder(i.Fields, fields) }
go
func (i InventoryIndex) FieldsEqual(fields []string) bool { return stringSliceEqualsIgnoreOrder(i.Fields, fields) }
[ "func", "(", "i", "InventoryIndex", ")", "FieldsEqual", "(", "fields", "[", "]", "string", ")", "bool", "{", "return", "stringSliceEqualsIgnoreOrder", "(", "i", ".", "Fields", ",", "fields", ")", "\n", "}" ]
// FieldsEqual returns true when the given fields list equals the // Fields list in the InventoryIndex. // The order of fields is irrelevant.
[ "FieldsEqual", "returns", "true", "when", "the", "given", "fields", "list", "equals", "the", "Fields", "list", "in", "the", "InventoryIndex", ".", "The", "order", "of", "fields", "is", "irrelevant", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L239-L241
5,724
arangodb/go-driver
cluster.go
stringSliceEqualsIgnoreOrder
func stringSliceEqualsIgnoreOrder(a, b []string) bool { if len(a) != len(b) { return false } bMap := make(map[string]struct{}) for _, x := range b { bMap[x] = struct{}{} } for _, x := range a { if _, found := bMap[x]; !found { return false } } return true }
go
func stringSliceEqualsIgnoreOrder(a, b []string) bool { if len(a) != len(b) { return false } bMap := make(map[string]struct{}) for _, x := range b { bMap[x] = struct{}{} } for _, x := range a { if _, found := bMap[x]; !found { return false } } return true }
[ "func", "stringSliceEqualsIgnoreOrder", "(", "a", ",", "b", "[", "]", "string", ")", "bool", "{", "if", "len", "(", "a", ")", "!=", "len", "(", "b", ")", "{", "return", "false", "\n", "}", "\n", "bMap", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ")", "\n", "for", "_", ",", "x", ":=", "range", "b", "{", "bMap", "[", "x", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "for", "_", ",", "x", ":=", "range", "a", "{", "if", "_", ",", "found", ":=", "bMap", "[", "x", "]", ";", "!", "found", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// stringSliceEqualsIgnoreOrder returns true when the given lists contain the same elements. // The order of elements is irrelevant.
[ "stringSliceEqualsIgnoreOrder", "returns", "true", "when", "the", "given", "lists", "contain", "the", "same", "elements", ".", "The", "order", "of", "elements", "is", "irrelevant", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster.go#L258-L272
5,725
arangodb/go-driver
vst/protocol/message_store.go
Size
func (s *messageStore) Size() int { s.mutex.RLock() defer s.mutex.RUnlock() return len(s.messages) }
go
func (s *messageStore) Size() int { s.mutex.RLock() defer s.mutex.RUnlock() return len(s.messages) }
[ "func", "(", "s", "*", "messageStore", ")", "Size", "(", ")", "int", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "len", "(", "s", ".", "messages", ")", "\n", "}" ]
// Size returns the number of messages in this store.
[ "Size", "returns", "the", "number", "of", "messages", "in", "this", "store", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message_store.go#L36-L41
5,726
arangodb/go-driver
vst/protocol/message_store.go
Get
func (s *messageStore) Get(id uint64) *Message { s.mutex.RLock() defer s.mutex.RUnlock() m, ok := s.messages[id] if ok { return m } return nil }
go
func (s *messageStore) Get(id uint64) *Message { s.mutex.RLock() defer s.mutex.RUnlock() m, ok := s.messages[id] if ok { return m } return nil }
[ "func", "(", "s", "*", "messageStore", ")", "Get", "(", "id", "uint64", ")", "*", "Message", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "m", ",", "ok", ":=", "s", ".", "messages", "[", "id", "]", "\n", "if", "ok", "{", "return", "m", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Get returns the message with given id, or nil if not found
[ "Get", "returns", "the", "message", "with", "given", "id", "or", "nil", "if", "not", "found" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message_store.go#L44-L53
5,727
arangodb/go-driver
vst/protocol/message_store.go
Add
func (s *messageStore) Add(id uint64) *Message { s.mutex.Lock() defer s.mutex.Unlock() if s.messages == nil { s.messages = make(map[uint64]*Message) } if _, ok := s.messages[id]; ok { panic(fmt.Sprintf("ID %v is not unique", id)) } m := &Message{ ID: id, responseChan: make(chan Message), } s.messages[id] = m return m }
go
func (s *messageStore) Add(id uint64) *Message { s.mutex.Lock() defer s.mutex.Unlock() if s.messages == nil { s.messages = make(map[uint64]*Message) } if _, ok := s.messages[id]; ok { panic(fmt.Sprintf("ID %v is not unique", id)) } m := &Message{ ID: id, responseChan: make(chan Message), } s.messages[id] = m return m }
[ "func", "(", "s", "*", "messageStore", ")", "Add", "(", "id", "uint64", ")", "*", "Message", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "messages", "==", "nil", "{", "s", ".", "messages", "=", "make", "(", "map", "[", "uint64", "]", "*", "Message", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "s", ".", "messages", "[", "id", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "id", ")", ")", "\n", "}", "\n\n", "m", ":=", "&", "Message", "{", "ID", ":", "id", ",", "responseChan", ":", "make", "(", "chan", "Message", ")", ",", "}", "\n", "s", ".", "messages", "[", "id", "]", "=", "m", "\n", "return", "m", "\n", "}" ]
// Add adds a new message to the store with given ID. // If the ID is not unique this function will panic.
[ "Add", "adds", "a", "new", "message", "to", "the", "store", "with", "given", "ID", ".", "If", "the", "ID", "is", "not", "unique", "this", "function", "will", "panic", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message_store.go#L57-L74
5,728
arangodb/go-driver
vst/protocol/message_store.go
Remove
func (s *messageStore) Remove(id uint64) { s.mutex.Lock() defer s.mutex.Unlock() delete(s.messages, id) }
go
func (s *messageStore) Remove(id uint64) { s.mutex.Lock() defer s.mutex.Unlock() delete(s.messages, id) }
[ "func", "(", "s", "*", "messageStore", ")", "Remove", "(", "id", "uint64", ")", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "s", ".", "messages", ",", "id", ")", "\n", "}" ]
// Remove removes the message with given ID from the store.
[ "Remove", "removes", "the", "message", "with", "given", "ID", "from", "the", "store", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message_store.go#L77-L82
5,729
arangodb/go-driver
vst/protocol/message_store.go
ForEach
func (s *messageStore) ForEach(cb func(*Message)) { s.mutex.RLock() defer s.mutex.RUnlock() for _, m := range s.messages { cb(m) } }
go
func (s *messageStore) ForEach(cb func(*Message)) { s.mutex.RLock() defer s.mutex.RUnlock() for _, m := range s.messages { cb(m) } }
[ "func", "(", "s", "*", "messageStore", ")", "ForEach", "(", "cb", "func", "(", "*", "Message", ")", ")", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "m", ":=", "range", "s", ".", "messages", "{", "cb", "(", "m", ")", "\n", "}", "\n", "}" ]
// ForEach calls the given function for each message in the store.
[ "ForEach", "calls", "the", "given", "function", "for", "each", "message", "in", "the", "store", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/message_store.go#L85-L92
5,730
arangodb/go-driver
edge_collection_documents_impl.go
ReadDocument
func (c *edgeCollection) ReadDocument(ctx context.Context, key string, result interface{}) (DocumentMeta, error) { meta, _, err := c.readDocument(ctx, key, result) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
go
func (c *edgeCollection) ReadDocument(ctx context.Context, key string, result interface{}) (DocumentMeta, error) { meta, _, err := c.readDocument(ctx, key, result) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
[ "func", "(", "c", "*", "edgeCollection", ")", "ReadDocument", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "result", "interface", "{", "}", ")", "(", "DocumentMeta", ",", "error", ")", "{", "meta", ",", "_", ",", "err", ":=", "c", ".", "readDocument", "(", "ctx", ",", "key", ",", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "meta", ",", "nil", "\n", "}" ]
// ReadDocument reads a single document with given key from the collection. // The document data is stored into result, the document meta data is returned. // If no document exists with given key, a NotFoundError is returned.
[ "ReadDocument", "reads", "a", "single", "document", "with", "given", "key", "from", "the", "collection", ".", "The", "document", "data", "is", "stored", "into", "result", "the", "document", "meta", "data", "is", "returned", ".", "If", "no", "document", "exists", "with", "given", "key", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_documents_impl.go#L45-L51
5,731
arangodb/go-driver
edge_collection_documents_impl.go
UpdateDocument
func (c *edgeCollection) UpdateDocument(ctx context.Context, key string, update interface{}) (DocumentMeta, error) { meta, _, err := c.updateDocument(ctx, key, update) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
go
func (c *edgeCollection) UpdateDocument(ctx context.Context, key string, update interface{}) (DocumentMeta, error) { meta, _, err := c.updateDocument(ctx, key, update) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
[ "func", "(", "c", "*", "edgeCollection", ")", "UpdateDocument", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "update", "interface", "{", "}", ")", "(", "DocumentMeta", ",", "error", ")", "{", "meta", ",", "_", ",", "err", ":=", "c", ".", "updateDocument", "(", "ctx", ",", "key", ",", "update", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "meta", ",", "nil", "\n", "}" ]
// UpdateDocument updates a single document with given key in the collection. // The document meta data is returned. // To return the NEW document, prepare a context with `WithReturnNew`. // To return the OLD document, prepare a context with `WithReturnOld`. // To wait until document has been synced to disk, prepare a context with `WithWaitForSync`. // If no document exists with given key, a NotFoundError is returned.
[ "UpdateDocument", "updates", "a", "single", "document", "with", "given", "key", "in", "the", "collection", ".", "The", "document", "meta", "data", "is", "returned", ".", "To", "return", "the", "NEW", "document", "prepare", "a", "context", "with", "WithReturnNew", ".", "To", "return", "the", "OLD", "document", "prepare", "a", "context", "with", "WithReturnOld", ".", "To", "wait", "until", "document", "has", "been", "synced", "to", "disk", "prepare", "a", "context", "with", "WithWaitForSync", ".", "If", "no", "document", "exists", "with", "given", "key", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_documents_impl.go#L233-L239
5,732
arangodb/go-driver
edge_collection_documents_impl.go
getKeyFromDocument
func getKeyFromDocument(doc reflect.Value) (string, error) { if doc.IsNil() { return "", WithStack(InvalidArgumentError{Message: "Document is nil"}) } if doc.Kind() == reflect.Ptr { doc = doc.Elem() } switch doc.Kind() { case reflect.Struct: structType := doc.Type() fieldCount := structType.NumField() for i := 0; i < fieldCount; i++ { f := structType.Field(i) tagParts := strings.Split(f.Tag.Get("json"), ",") if tagParts[0] == "_key" { // We found the _key field keyVal := doc.Field(i) return keyVal.String(), nil } } return "", WithStack(InvalidArgumentError{Message: "Document contains no '_key' field"}) case reflect.Map: keyVal := doc.MapIndex(reflect.ValueOf("_key")) if keyVal.IsNil() { return "", WithStack(InvalidArgumentError{Message: "Document contains no '_key' entry"}) } return keyVal.String(), nil default: return "", WithStack(InvalidArgumentError{Message: fmt.Sprintf("Document must be struct or map. Got %s", doc.Kind())}) } }
go
func getKeyFromDocument(doc reflect.Value) (string, error) { if doc.IsNil() { return "", WithStack(InvalidArgumentError{Message: "Document is nil"}) } if doc.Kind() == reflect.Ptr { doc = doc.Elem() } switch doc.Kind() { case reflect.Struct: structType := doc.Type() fieldCount := structType.NumField() for i := 0; i < fieldCount; i++ { f := structType.Field(i) tagParts := strings.Split(f.Tag.Get("json"), ",") if tagParts[0] == "_key" { // We found the _key field keyVal := doc.Field(i) return keyVal.String(), nil } } return "", WithStack(InvalidArgumentError{Message: "Document contains no '_key' field"}) case reflect.Map: keyVal := doc.MapIndex(reflect.ValueOf("_key")) if keyVal.IsNil() { return "", WithStack(InvalidArgumentError{Message: "Document contains no '_key' entry"}) } return keyVal.String(), nil default: return "", WithStack(InvalidArgumentError{Message: fmt.Sprintf("Document must be struct or map. Got %s", doc.Kind())}) } }
[ "func", "getKeyFromDocument", "(", "doc", "reflect", ".", "Value", ")", "(", "string", ",", "error", ")", "{", "if", "doc", ".", "IsNil", "(", ")", "{", "return", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "doc", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "doc", "=", "doc", ".", "Elem", "(", ")", "\n", "}", "\n", "switch", "doc", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Struct", ":", "structType", ":=", "doc", ".", "Type", "(", ")", "\n", "fieldCount", ":=", "structType", ".", "NumField", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "fieldCount", ";", "i", "++", "{", "f", ":=", "structType", ".", "Field", "(", "i", ")", "\n", "tagParts", ":=", "strings", ".", "Split", "(", "f", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "\n", "if", "tagParts", "[", "0", "]", "==", "\"", "\"", "{", "// We found the _key field", "keyVal", ":=", "doc", ".", "Field", "(", "i", ")", "\n", "return", "keyVal", ".", "String", "(", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "case", "reflect", ".", "Map", ":", "keyVal", ":=", "doc", ".", "MapIndex", "(", "reflect", ".", "ValueOf", "(", "\"", "\"", ")", ")", "\n", "if", "keyVal", ".", "IsNil", "(", ")", "{", "return", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "keyVal", ".", "String", "(", ")", ",", "nil", "\n", "default", ":", "return", "\"", "\"", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "doc", ".", "Kind", "(", ")", ")", "}", ")", "\n", "}", "\n", "}" ]
// getKeyFromDocument looks for a `_key` document in the given document and returns it.
[ "getKeyFromDocument", "looks", "for", "a", "_key", "document", "in", "the", "given", "document", "and", "returns", "it", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/edge_collection_documents_impl.go#L566-L596
5,733
arangodb/go-driver
http/authentication.go
newAuthenticatedConnection
func newAuthenticatedConnection(conn driver.Connection, auth httpAuthentication) (driver.Connection, error) { if conn == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "conn is nil"}) } if auth == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "auth is nil"}) } return &authenticatedConnection{ conn: conn, auth: auth, }, nil }
go
func newAuthenticatedConnection(conn driver.Connection, auth httpAuthentication) (driver.Connection, error) { if conn == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "conn is nil"}) } if auth == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "auth is nil"}) } return &authenticatedConnection{ conn: conn, auth: auth, }, nil }
[ "func", "newAuthenticatedConnection", "(", "conn", "driver", ".", "Connection", ",", "auth", "httpAuthentication", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "if", "conn", "==", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "driver", ".", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "auth", "==", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "driver", ".", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "authenticatedConnection", "{", "conn", ":", "conn", ",", "auth", ":", "auth", ",", "}", ",", "nil", "\n", "}" ]
// newAuthenticatedConnection creates a Connection that applies the given connection on the given underlying connection.
[ "newAuthenticatedConnection", "creates", "a", "Connection", "that", "applies", "the", "given", "connection", "on", "the", "given", "underlying", "connection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/authentication.go#L143-L154
5,734
arangodb/go-driver
http/authentication.go
prepare
func (c *authenticatedConnection) prepare(ctx context.Context) error { c.prepareMutex.Lock() defer c.prepareMutex.Unlock() if c.prepared == 0 { // We need to prepare first if err := c.auth.Prepare(ctx, c.conn); err != nil { // Authentication failed return driver.WithStack(err) } // We're now prepared atomic.StoreInt32(&c.prepared, 1) } else { // We're already prepared, do nothing } return nil }
go
func (c *authenticatedConnection) prepare(ctx context.Context) error { c.prepareMutex.Lock() defer c.prepareMutex.Unlock() if c.prepared == 0 { // We need to prepare first if err := c.auth.Prepare(ctx, c.conn); err != nil { // Authentication failed return driver.WithStack(err) } // We're now prepared atomic.StoreInt32(&c.prepared, 1) } else { // We're already prepared, do nothing } return nil }
[ "func", "(", "c", "*", "authenticatedConnection", ")", "prepare", "(", "ctx", "context", ".", "Context", ")", "error", "{", "c", ".", "prepareMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "prepareMutex", ".", "Unlock", "(", ")", "\n", "if", "c", ".", "prepared", "==", "0", "{", "// We need to prepare first", "if", "err", ":=", "c", ".", "auth", ".", "Prepare", "(", "ctx", ",", "c", ".", "conn", ")", ";", "err", "!=", "nil", "{", "// Authentication failed", "return", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "// We're now prepared", "atomic", ".", "StoreInt32", "(", "&", "c", ".", "prepared", ",", "1", ")", "\n", "}", "else", "{", "// We're already prepared, do nothing", "}", "\n", "return", "nil", "\n", "}" ]
// prepare calls Authentication.Prepare if needed.
[ "prepare", "calls", "Authentication", ".", "Prepare", "if", "needed", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/authentication.go#L231-L246
5,735
arangodb/go-driver
vst/protocol/transport.go
NewTransport
func NewTransport(hostAddr string, tlsConfig *tls.Config, config TransportConfig) *Transport { if config.IdleConnTimeout == 0 { config.IdleConnTimeout = DefaultIdleConnTimeout } if config.ConnLimit == 0 { config.ConnLimit = DefaultConnLimit } return &Transport{ TransportConfig: config, hostAddr: hostAddr, tlsConfig: tlsConfig, } }
go
func NewTransport(hostAddr string, tlsConfig *tls.Config, config TransportConfig) *Transport { if config.IdleConnTimeout == 0 { config.IdleConnTimeout = DefaultIdleConnTimeout } if config.ConnLimit == 0 { config.ConnLimit = DefaultConnLimit } return &Transport{ TransportConfig: config, hostAddr: hostAddr, tlsConfig: tlsConfig, } }
[ "func", "NewTransport", "(", "hostAddr", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ",", "config", "TransportConfig", ")", "*", "Transport", "{", "if", "config", ".", "IdleConnTimeout", "==", "0", "{", "config", ".", "IdleConnTimeout", "=", "DefaultIdleConnTimeout", "\n", "}", "\n", "if", "config", ".", "ConnLimit", "==", "0", "{", "config", ".", "ConnLimit", "=", "DefaultConnLimit", "\n", "}", "\n", "return", "&", "Transport", "{", "TransportConfig", ":", "config", ",", "hostAddr", ":", "hostAddr", ",", "tlsConfig", ":", "tlsConfig", ",", "}", "\n", "}" ]
// NewTransport creates a new Transport for given address & tls settings.
[ "NewTransport", "creates", "a", "new", "Transport", "for", "given", "address", "&", "tls", "settings", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L69-L81
5,736
arangodb/go-driver
vst/protocol/transport.go
CloseIdleConnections
func (c *Transport) CloseIdleConnections() (closed, remaining int) { c.connMutex.Lock() defer c.connMutex.Unlock() for i := 0; i < len(c.connections); { conn := c.connections[i] if conn.IsClosed() || conn.IsIdle(c.IdleConnTimeout) { // Remove connection from list c.connections = append(c.connections[:i], c.connections[i+1:]...) // Close connection go conn.Close() closed++ } else { i++ } } remaining = len(c.connections) return closed, remaining }
go
func (c *Transport) CloseIdleConnections() (closed, remaining int) { c.connMutex.Lock() defer c.connMutex.Unlock() for i := 0; i < len(c.connections); { conn := c.connections[i] if conn.IsClosed() || conn.IsIdle(c.IdleConnTimeout) { // Remove connection from list c.connections = append(c.connections[:i], c.connections[i+1:]...) // Close connection go conn.Close() closed++ } else { i++ } } remaining = len(c.connections) return closed, remaining }
[ "func", "(", "c", "*", "Transport", ")", "CloseIdleConnections", "(", ")", "(", "closed", ",", "remaining", "int", ")", "{", "c", ".", "connMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "connMutex", ".", "Unlock", "(", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "c", ".", "connections", ")", ";", "{", "conn", ":=", "c", ".", "connections", "[", "i", "]", "\n", "if", "conn", ".", "IsClosed", "(", ")", "||", "conn", ".", "IsIdle", "(", "c", ".", "IdleConnTimeout", ")", "{", "// Remove connection from list", "c", ".", "connections", "=", "append", "(", "c", ".", "connections", "[", ":", "i", "]", ",", "c", ".", "connections", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "// Close connection", "go", "conn", ".", "Close", "(", ")", "\n", "closed", "++", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n\n", "remaining", "=", "len", "(", "c", ".", "connections", ")", "\n", "return", "closed", ",", "remaining", "\n", "}" ]
// CloseIdleConnections closes all connections which are closed or have been idle for more than the configured idle timeout.
[ "CloseIdleConnections", "closes", "all", "connections", "which", "are", "closed", "or", "have", "been", "idle", "for", "more", "than", "the", "configured", "idle", "timeout", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L100-L119
5,737
arangodb/go-driver
vst/protocol/transport.go
CloseAllConnections
func (c *Transport) CloseAllConnections() { c.connMutex.Lock() defer c.connMutex.Unlock() for _, conn := range c.connections { // Close connection go conn.Close() } }
go
func (c *Transport) CloseAllConnections() { c.connMutex.Lock() defer c.connMutex.Unlock() for _, conn := range c.connections { // Close connection go conn.Close() } }
[ "func", "(", "c", "*", "Transport", ")", "CloseAllConnections", "(", ")", "{", "c", ".", "connMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "connMutex", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "conn", ":=", "range", "c", ".", "connections", "{", "// Close connection", "go", "conn", ".", "Close", "(", ")", "\n", "}", "\n", "}" ]
// CloseAllConnections closes all connections.
[ "CloseAllConnections", "closes", "all", "connections", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L122-L130
5,738
arangodb/go-driver
vst/protocol/transport.go
SetOnConnectionCreated
func (c *Transport) SetOnConnectionCreated(handler func(context.Context, *Connection) error) { c.onConnectionCreated = handler }
go
func (c *Transport) SetOnConnectionCreated(handler func(context.Context, *Connection) error) { c.onConnectionCreated = handler }
[ "func", "(", "c", "*", "Transport", ")", "SetOnConnectionCreated", "(", "handler", "func", "(", "context", ".", "Context", ",", "*", "Connection", ")", "error", ")", "{", "c", ".", "onConnectionCreated", "=", "handler", "\n", "}" ]
// SetOnConnectionCreated stores a callback function that is called every time a new connection has been created.
[ "SetOnConnectionCreated", "stores", "a", "callback", "function", "that", "is", "called", "every", "time", "a", "new", "connection", "has", "been", "created", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L133-L135
5,739
arangodb/go-driver
vst/protocol/transport.go
getConnection
func (c *Transport) getConnection(ctx context.Context) (*Connection, error) { conn := c.getAvailableConnection() if conn != nil { return conn, nil } // No connections available, make a new one conn, err := c.createConnection() if err != nil { if conn != nil { conn.Close() } return nil, driver.WithStack(err) } // Invoke callback if cb := c.onConnectionCreated; cb != nil { if err := cb(ctx, conn); err != nil { conn.Close() return nil, driver.WithStack(err) } } // Mark the connection as ready atomic.StoreInt32(&conn.configured, 1) return conn, nil }
go
func (c *Transport) getConnection(ctx context.Context) (*Connection, error) { conn := c.getAvailableConnection() if conn != nil { return conn, nil } // No connections available, make a new one conn, err := c.createConnection() if err != nil { if conn != nil { conn.Close() } return nil, driver.WithStack(err) } // Invoke callback if cb := c.onConnectionCreated; cb != nil { if err := cb(ctx, conn); err != nil { conn.Close() return nil, driver.WithStack(err) } } // Mark the connection as ready atomic.StoreInt32(&conn.configured, 1) return conn, nil }
[ "func", "(", "c", "*", "Transport", ")", "getConnection", "(", "ctx", "context", ".", "Context", ")", "(", "*", "Connection", ",", "error", ")", "{", "conn", ":=", "c", ".", "getAvailableConnection", "(", ")", "\n", "if", "conn", "!=", "nil", "{", "return", "conn", ",", "nil", "\n", "}", "\n\n", "// No connections available, make a new one", "conn", ",", "err", ":=", "c", ".", "createConnection", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "conn", "!=", "nil", "{", "conn", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Invoke callback", "if", "cb", ":=", "c", ".", "onConnectionCreated", ";", "cb", "!=", "nil", "{", "if", "err", ":=", "cb", "(", "ctx", ",", "conn", ")", ";", "err", "!=", "nil", "{", "conn", ".", "Close", "(", ")", "\n", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n\n", "// Mark the connection as ready", "atomic", ".", "StoreInt32", "(", "&", "conn", ".", "configured", ",", "1", ")", "\n\n", "return", "conn", ",", "nil", "\n", "}" ]
// getConnection returns the first available connection, or when no such connection is available, // is created a new connection.
[ "getConnection", "returns", "the", "first", "available", "connection", "or", "when", "no", "such", "connection", "is", "available", "is", "created", "a", "new", "connection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L139-L166
5,740
arangodb/go-driver
vst/protocol/transport.go
getAvailableConnection
func (c *Transport) getAvailableConnection() *Connection { c.connMutex.Lock() defer c.connMutex.Unlock() // Select the connection with the least amount of traffic var bestConn *Connection bestConnLoad := 0 activeConnCount := 0 for _, conn := range c.connections { if !conn.IsClosed() { activeConnCount++ if conn.IsConfigured() { connLoad := conn.load() if bestConn == nil || connLoad < bestConnLoad { bestConn = conn bestConnLoad = connLoad } } } } if bestConn == nil { // No connections available return nil } // Is load is >0 AND the number of connections is below the limit, create a new one if bestConnLoad > 0 && activeConnCount < c.ConnLimit { return nil } // Use the best connection found bestConn.updateLastActivity() return bestConn }
go
func (c *Transport) getAvailableConnection() *Connection { c.connMutex.Lock() defer c.connMutex.Unlock() // Select the connection with the least amount of traffic var bestConn *Connection bestConnLoad := 0 activeConnCount := 0 for _, conn := range c.connections { if !conn.IsClosed() { activeConnCount++ if conn.IsConfigured() { connLoad := conn.load() if bestConn == nil || connLoad < bestConnLoad { bestConn = conn bestConnLoad = connLoad } } } } if bestConn == nil { // No connections available return nil } // Is load is >0 AND the number of connections is below the limit, create a new one if bestConnLoad > 0 && activeConnCount < c.ConnLimit { return nil } // Use the best connection found bestConn.updateLastActivity() return bestConn }
[ "func", "(", "c", "*", "Transport", ")", "getAvailableConnection", "(", ")", "*", "Connection", "{", "c", ".", "connMutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "connMutex", ".", "Unlock", "(", ")", "\n\n", "// Select the connection with the least amount of traffic", "var", "bestConn", "*", "Connection", "\n", "bestConnLoad", ":=", "0", "\n", "activeConnCount", ":=", "0", "\n", "for", "_", ",", "conn", ":=", "range", "c", ".", "connections", "{", "if", "!", "conn", ".", "IsClosed", "(", ")", "{", "activeConnCount", "++", "\n", "if", "conn", ".", "IsConfigured", "(", ")", "{", "connLoad", ":=", "conn", ".", "load", "(", ")", "\n", "if", "bestConn", "==", "nil", "||", "connLoad", "<", "bestConnLoad", "{", "bestConn", "=", "conn", "\n", "bestConnLoad", "=", "connLoad", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "bestConn", "==", "nil", "{", "// No connections available", "return", "nil", "\n", "}", "\n\n", "// Is load is >0 AND the number of connections is below the limit, create a new one", "if", "bestConnLoad", ">", "0", "&&", "activeConnCount", "<", "c", ".", "ConnLimit", "{", "return", "nil", "\n", "}", "\n\n", "// Use the best connection found", "bestConn", ".", "updateLastActivity", "(", ")", "\n", "return", "bestConn", "\n", "}" ]
// getAvailableConnection returns the first available connection. // If no such connection is available, nil is returned.
[ "getAvailableConnection", "returns", "the", "first", "available", "connection", ".", "If", "no", "such", "connection", "is", "available", "nil", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L170-L204
5,741
arangodb/go-driver
vst/protocol/transport.go
createConnection
func (c *Transport) createConnection() (*Connection, error) { conn, err := dial(c.Version, c.hostAddr, c.tlsConfig) if err != nil { return nil, driver.WithStack(err) } // Record connection c.connMutex.Lock() c.connections = append(c.connections, conn) startCleanup := len(c.connections) == 1 c.connMutex.Unlock() if startCleanup { // TODO enable cleanup go c.cleanup() } return conn, nil }
go
func (c *Transport) createConnection() (*Connection, error) { conn, err := dial(c.Version, c.hostAddr, c.tlsConfig) if err != nil { return nil, driver.WithStack(err) } // Record connection c.connMutex.Lock() c.connections = append(c.connections, conn) startCleanup := len(c.connections) == 1 c.connMutex.Unlock() if startCleanup { // TODO enable cleanup go c.cleanup() } return conn, nil }
[ "func", "(", "c", "*", "Transport", ")", "createConnection", "(", ")", "(", "*", "Connection", ",", "error", ")", "{", "conn", ",", "err", ":=", "dial", "(", "c", ".", "Version", ",", "c", ".", "hostAddr", ",", "c", ".", "tlsConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Record connection", "c", ".", "connMutex", ".", "Lock", "(", ")", "\n", "c", ".", "connections", "=", "append", "(", "c", ".", "connections", ",", "conn", ")", "\n", "startCleanup", ":=", "len", "(", "c", ".", "connections", ")", "==", "1", "\n", "c", ".", "connMutex", ".", "Unlock", "(", ")", "\n\n", "if", "startCleanup", "{", "// TODO enable cleanup", "go", "c", ".", "cleanup", "(", ")", "\n", "}", "\n\n", "return", "conn", ",", "nil", "\n", "}" ]
// createConnection creates a new connection.
[ "createConnection", "creates", "a", "new", "connection", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L207-L225
5,742
arangodb/go-driver
vst/protocol/transport.go
cleanup
func (c *Transport) cleanup() { for { time.Sleep(c.IdleConnTimeout / 10) _, remaining := c.CloseIdleConnections() if remaining == 0 { return } } }
go
func (c *Transport) cleanup() { for { time.Sleep(c.IdleConnTimeout / 10) _, remaining := c.CloseIdleConnections() if remaining == 0 { return } } }
[ "func", "(", "c", "*", "Transport", ")", "cleanup", "(", ")", "{", "for", "{", "time", ".", "Sleep", "(", "c", ".", "IdleConnTimeout", "/", "10", ")", "\n", "_", ",", "remaining", ":=", "c", ".", "CloseIdleConnections", "(", ")", "\n", "if", "remaining", "==", "0", "{", "return", "\n", "}", "\n", "}", "\n", "}" ]
// cleanup keeps removing idle connections
[ "cleanup", "keeps", "removing", "idle", "connections" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/transport.go#L228-L236
5,743
arangodb/go-driver
agency/agency_connection.go
Do
func (c *agencyConnection) Do(ctx context.Context, req driver.Request) (driver.Response, error) { if ctx == nil { ctx = context.Background() } deadline, ok := ctx.Deadline() if !ok { deadline = time.Now().Add(time.Second * 30) } timeout := time.Until(deadline) if timeout < minAgencyTimeout { timeout = minAgencyTimeout } attempt := 1 delay := agencyConnectionFailureBackoff(0) for { lctx, cancel := context.WithTimeout(ctx, timeout/3) resp, isPerm, err := c.doOnce(lctx, req) cancel() if err == nil { // Success return resp, nil } else if isPerm { // Permanent error return nil, driver.WithStack(err) } // Is deadline exceeded? if time.Now().After(deadline) { return nil, driver.WithStack(fmt.Errorf("All %d attemps resulted in temporary failure", attempt)) } // Just retry attempt++ delay = agencyConnectionFailureBackoff(delay) // Wait a bit so we don't hammer the agency select { case <-time.After(delay): // Continue case <-ctx.Done(): // Context canceled return nil, driver.WithStack(ctx.Err()) } } }
go
func (c *agencyConnection) Do(ctx context.Context, req driver.Request) (driver.Response, error) { if ctx == nil { ctx = context.Background() } deadline, ok := ctx.Deadline() if !ok { deadline = time.Now().Add(time.Second * 30) } timeout := time.Until(deadline) if timeout < minAgencyTimeout { timeout = minAgencyTimeout } attempt := 1 delay := agencyConnectionFailureBackoff(0) for { lctx, cancel := context.WithTimeout(ctx, timeout/3) resp, isPerm, err := c.doOnce(lctx, req) cancel() if err == nil { // Success return resp, nil } else if isPerm { // Permanent error return nil, driver.WithStack(err) } // Is deadline exceeded? if time.Now().After(deadline) { return nil, driver.WithStack(fmt.Errorf("All %d attemps resulted in temporary failure", attempt)) } // Just retry attempt++ delay = agencyConnectionFailureBackoff(delay) // Wait a bit so we don't hammer the agency select { case <-time.After(delay): // Continue case <-ctx.Done(): // Context canceled return nil, driver.WithStack(ctx.Err()) } } }
[ "func", "(", "c", "*", "agencyConnection", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "driver", ".", "Request", ")", "(", "driver", ".", "Response", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "ctx", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "deadline", ",", "ok", ":=", "ctx", ".", "Deadline", "(", ")", "\n", "if", "!", "ok", "{", "deadline", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "time", ".", "Second", "*", "30", ")", "\n", "}", "\n", "timeout", ":=", "time", ".", "Until", "(", "deadline", ")", "\n", "if", "timeout", "<", "minAgencyTimeout", "{", "timeout", "=", "minAgencyTimeout", "\n", "}", "\n", "attempt", ":=", "1", "\n", "delay", ":=", "agencyConnectionFailureBackoff", "(", "0", ")", "\n", "for", "{", "lctx", ",", "cancel", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "timeout", "/", "3", ")", "\n", "resp", ",", "isPerm", ",", "err", ":=", "c", ".", "doOnce", "(", "lctx", ",", "req", ")", "\n", "cancel", "(", ")", "\n", "if", "err", "==", "nil", "{", "// Success", "return", "resp", ",", "nil", "\n", "}", "else", "if", "isPerm", "{", "// Permanent error", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "// Is deadline exceeded?", "if", "time", ".", "Now", "(", ")", ".", "After", "(", "deadline", ")", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "attempt", ")", ")", "\n", "}", "\n", "// Just retry", "attempt", "++", "\n", "delay", "=", "agencyConnectionFailureBackoff", "(", "delay", ")", "\n", "// Wait a bit so we don't hammer the agency", "select", "{", "case", "<-", "time", ".", "After", "(", "delay", ")", ":", "// Continue", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "// Context canceled", "return", "nil", ",", "driver", ".", "WithStack", "(", "ctx", ".", "Err", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Do performs a given request, returning its response. // In case of a termporary failure, the request is retried until // the deadline is exceeded.
[ "Do", "performs", "a", "given", "request", "returning", "its", "response", ".", "In", "case", "of", "a", "termporary", "failure", "the", "request", "is", "retried", "until", "the", "deadline", "is", "exceeded", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_connection.go#L81-L122
5,744
arangodb/go-driver
agency/agency_connection.go
agencyConnectionFailureBackoff
func agencyConnectionFailureBackoff(lastDelay time.Duration) time.Duration { return increaseDelay(lastDelay, 1.5, time.Millisecond, time.Second*2) }
go
func agencyConnectionFailureBackoff(lastDelay time.Duration) time.Duration { return increaseDelay(lastDelay, 1.5, time.Millisecond, time.Second*2) }
[ "func", "agencyConnectionFailureBackoff", "(", "lastDelay", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "return", "increaseDelay", "(", "lastDelay", ",", "1.5", ",", "time", ".", "Millisecond", ",", "time", ".", "Second", "*", "2", ")", "\n", "}" ]
// agencyConnectionFailureBackoff returns a backoff delay for cases where all // agents responded with a non-fatal error.
[ "agencyConnectionFailureBackoff", "returns", "a", "backoff", "delay", "for", "cases", "where", "all", "agents", "responded", "with", "a", "non", "-", "fatal", "error", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_connection.go#L300-L302
5,745
arangodb/go-driver
agency/agency_connection.go
increaseDelay
func increaseDelay(oldDelay time.Duration, factor float64, min, max time.Duration) time.Duration { delay := time.Duration(float64(oldDelay) * factor) if delay < min { delay = min } if delay > max { delay = max } return delay }
go
func increaseDelay(oldDelay time.Duration, factor float64, min, max time.Duration) time.Duration { delay := time.Duration(float64(oldDelay) * factor) if delay < min { delay = min } if delay > max { delay = max } return delay }
[ "func", "increaseDelay", "(", "oldDelay", "time", ".", "Duration", ",", "factor", "float64", ",", "min", ",", "max", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "delay", ":=", "time", ".", "Duration", "(", "float64", "(", "oldDelay", ")", "*", "factor", ")", "\n", "if", "delay", "<", "min", "{", "delay", "=", "min", "\n", "}", "\n", "if", "delay", ">", "max", "{", "delay", "=", "max", "\n", "}", "\n", "return", "delay", "\n", "}" ]
// increaseDelay returns an delay, increased from an old delay with a given // factor, limited to given min & max.
[ "increaseDelay", "returns", "an", "delay", "increased", "from", "an", "old", "delay", "with", "a", "given", "factor", "limited", "to", "given", "min", "&", "max", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency_connection.go#L306-L315
5,746
arangodb/go-driver
view_arangosearch_impl.go
Properties
func (v *viewArangoSearch) Properties(ctx context.Context) (ArangoSearchViewProperties, error) { req, err := v.conn.NewRequest("GET", path.Join(v.relPath(), "properties")) if err != nil { return ArangoSearchViewProperties{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := v.conn.Do(ctx, req) if err != nil { return ArangoSearchViewProperties{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return ArangoSearchViewProperties{}, WithStack(err) } var data ArangoSearchViewProperties if err := resp.ParseBody("", &data); err != nil { return ArangoSearchViewProperties{}, WithStack(err) } return data, nil }
go
func (v *viewArangoSearch) Properties(ctx context.Context) (ArangoSearchViewProperties, error) { req, err := v.conn.NewRequest("GET", path.Join(v.relPath(), "properties")) if err != nil { return ArangoSearchViewProperties{}, WithStack(err) } applyContextSettings(ctx, req) resp, err := v.conn.Do(ctx, req) if err != nil { return ArangoSearchViewProperties{}, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return ArangoSearchViewProperties{}, WithStack(err) } var data ArangoSearchViewProperties if err := resp.ParseBody("", &data); err != nil { return ArangoSearchViewProperties{}, WithStack(err) } return data, nil }
[ "func", "(", "v", "*", "viewArangoSearch", ")", "Properties", "(", "ctx", "context", ".", "Context", ")", "(", "ArangoSearchViewProperties", ",", "error", ")", "{", "req", ",", "err", ":=", "v", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "v", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ArangoSearchViewProperties", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "v", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ArangoSearchViewProperties", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "ArangoSearchViewProperties", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "data", "ArangoSearchViewProperties", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "ArangoSearchViewProperties", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// Properties fetches extended information about the view.
[ "Properties", "fetches", "extended", "information", "about", "the", "view", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/view_arangosearch_impl.go#L36-L54
5,747
arangodb/go-driver
view_arangosearch_impl.go
SetProperties
func (v *viewArangoSearch) SetProperties(ctx context.Context, options ArangoSearchViewProperties) error { req, err := v.conn.NewRequest("PUT", path.Join(v.relPath(), "properties")) if err != nil { return WithStack(err) } if _, err := req.SetBody(options); 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 *viewArangoSearch) SetProperties(ctx context.Context, options ArangoSearchViewProperties) error { req, err := v.conn.NewRequest("PUT", path.Join(v.relPath(), "properties")) if err != nil { return WithStack(err) } if _, err := req.SetBody(options); 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", "*", "viewArangoSearch", ")", "SetProperties", "(", "ctx", "context", ".", "Context", ",", "options", "ArangoSearchViewProperties", ")", "error", "{", "req", ",", "err", ":=", "v", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "v", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "req", ".", "SetBody", "(", "options", ")", ";", "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", "}" ]
// SetProperties changes properties of the view.
[ "SetProperties", "changes", "properties", "of", "the", "view", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/view_arangosearch_impl.go#L57-L74
5,748
arangodb/go-driver
cluster/cluster.go
NewConnection
func NewConnection(config ConnectionConfig, connectionBuilder ServerConnectionBuilder, endpoints []string) (driver.Connection, error) { if connectionBuilder == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "Must a connection builder"}) } if len(endpoints) == 0 { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "Must provide at least 1 endpoint"}) } if config.DefaultTimeout == 0 { config.DefaultTimeout = defaultTimeout } cConn := &clusterConnection{ connectionBuilder: connectionBuilder, defaultTimeout: config.DefaultTimeout, } // Initialize endpoints if err := cConn.UpdateEndpoints(endpoints); err != nil { return nil, driver.WithStack(err) } return cConn, nil }
go
func NewConnection(config ConnectionConfig, connectionBuilder ServerConnectionBuilder, endpoints []string) (driver.Connection, error) { if connectionBuilder == nil { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "Must a connection builder"}) } if len(endpoints) == 0 { return nil, driver.WithStack(driver.InvalidArgumentError{Message: "Must provide at least 1 endpoint"}) } if config.DefaultTimeout == 0 { config.DefaultTimeout = defaultTimeout } cConn := &clusterConnection{ connectionBuilder: connectionBuilder, defaultTimeout: config.DefaultTimeout, } // Initialize endpoints if err := cConn.UpdateEndpoints(endpoints); err != nil { return nil, driver.WithStack(err) } return cConn, nil }
[ "func", "NewConnection", "(", "config", "ConnectionConfig", ",", "connectionBuilder", "ServerConnectionBuilder", ",", "endpoints", "[", "]", "string", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "if", "connectionBuilder", "==", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "driver", ".", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "len", "(", "endpoints", ")", "==", "0", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "driver", ".", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "config", ".", "DefaultTimeout", "==", "0", "{", "config", ".", "DefaultTimeout", "=", "defaultTimeout", "\n", "}", "\n", "cConn", ":=", "&", "clusterConnection", "{", "connectionBuilder", ":", "connectionBuilder", ",", "defaultTimeout", ":", "config", ".", "DefaultTimeout", ",", "}", "\n", "// Initialize endpoints", "if", "err", ":=", "cConn", ".", "UpdateEndpoints", "(", "endpoints", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "cConn", ",", "nil", "\n", "}" ]
// NewConnection creates a new cluster connection to a cluster of servers. // The given connections are existing connections to each of the servers.
[ "NewConnection", "creates", "a", "new", "cluster", "connection", "to", "a", "cluster", "of", "servers", ".", "The", "given", "connections", "are", "existing", "connections", "to", "each", "of", "the", "servers", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster/cluster.go#L54-L73
5,749
arangodb/go-driver
cluster/cluster.go
getCurrentServer
func (c *clusterConnection) getCurrentServer() driver.Connection { c.mutex.RLock() defer c.mutex.RUnlock() return c.servers[c.current] }
go
func (c *clusterConnection) getCurrentServer() driver.Connection { c.mutex.RLock() defer c.mutex.RUnlock() return c.servers[c.current] }
[ "func", "(", "c", "*", "clusterConnection", ")", "getCurrentServer", "(", ")", "driver", ".", "Connection", "{", "c", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "servers", "[", "c", ".", "current", "]", "\n", "}" ]
// getCurrentServer returns the currently used server.
[ "getCurrentServer", "returns", "the", "currently", "used", "server", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster/cluster.go#L328-L332
5,750
arangodb/go-driver
cluster/cluster.go
getSpecificServer
func (c *clusterConnection) getSpecificServer(endpoint string) (driver.Connection, error) { c.mutex.RLock() defer c.mutex.RUnlock() for _, s := range c.servers { endpoints := s.Endpoints() found := false for _, x := range endpoints { if x == endpoint { found = true break } } if found { return s, nil } } return nil, driver.WithStack(driver.InvalidArgumentError{Message: fmt.Sprintf("unknown endpoint: %s", endpoint)}) }
go
func (c *clusterConnection) getSpecificServer(endpoint string) (driver.Connection, error) { c.mutex.RLock() defer c.mutex.RUnlock() for _, s := range c.servers { endpoints := s.Endpoints() found := false for _, x := range endpoints { if x == endpoint { found = true break } } if found { return s, nil } } return nil, driver.WithStack(driver.InvalidArgumentError{Message: fmt.Sprintf("unknown endpoint: %s", endpoint)}) }
[ "func", "(", "c", "*", "clusterConnection", ")", "getSpecificServer", "(", "endpoint", "string", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "c", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "s", ":=", "range", "c", ".", "servers", "{", "endpoints", ":=", "s", ".", "Endpoints", "(", ")", "\n", "found", ":=", "false", "\n", "for", "_", ",", "x", ":=", "range", "endpoints", "{", "if", "x", "==", "endpoint", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "found", "{", "return", "s", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "driver", ".", "WithStack", "(", "driver", ".", "InvalidArgumentError", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "endpoint", ")", "}", ")", "\n", "}" ]
// getSpecificServer returns the server with the given endpoint.
[ "getSpecificServer", "returns", "the", "server", "with", "the", "given", "endpoint", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster/cluster.go#L335-L354
5,751
arangodb/go-driver
cluster/cluster.go
getNextServer
func (c *clusterConnection) getNextServer() driver.Connection { c.mutex.Lock() defer c.mutex.Unlock() c.current = (c.current + 1) % len(c.servers) return c.servers[c.current] }
go
func (c *clusterConnection) getNextServer() driver.Connection { c.mutex.Lock() defer c.mutex.Unlock() c.current = (c.current + 1) % len(c.servers) return c.servers[c.current] }
[ "func", "(", "c", "*", "clusterConnection", ")", "getNextServer", "(", ")", "driver", ".", "Connection", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "c", ".", "current", "=", "(", "c", ".", "current", "+", "1", ")", "%", "len", "(", "c", ".", "servers", ")", "\n", "return", "c", ".", "servers", "[", "c", ".", "current", "]", "\n", "}" ]
// getNextServer changes the currently used server and returns the new server.
[ "getNextServer", "changes", "the", "currently", "used", "server", "and", "returns", "the", "new", "server", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/cluster/cluster.go#L357-L362
5,752
arangodb/go-driver
collection_impl.go
newCollection
func newCollection(name string, db *database) (Collection, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &collection{ name: name, db: db, conn: db.conn, }, nil }
go
func newCollection(name string, db *database) (Collection, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &collection{ name: name, db: db, conn: db.conn, }, nil }
[ "func", "newCollection", "(", "name", "string", ",", "db", "*", "database", ")", "(", "Collection", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "db", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "collection", "{", "name", ":", "name", ",", "db", ":", "db", ",", "conn", ":", "db", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newCollection creates a new Collection implementation.
[ "newCollection", "creates", "a", "new", "Collection", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_impl.go#L32-L44
5,753
arangodb/go-driver
collection_impl.go
Unload
func (c *collection) Unload(ctx context.Context) error { req, err := c.conn.NewRequest("PUT", path.Join(c.relPath("collection"), "unload")) if err != nil { return WithStack(err) } 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 *collection) Unload(ctx context.Context) error { req, err := c.conn.NewRequest("PUT", path.Join(c.relPath("collection"), "unload")) if err != nil { return WithStack(err) } 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", "*", "collection", ")", "Unload", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "c", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "c", ".", "relPath", "(", "\"", "\"", ")", ",", "\"", "\"", ")", ")", "\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", "(", "200", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n\n", "}" ]
// UnLoad the collection from memory.
[ "UnLoad", "the", "collection", "from", "memory", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_impl.go#L218-L232
5,754
arangodb/go-driver
collection_impl.go
UnmarshalJSON
func (p *CollectionProperties) UnmarshalJSON(d []byte) error { var internal collectionPropertiesInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(&internal) return nil }
go
func (p *CollectionProperties) UnmarshalJSON(d []byte) error { var internal collectionPropertiesInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(&internal) return nil }
[ "func", "(", "p", "*", "CollectionProperties", ")", "UnmarshalJSON", "(", "d", "[", "]", "byte", ")", "error", "{", "var", "internal", "collectionPropertiesInternal", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "d", ",", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "fromInternal", "(", "&", "internal", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON loads CollectionProperties from json
[ "UnmarshalJSON", "loads", "CollectionProperties", "from", "json" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_impl.go#L333-L341
5,755
arangodb/go-driver
collection_impl.go
UnmarshalJSON
func (p *SetCollectionPropertiesOptions) UnmarshalJSON(d []byte) error { var internal setCollectionPropertiesOptionsInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(&internal) return nil }
go
func (p *SetCollectionPropertiesOptions) UnmarshalJSON(d []byte) error { var internal setCollectionPropertiesOptionsInternal if err := json.Unmarshal(d, &internal); err != nil { return err } p.fromInternal(&internal) return nil }
[ "func", "(", "p", "*", "SetCollectionPropertiesOptions", ")", "UnmarshalJSON", "(", "d", "[", "]", "byte", ")", "error", "{", "var", "internal", "setCollectionPropertiesOptionsInternal", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "d", ",", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "fromInternal", "(", "&", "internal", ")", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON loads SetCollectionPropertiesOptions from json
[ "UnmarshalJSON", "loads", "SetCollectionPropertiesOptions", "from", "json" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_impl.go#L369-L377
5,756
arangodb/go-driver
http/connection.go
newHTTPConnection
func newHTTPConnection(endpoint string, config ConnectionConfig) (driver.Connection, error) { if config.ConnLimit == 0 { config.ConnLimit = DefaultConnLimit } endpoint = util.FixupEndpointURLScheme(endpoint) u, err := url.Parse(endpoint) if err != nil { return nil, driver.WithStack(err) } var httpTransport *http.Transport if config.Transport != nil { httpTransport, _ = config.Transport.(*http.Transport) } else { httpTransport = &http.Transport{ // Copy default values from http.DefaultTransport Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } config.Transport = httpTransport } if httpTransport != nil { if httpTransport.MaxIdleConnsPerHost == 0 { // Raise the default number of idle connections per host since in a database application // it is very likely that you want more than 2 concurrent connections to a host. // We raise it to avoid the extra concurrent connections being closed directly // after use, resulting in a lot of connection in `TIME_WAIT` state. httpTransport.MaxIdleConnsPerHost = DefaultMaxIdleConnsPerHost } defaultMaxIdleConns := 3 * DefaultMaxIdleConnsPerHost if httpTransport.MaxIdleConns > 0 && httpTransport.MaxIdleConns < defaultMaxIdleConns { // For a cluster scenario we assume the use of 3 coordinators (don't know the exact number here) // and derive the maximum total number of idle connections from that. httpTransport.MaxIdleConns = defaultMaxIdleConns } if config.TLSConfig != nil { httpTransport.TLSClientConfig = config.TLSConfig } } httpClient := &http.Client{ Transport: config.Transport, } if config.DontFollowRedirect { httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse // Do not wrap, standard library will not understand } } else if config.FailOnRedirect { httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { return driver.ArangoError{ HasError: true, Code: http.StatusFound, ErrorNum: 0, ErrorMessage: "Redirect not allowed", } } } var connPool chan int if config.ConnLimit > 0 { connPool = make(chan int, config.ConnLimit) // Fill with available tokens for i := 0; i < config.ConnLimit; i++ { connPool <- i } } c := &httpConnection{ endpoint: *u, contentType: config.ContentType, client: httpClient, connPool: connPool, } return c, nil }
go
func newHTTPConnection(endpoint string, config ConnectionConfig) (driver.Connection, error) { if config.ConnLimit == 0 { config.ConnLimit = DefaultConnLimit } endpoint = util.FixupEndpointURLScheme(endpoint) u, err := url.Parse(endpoint) if err != nil { return nil, driver.WithStack(err) } var httpTransport *http.Transport if config.Transport != nil { httpTransport, _ = config.Transport.(*http.Transport) } else { httpTransport = &http.Transport{ // Copy default values from http.DefaultTransport Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } config.Transport = httpTransport } if httpTransport != nil { if httpTransport.MaxIdleConnsPerHost == 0 { // Raise the default number of idle connections per host since in a database application // it is very likely that you want more than 2 concurrent connections to a host. // We raise it to avoid the extra concurrent connections being closed directly // after use, resulting in a lot of connection in `TIME_WAIT` state. httpTransport.MaxIdleConnsPerHost = DefaultMaxIdleConnsPerHost } defaultMaxIdleConns := 3 * DefaultMaxIdleConnsPerHost if httpTransport.MaxIdleConns > 0 && httpTransport.MaxIdleConns < defaultMaxIdleConns { // For a cluster scenario we assume the use of 3 coordinators (don't know the exact number here) // and derive the maximum total number of idle connections from that. httpTransport.MaxIdleConns = defaultMaxIdleConns } if config.TLSConfig != nil { httpTransport.TLSClientConfig = config.TLSConfig } } httpClient := &http.Client{ Transport: config.Transport, } if config.DontFollowRedirect { httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse // Do not wrap, standard library will not understand } } else if config.FailOnRedirect { httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { return driver.ArangoError{ HasError: true, Code: http.StatusFound, ErrorNum: 0, ErrorMessage: "Redirect not allowed", } } } var connPool chan int if config.ConnLimit > 0 { connPool = make(chan int, config.ConnLimit) // Fill with available tokens for i := 0; i < config.ConnLimit; i++ { connPool <- i } } c := &httpConnection{ endpoint: *u, contentType: config.ContentType, client: httpClient, connPool: connPool, } return c, nil }
[ "func", "newHTTPConnection", "(", "endpoint", "string", ",", "config", "ConnectionConfig", ")", "(", "driver", ".", "Connection", ",", "error", ")", "{", "if", "config", ".", "ConnLimit", "==", "0", "{", "config", ".", "ConnLimit", "=", "DefaultConnLimit", "\n", "}", "\n", "endpoint", "=", "util", ".", "FixupEndpointURLScheme", "(", "endpoint", ")", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "endpoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "httpTransport", "*", "http", ".", "Transport", "\n", "if", "config", ".", "Transport", "!=", "nil", "{", "httpTransport", ",", "_", "=", "config", ".", "Transport", ".", "(", "*", "http", ".", "Transport", ")", "\n", "}", "else", "{", "httpTransport", "=", "&", "http", ".", "Transport", "{", "// Copy default values from http.DefaultTransport", "Proxy", ":", "http", ".", "ProxyFromEnvironment", ",", "DialContext", ":", "(", "&", "net", ".", "Dialer", "{", "Timeout", ":", "30", "*", "time", ".", "Second", ",", "KeepAlive", ":", "30", "*", "time", ".", "Second", ",", "DualStack", ":", "true", ",", "}", ")", ".", "DialContext", ",", "MaxIdleConns", ":", "100", ",", "IdleConnTimeout", ":", "90", "*", "time", ".", "Second", ",", "TLSHandshakeTimeout", ":", "10", "*", "time", ".", "Second", ",", "ExpectContinueTimeout", ":", "1", "*", "time", ".", "Second", ",", "}", "\n", "config", ".", "Transport", "=", "httpTransport", "\n", "}", "\n", "if", "httpTransport", "!=", "nil", "{", "if", "httpTransport", ".", "MaxIdleConnsPerHost", "==", "0", "{", "// Raise the default number of idle connections per host since in a database application", "// it is very likely that you want more than 2 concurrent connections to a host.", "// We raise it to avoid the extra concurrent connections being closed directly", "// after use, resulting in a lot of connection in `TIME_WAIT` state.", "httpTransport", ".", "MaxIdleConnsPerHost", "=", "DefaultMaxIdleConnsPerHost", "\n", "}", "\n", "defaultMaxIdleConns", ":=", "3", "*", "DefaultMaxIdleConnsPerHost", "\n", "if", "httpTransport", ".", "MaxIdleConns", ">", "0", "&&", "httpTransport", ".", "MaxIdleConns", "<", "defaultMaxIdleConns", "{", "// For a cluster scenario we assume the use of 3 coordinators (don't know the exact number here)", "// and derive the maximum total number of idle connections from that.", "httpTransport", ".", "MaxIdleConns", "=", "defaultMaxIdleConns", "\n", "}", "\n", "if", "config", ".", "TLSConfig", "!=", "nil", "{", "httpTransport", ".", "TLSClientConfig", "=", "config", ".", "TLSConfig", "\n", "}", "\n", "}", "\n", "httpClient", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "config", ".", "Transport", ",", "}", "\n", "if", "config", ".", "DontFollowRedirect", "{", "httpClient", ".", "CheckRedirect", "=", "func", "(", "req", "*", "http", ".", "Request", ",", "via", "[", "]", "*", "http", ".", "Request", ")", "error", "{", "return", "http", ".", "ErrUseLastResponse", "// Do not wrap, standard library will not understand", "\n", "}", "\n", "}", "else", "if", "config", ".", "FailOnRedirect", "{", "httpClient", ".", "CheckRedirect", "=", "func", "(", "req", "*", "http", ".", "Request", ",", "via", "[", "]", "*", "http", ".", "Request", ")", "error", "{", "return", "driver", ".", "ArangoError", "{", "HasError", ":", "true", ",", "Code", ":", "http", ".", "StatusFound", ",", "ErrorNum", ":", "0", ",", "ErrorMessage", ":", "\"", "\"", ",", "}", "\n", "}", "\n", "}", "\n", "var", "connPool", "chan", "int", "\n", "if", "config", ".", "ConnLimit", ">", "0", "{", "connPool", "=", "make", "(", "chan", "int", ",", "config", ".", "ConnLimit", ")", "\n", "// Fill with available tokens", "for", "i", ":=", "0", ";", "i", "<", "config", ".", "ConnLimit", ";", "i", "++", "{", "connPool", "<-", "i", "\n", "}", "\n", "}", "\n", "c", ":=", "&", "httpConnection", "{", "endpoint", ":", "*", "u", ",", "contentType", ":", "config", ".", "ContentType", ",", "client", ":", "httpClient", ",", "connPool", ":", "connPool", ",", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// newHTTPConnection creates a new HTTP connection for a single endpoint and the remainder of the given configuration settings.
[ "newHTTPConnection", "creates", "a", "new", "HTTP", "connection", "for", "a", "single", "endpoint", "and", "the", "remainder", "of", "the", "given", "configuration", "settings", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/connection.go#L103-L181
5,757
arangodb/go-driver
http/connection.go
readBody
func readBody(resp *http.Response) ([]byte, error) { defer resp.Body.Close() contentLength := resp.ContentLength if contentLength < 0 { // Don't know the content length, do it the slowest way result, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, driver.WithStack(err) } return result, nil } buf := &bytes.Buffer{} if int64(int(contentLength)) == contentLength { // contentLength is an int64. If we can safely cast to int, use Grow. buf.Grow(int(contentLength)) } if _, err := buf.ReadFrom(resp.Body); err != nil { return nil, driver.WithStack(err) } return buf.Bytes(), nil }
go
func readBody(resp *http.Response) ([]byte, error) { defer resp.Body.Close() contentLength := resp.ContentLength if contentLength < 0 { // Don't know the content length, do it the slowest way result, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, driver.WithStack(err) } return result, nil } buf := &bytes.Buffer{} if int64(int(contentLength)) == contentLength { // contentLength is an int64. If we can safely cast to int, use Grow. buf.Grow(int(contentLength)) } if _, err := buf.ReadFrom(resp.Body); err != nil { return nil, driver.WithStack(err) } return buf.Bytes(), nil }
[ "func", "readBody", "(", "resp", "*", "http", ".", "Response", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "contentLength", ":=", "resp", ".", "ContentLength", "\n", "if", "contentLength", "<", "0", "{", "// Don't know the content length, do it the slowest way", "result", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}", "\n", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "if", "int64", "(", "int", "(", "contentLength", ")", ")", "==", "contentLength", "{", "// contentLength is an int64. If we can safely cast to int, use Grow.", "buf", ".", "Grow", "(", "int", "(", "contentLength", ")", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "buf", ".", "ReadFrom", "(", "resp", ".", "Body", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// readBody reads the body of the given response into a byte slice.
[ "readBody", "reads", "the", "body", "of", "the", "given", "response", "into", "a", "byte", "slice", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/connection.go#L323-L343
5,758
arangodb/go-driver
collection_document_impl.go
parseResponseArray
func parseResponseArray(resp Response, count int, cs contextSettings, results interface{}) (DocumentMetaSlice, ErrorSlice, error) { resps, err := resp.ParseArrayBody() if err != nil { return nil, nil, WithStack(err) } metas := make(DocumentMetaSlice, count) errs := make(ErrorSlice, count) returnOldVal := reflect.ValueOf(cs.ReturnOld) returnNewVal := reflect.ValueOf(cs.ReturnNew) resultsVal := reflect.ValueOf(results) for i := 0; i < count; i++ { resp := resps[i] var meta DocumentMeta if err := resp.CheckStatus(200, 201, 202); err != nil { errs[i] = err } else { if err := resp.ParseBody("", &meta); err != nil { errs[i] = err } else { metas[i] = meta // Parse returnOld (if needed) if cs.ReturnOld != nil { returnOldEntryVal := returnOldVal.Index(i).Addr() if err := resp.ParseBody("old", returnOldEntryVal.Interface()); err != nil { errs[i] = err } } // Parse returnNew (if needed) if cs.ReturnNew != nil { returnNewEntryVal := returnNewVal.Index(i).Addr() if err := resp.ParseBody("new", returnNewEntryVal.Interface()); err != nil { errs[i] = err } } } if results != nil { // Parse compare result document resultsEntryVal := resultsVal.Index(i).Addr() if err := resp.ParseBody("", resultsEntryVal.Interface()); err != nil { errs[i] = err } } } } return metas, errs, nil }
go
func parseResponseArray(resp Response, count int, cs contextSettings, results interface{}) (DocumentMetaSlice, ErrorSlice, error) { resps, err := resp.ParseArrayBody() if err != nil { return nil, nil, WithStack(err) } metas := make(DocumentMetaSlice, count) errs := make(ErrorSlice, count) returnOldVal := reflect.ValueOf(cs.ReturnOld) returnNewVal := reflect.ValueOf(cs.ReturnNew) resultsVal := reflect.ValueOf(results) for i := 0; i < count; i++ { resp := resps[i] var meta DocumentMeta if err := resp.CheckStatus(200, 201, 202); err != nil { errs[i] = err } else { if err := resp.ParseBody("", &meta); err != nil { errs[i] = err } else { metas[i] = meta // Parse returnOld (if needed) if cs.ReturnOld != nil { returnOldEntryVal := returnOldVal.Index(i).Addr() if err := resp.ParseBody("old", returnOldEntryVal.Interface()); err != nil { errs[i] = err } } // Parse returnNew (if needed) if cs.ReturnNew != nil { returnNewEntryVal := returnNewVal.Index(i).Addr() if err := resp.ParseBody("new", returnNewEntryVal.Interface()); err != nil { errs[i] = err } } } if results != nil { // Parse compare result document resultsEntryVal := resultsVal.Index(i).Addr() if err := resp.ParseBody("", resultsEntryVal.Interface()); err != nil { errs[i] = err } } } } return metas, errs, nil }
[ "func", "parseResponseArray", "(", "resp", "Response", ",", "count", "int", ",", "cs", "contextSettings", ",", "results", "interface", "{", "}", ")", "(", "DocumentMetaSlice", ",", "ErrorSlice", ",", "error", ")", "{", "resps", ",", "err", ":=", "resp", ".", "ParseArrayBody", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "metas", ":=", "make", "(", "DocumentMetaSlice", ",", "count", ")", "\n", "errs", ":=", "make", "(", "ErrorSlice", ",", "count", ")", "\n", "returnOldVal", ":=", "reflect", ".", "ValueOf", "(", "cs", ".", "ReturnOld", ")", "\n", "returnNewVal", ":=", "reflect", ".", "ValueOf", "(", "cs", ".", "ReturnNew", ")", "\n", "resultsVal", ":=", "reflect", ".", "ValueOf", "(", "results", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "resp", ":=", "resps", "[", "i", "]", "\n", "var", "meta", "DocumentMeta", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "200", ",", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "}", "else", "{", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "meta", ")", ";", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "}", "else", "{", "metas", "[", "i", "]", "=", "meta", "\n", "// Parse returnOld (if needed)", "if", "cs", ".", "ReturnOld", "!=", "nil", "{", "returnOldEntryVal", ":=", "returnOldVal", ".", "Index", "(", "i", ")", ".", "Addr", "(", ")", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "returnOldEntryVal", ".", "Interface", "(", ")", ")", ";", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "}", "\n", "}", "\n", "// Parse returnNew (if needed)", "if", "cs", ".", "ReturnNew", "!=", "nil", "{", "returnNewEntryVal", ":=", "returnNewVal", ".", "Index", "(", "i", ")", ".", "Addr", "(", ")", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "returnNewEntryVal", ".", "Interface", "(", ")", ")", ";", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "results", "!=", "nil", "{", "// Parse compare result document", "resultsEntryVal", ":=", "resultsVal", ".", "Index", "(", "i", ")", ".", "Addr", "(", ")", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "resultsEntryVal", ".", "Interface", "(", ")", ")", ";", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "metas", ",", "errs", ",", "nil", "\n", "}" ]
// parseResponseArray parses an array response in the given response
[ "parseResponseArray", "parses", "an", "array", "response", "in", "the", "given", "response" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/collection_document_impl.go#L631-L676
5,759
arangodb/go-driver
graph_impl.go
newGraph
func newGraph(name string, db *database) (Graph, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &graph{ name: name, db: db, conn: db.conn, }, nil }
go
func newGraph(name string, db *database) (Graph, error) { if name == "" { return nil, WithStack(InvalidArgumentError{Message: "name is empty"}) } if db == nil { return nil, WithStack(InvalidArgumentError{Message: "db is nil"}) } return &graph{ name: name, db: db, conn: db.conn, }, nil }
[ "func", "newGraph", "(", "name", "string", ",", "db", "*", "database", ")", "(", "Graph", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "if", "db", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "&", "graph", "{", "name", ":", "name", ",", "db", ":", "db", ",", "conn", ":", "db", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newGraph creates a new Graph implementation.
[ "newGraph", "creates", "a", "new", "Graph", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_impl.go#L31-L43
5,760
arangodb/go-driver
graph_impl.go
Remove
func (g *graph) Remove(ctx context.Context) error { req, err := g.conn.NewRequest("DELETE", g.relPath()) if err != nil { return WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(201, 202); err != nil { return WithStack(err) } return nil }
go
func (g *graph) Remove(ctx context.Context) error { req, err := g.conn.NewRequest("DELETE", g.relPath()) if err != nil { return WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return WithStack(err) } if err := resp.CheckStatus(201, 202); err != nil { return WithStack(err) } return nil }
[ "func", "(", "g", "*", "graph", ")", "Remove", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "g", ".", "relPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "conn", ".", "Do", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "resp", ".", "CheckStatus", "(", "201", ",", "202", ")", ";", "err", "!=", "nil", "{", "return", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Remove removes the entire graph. // If the graph does not exist, a NotFoundError is returned.
[ "Remove", "removes", "the", "entire", "graph", ".", "If", "the", "graph", "does", "not", "exist", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_impl.go#L64-L77
5,761
arangodb/go-driver
vst/protocol/chunk_1_1.go
readChunkVST1_1
func readChunkVST1_1(r io.Reader) (chunk, error) { hdr := [maxChunkHeaderSize]byte{} if err := readBytes(hdr[:maxChunkHeaderSize], r); err != nil { return chunk{}, driver.WithStack(err) } le := binary.LittleEndian length := le.Uint32(hdr[0:]) chunkX := le.Uint32(hdr[4:]) messageID := le.Uint64(hdr[8:]) messageLength := le.Uint64(hdr[16:]) contentLength := length - maxChunkHeaderSize data := make([]byte, contentLength) if err := readBytes(data, r); err != nil { return chunk{}, driver.WithStack(err) } //fmt.Printf("data: " + hex.EncodeToString(data) + "\n") return chunk{ chunkX: chunkX, MessageID: messageID, MessageLength: messageLength, Data: data, }, nil }
go
func readChunkVST1_1(r io.Reader) (chunk, error) { hdr := [maxChunkHeaderSize]byte{} if err := readBytes(hdr[:maxChunkHeaderSize], r); err != nil { return chunk{}, driver.WithStack(err) } le := binary.LittleEndian length := le.Uint32(hdr[0:]) chunkX := le.Uint32(hdr[4:]) messageID := le.Uint64(hdr[8:]) messageLength := le.Uint64(hdr[16:]) contentLength := length - maxChunkHeaderSize data := make([]byte, contentLength) if err := readBytes(data, r); err != nil { return chunk{}, driver.WithStack(err) } //fmt.Printf("data: " + hex.EncodeToString(data) + "\n") return chunk{ chunkX: chunkX, MessageID: messageID, MessageLength: messageLength, Data: data, }, nil }
[ "func", "readChunkVST1_1", "(", "r", "io", ".", "Reader", ")", "(", "chunk", ",", "error", ")", "{", "hdr", ":=", "[", "maxChunkHeaderSize", "]", "byte", "{", "}", "\n", "if", "err", ":=", "readBytes", "(", "hdr", "[", ":", "maxChunkHeaderSize", "]", ",", "r", ")", ";", "err", "!=", "nil", "{", "return", "chunk", "{", "}", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "le", ":=", "binary", ".", "LittleEndian", "\n", "length", ":=", "le", ".", "Uint32", "(", "hdr", "[", "0", ":", "]", ")", "\n", "chunkX", ":=", "le", ".", "Uint32", "(", "hdr", "[", "4", ":", "]", ")", "\n", "messageID", ":=", "le", ".", "Uint64", "(", "hdr", "[", "8", ":", "]", ")", "\n", "messageLength", ":=", "le", ".", "Uint64", "(", "hdr", "[", "16", ":", "]", ")", "\n", "contentLength", ":=", "length", "-", "maxChunkHeaderSize", "\n\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "contentLength", ")", "\n", "if", "err", ":=", "readBytes", "(", "data", ",", "r", ")", ";", "err", "!=", "nil", "{", "return", "chunk", "{", "}", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "//fmt.Printf(\"data: \" + hex.EncodeToString(data) + \"\\n\")", "return", "chunk", "{", "chunkX", ":", "chunkX", ",", "MessageID", ":", "messageID", ",", "MessageLength", ":", "messageLength", ",", "Data", ":", "data", ",", "}", ",", "nil", "\n", "}" ]
// readChunkVST1_1 reads an entire chunk from the given reader in VST 1.1 format.
[ "readChunkVST1_1", "reads", "an", "entire", "chunk", "from", "the", "given", "reader", "in", "VST", "1", ".", "1", "format", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/chunk_1_1.go#L33-L56
5,762
arangodb/go-driver
vst/protocol/chunk_1_1.go
WriteToVST1_1
func (c chunk) WriteToVST1_1(w io.Writer) (int64, error) { le := binary.LittleEndian hdr := [maxChunkHeaderSize]byte{} le.PutUint32(hdr[0:], uint32(len(c.Data)+len(hdr))) // length le.PutUint32(hdr[4:], c.chunkX) // chunkX le.PutUint64(hdr[8:], c.MessageID) // message ID le.PutUint64(hdr[16:], c.MessageLength) // message length // Write header //fmt.Printf("Writing hdr: %s\n", hex.EncodeToString(hdr)) if n, err := w.Write(hdr[:]); err != nil { return int64(n), driver.WithStack(err) } // Write data //fmt.Printf("Writing data: %s\n", hex.EncodeToString(c.Data)) n, err := w.Write(c.Data) result := int64(n) + int64(len(hdr)) if err != nil { return result, driver.WithStack(err) } return result, nil }
go
func (c chunk) WriteToVST1_1(w io.Writer) (int64, error) { le := binary.LittleEndian hdr := [maxChunkHeaderSize]byte{} le.PutUint32(hdr[0:], uint32(len(c.Data)+len(hdr))) // length le.PutUint32(hdr[4:], c.chunkX) // chunkX le.PutUint64(hdr[8:], c.MessageID) // message ID le.PutUint64(hdr[16:], c.MessageLength) // message length // Write header //fmt.Printf("Writing hdr: %s\n", hex.EncodeToString(hdr)) if n, err := w.Write(hdr[:]); err != nil { return int64(n), driver.WithStack(err) } // Write data //fmt.Printf("Writing data: %s\n", hex.EncodeToString(c.Data)) n, err := w.Write(c.Data) result := int64(n) + int64(len(hdr)) if err != nil { return result, driver.WithStack(err) } return result, nil }
[ "func", "(", "c", "chunk", ")", "WriteToVST1_1", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "le", ":=", "binary", ".", "LittleEndian", "\n", "hdr", ":=", "[", "maxChunkHeaderSize", "]", "byte", "{", "}", "\n\n", "le", ".", "PutUint32", "(", "hdr", "[", "0", ":", "]", ",", "uint32", "(", "len", "(", "c", ".", "Data", ")", "+", "len", "(", "hdr", ")", ")", ")", "// length", "\n", "le", ".", "PutUint32", "(", "hdr", "[", "4", ":", "]", ",", "c", ".", "chunkX", ")", "// chunkX", "\n", "le", ".", "PutUint64", "(", "hdr", "[", "8", ":", "]", ",", "c", ".", "MessageID", ")", "// message ID", "\n", "le", ".", "PutUint64", "(", "hdr", "[", "16", ":", "]", ",", "c", ".", "MessageLength", ")", "// message length", "\n\n", "// Write header", "//fmt.Printf(\"Writing hdr: %s\\n\", hex.EncodeToString(hdr))", "if", "n", ",", "err", ":=", "w", ".", "Write", "(", "hdr", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "int64", "(", "n", ")", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "// Write data", "//fmt.Printf(\"Writing data: %s\\n\", hex.EncodeToString(c.Data))", "n", ",", "err", ":=", "w", ".", "Write", "(", "c", ".", "Data", ")", "\n", "result", ":=", "int64", "(", "n", ")", "+", "int64", "(", "len", "(", "hdr", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// WriteToVST1_1 write the chunk to the given writer in VST 1.0 format. // An error is returned when less than the entire chunk was written.
[ "WriteToVST1_1", "write", "the", "chunk", "to", "the", "given", "writer", "in", "VST", "1", ".", "0", "format", ".", "An", "error", "is", "returned", "when", "less", "than", "the", "entire", "chunk", "was", "written", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/chunk_1_1.go#L60-L83
5,763
arangodb/go-driver
database_collections_impl.go
Collection
func (d *database) Collection(ctx context.Context, name string) (Collection, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/collection", 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) } coll, err := newCollection(name, d) if err != nil { return nil, WithStack(err) } return coll, nil }
go
func (d *database) Collection(ctx context.Context, name string) (Collection, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/collection", 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) } coll, err := newCollection(name, d) if err != nil { return nil, WithStack(err) } return coll, nil }
[ "func", "(", "d", "*", "database", ")", "Collection", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "Collection", ",", "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", "coll", ",", "err", ":=", "newCollection", "(", "name", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "coll", ",", "nil", "\n", "}" ]
// Collection opens a connection to an existing collection within the database. // If no collection with given name exists, an NotFoundError is returned.
[ "Collection", "opens", "a", "connection", "to", "an", "existing", "collection", "within", "the", "database", ".", "If", "no", "collection", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_collections_impl.go#L32-L50
5,764
arangodb/go-driver
database_collections_impl.go
Collections
func (d *database) Collections(ctx context.Context) ([]Collection, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/collection")) 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 getCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Collection, 0, len(data.Result)) for _, info := range data.Result { col, err := newCollection(info.Name, d) if err != nil { return nil, WithStack(err) } result = append(result, col) } return result, nil }
go
func (d *database) Collections(ctx context.Context) ([]Collection, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/collection")) 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 getCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Collection, 0, len(data.Result)) for _, info := range data.Result { col, err := newCollection(info.Name, d) if err != nil { return nil, WithStack(err) } result = append(result, col) } return result, nil }
[ "func", "(", "d", "*", "database", ")", "Collections", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Collection", ",", "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", "getCollectionResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Collection", ",", "0", ",", "len", "(", "data", ".", "Result", ")", ")", "\n", "for", "_", ",", "info", ":=", "range", "data", ".", "Result", "{", "col", ",", "err", ":=", "newCollection", "(", "info", ".", "Name", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "col", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Collections returns a list of all collections in the database.
[ "Collections", "returns", "a", "list", "of", "all", "collections", "in", "the", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_collections_impl.go#L77-L102
5,765
arangodb/go-driver
database_collections_impl.go
CreateCollection
func (d *database) CreateCollection(ctx context.Context, name string, options *CreateCollectionOptions) (Collection, error) { input := createCollectionOptionsInternal{ Name: name, } if options != nil { input.fromExternal(options) } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/collection")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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) } col, err := newCollection(name, d) if err != nil { return nil, WithStack(err) } return col, nil }
go
func (d *database) CreateCollection(ctx context.Context, name string, options *CreateCollectionOptions) (Collection, error) { input := createCollectionOptionsInternal{ Name: name, } if options != nil { input.fromExternal(options) } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/collection")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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) } col, err := newCollection(name, d) if err != nil { return nil, WithStack(err) } return col, nil }
[ "func", "(", "d", "*", "database", ")", "CreateCollection", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "options", "*", "CreateCollectionOptions", ")", "(", "Collection", ",", "error", ")", "{", "input", ":=", "createCollectionOptionsInternal", "{", "Name", ":", "name", ",", "}", "\n", "if", "options", "!=", "nil", "{", "input", ".", "fromExternal", "(", "options", ")", "\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", "applyContextSettings", "(", "ctx", ",", "req", ")", "\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", "col", ",", "err", ":=", "newCollection", "(", "name", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "col", ",", "nil", "\n", "}" ]
// CreateCollection creates a new collection with given name and options, and opens a connection to it. // If a collection with given name already exists within the database, a DuplicateError is returned.
[ "CreateCollection", "creates", "a", "new", "collection", "with", "given", "name", "and", "options", "and", "opens", "a", "connection", "to", "it", ".", "If", "a", "collection", "with", "given", "name", "already", "exists", "within", "the", "database", "a", "DuplicateError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_collections_impl.go#L126-L153
5,766
arangodb/go-driver
vst/response.go
newResponse
func newResponse(msgData []byte, endpoint string, rawResponse *[]byte) (*vstResponse, error) { // Decode header hdr := velocypack.Slice(msgData) if err := hdr.AssertType(velocypack.Array); err != nil { return nil, driver.WithStack(err) } //panic("hdr: " + hex.EncodeToString(hdr)) var hdrLen velocypack.ValueLength if l, err := hdr.Length(); err != nil { return nil, driver.WithStack(err) } else if l < 3 { return nil, driver.WithStack(fmt.Errorf("Expected a header of 3 elements, got %d", l)) } else { hdrLen = l } resp := &vstResponse{ endpoint: endpoint, } // Decode version if elem, err := hdr.At(0); err != nil { return nil, driver.WithStack(err) } else if version, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.Version = int(version) } // Decode type if elem, err := hdr.At(1); err != nil { return nil, driver.WithStack(err) } else if tp, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.Type = int(tp) } // Decode responseCode if elem, err := hdr.At(2); err != nil { return nil, driver.WithStack(err) } else if code, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.ResponseCode = int(code) } // Decode meta if hdrLen >= 4 { if elem, err := hdr.At(3); err != nil { return nil, driver.WithStack(err) } else if !elem.IsObject() { return nil, driver.WithStack(fmt.Errorf("Expected meta field to be of type Object, got %s", elem.Type())) } else { resp.meta = elem } } // Fetch body directly after hdr if body, err := hdr.Next(); err != nil { return nil, driver.WithStack(err) } else { resp.slice = body if rawResponse != nil { *rawResponse = body } } //fmt.Printf("got response: code=%d, body=%s\n", resp.ResponseCode, hex.EncodeToString(resp.slice)) return resp, nil }
go
func newResponse(msgData []byte, endpoint string, rawResponse *[]byte) (*vstResponse, error) { // Decode header hdr := velocypack.Slice(msgData) if err := hdr.AssertType(velocypack.Array); err != nil { return nil, driver.WithStack(err) } //panic("hdr: " + hex.EncodeToString(hdr)) var hdrLen velocypack.ValueLength if l, err := hdr.Length(); err != nil { return nil, driver.WithStack(err) } else if l < 3 { return nil, driver.WithStack(fmt.Errorf("Expected a header of 3 elements, got %d", l)) } else { hdrLen = l } resp := &vstResponse{ endpoint: endpoint, } // Decode version if elem, err := hdr.At(0); err != nil { return nil, driver.WithStack(err) } else if version, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.Version = int(version) } // Decode type if elem, err := hdr.At(1); err != nil { return nil, driver.WithStack(err) } else if tp, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.Type = int(tp) } // Decode responseCode if elem, err := hdr.At(2); err != nil { return nil, driver.WithStack(err) } else if code, err := elem.GetInt(); err != nil { return nil, driver.WithStack(err) } else { resp.ResponseCode = int(code) } // Decode meta if hdrLen >= 4 { if elem, err := hdr.At(3); err != nil { return nil, driver.WithStack(err) } else if !elem.IsObject() { return nil, driver.WithStack(fmt.Errorf("Expected meta field to be of type Object, got %s", elem.Type())) } else { resp.meta = elem } } // Fetch body directly after hdr if body, err := hdr.Next(); err != nil { return nil, driver.WithStack(err) } else { resp.slice = body if rawResponse != nil { *rawResponse = body } } //fmt.Printf("got response: code=%d, body=%s\n", resp.ResponseCode, hex.EncodeToString(resp.slice)) return resp, nil }
[ "func", "newResponse", "(", "msgData", "[", "]", "byte", ",", "endpoint", "string", ",", "rawResponse", "*", "[", "]", "byte", ")", "(", "*", "vstResponse", ",", "error", ")", "{", "// Decode header", "hdr", ":=", "velocypack", ".", "Slice", "(", "msgData", ")", "\n", "if", "err", ":=", "hdr", ".", "AssertType", "(", "velocypack", ".", "Array", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "//panic(\"hdr: \" + hex.EncodeToString(hdr))", "var", "hdrLen", "velocypack", ".", "ValueLength", "\n", "if", "l", ",", "err", ":=", "hdr", ".", "Length", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "if", "l", "<", "3", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "l", ")", ")", "\n", "}", "else", "{", "hdrLen", "=", "l", "\n", "}", "\n\n", "resp", ":=", "&", "vstResponse", "{", "endpoint", ":", "endpoint", ",", "}", "\n", "// Decode version", "if", "elem", ",", "err", ":=", "hdr", ".", "At", "(", "0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "if", "version", ",", "err", ":=", "elem", ".", "GetInt", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "resp", ".", "Version", "=", "int", "(", "version", ")", "\n", "}", "\n", "// Decode type", "if", "elem", ",", "err", ":=", "hdr", ".", "At", "(", "1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "if", "tp", ",", "err", ":=", "elem", ".", "GetInt", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "resp", ".", "Type", "=", "int", "(", "tp", ")", "\n", "}", "\n", "// Decode responseCode", "if", "elem", ",", "err", ":=", "hdr", ".", "At", "(", "2", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "if", "code", ",", "err", ":=", "elem", ".", "GetInt", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "resp", ".", "ResponseCode", "=", "int", "(", "code", ")", "\n", "}", "\n", "// Decode meta", "if", "hdrLen", ">=", "4", "{", "if", "elem", ",", "err", ":=", "hdr", ".", "At", "(", "3", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "if", "!", "elem", ".", "IsObject", "(", ")", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "elem", ".", "Type", "(", ")", ")", ")", "\n", "}", "else", "{", "resp", ".", "meta", "=", "elem", "\n", "}", "\n", "}", "\n\n", "// Fetch body directly after hdr", "if", "body", ",", "err", ":=", "hdr", ".", "Next", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "driver", ".", "WithStack", "(", "err", ")", "\n", "}", "else", "{", "resp", ".", "slice", "=", "body", "\n", "if", "rawResponse", "!=", "nil", "{", "*", "rawResponse", "=", "body", "\n", "}", "\n", "}", "\n", "//fmt.Printf(\"got response: code=%d, body=%s\\n\", resp.ResponseCode, hex.EncodeToString(resp.slice))", "return", "resp", ",", "nil", "\n", "}" ]
// newResponse builds a vstResponse from given message.
[ "newResponse", "builds", "a", "vstResponse", "from", "given", "message", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/response.go#L48-L113
5,767
arangodb/go-driver
vertex_collection_documents_impl.go
ReplaceDocument
func (c *vertexCollection) ReplaceDocument(ctx context.Context, key string, document interface{}) (DocumentMeta, error) { meta, _, err := c.replaceDocument(ctx, key, document) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
go
func (c *vertexCollection) ReplaceDocument(ctx context.Context, key string, document interface{}) (DocumentMeta, error) { meta, _, err := c.replaceDocument(ctx, key, document) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
[ "func", "(", "c", "*", "vertexCollection", ")", "ReplaceDocument", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "document", "interface", "{", "}", ")", "(", "DocumentMeta", ",", "error", ")", "{", "meta", ",", "_", ",", "err", ":=", "c", ".", "replaceDocument", "(", "ctx", ",", "key", ",", "document", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "meta", ",", "nil", "\n", "}" ]
// ReplaceDocument replaces a single document with given key in the collection with the document given in the document argument. // The document meta data is returned. // To return the NEW document, prepare a context with `WithReturnNew`. // To return the OLD document, prepare a context with `WithReturnOld`. // To wait until document has been synced to disk, prepare a context with `WithWaitForSync`. // If no document exists with given key, a NotFoundError is returned.
[ "ReplaceDocument", "replaces", "a", "single", "document", "with", "given", "key", "in", "the", "collection", "with", "the", "document", "given", "in", "the", "document", "argument", ".", "The", "document", "meta", "data", "is", "returned", ".", "To", "return", "the", "NEW", "document", "prepare", "a", "context", "with", "WithReturnNew", ".", "To", "return", "the", "OLD", "document", "prepare", "a", "context", "with", "WithReturnOld", ".", "To", "wait", "until", "document", "has", "been", "synced", "to", "disk", "prepare", "a", "context", "with", "WithWaitForSync", ".", "If", "no", "document", "exists", "with", "given", "key", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vertex_collection_documents_impl.go#L351-L357
5,768
arangodb/go-driver
vertex_collection_documents_impl.go
ReplaceDocuments
func (c *vertexCollection) ReplaceDocuments(ctx context.Context, keys []string, documents interface{}) (DocumentMetaSlice, ErrorSlice, error) { documentsVal := reflect.ValueOf(documents) switch documentsVal.Kind() { case reflect.Array, reflect.Slice: // OK default: return nil, nil, WithStack(InvalidArgumentError{Message: fmt.Sprintf("documents data must be of kind Array, got %s", documentsVal.Kind())}) } documentCount := documentsVal.Len() if keys != nil { if len(keys) != documentCount { return nil, nil, WithStack(InvalidArgumentError{Message: fmt.Sprintf("expected %d keys, got %d", documentCount, len(keys))}) } for _, key := range keys { if err := validateKey(key); err != nil { return nil, nil, WithStack(err) } } } metas := make(DocumentMetaSlice, documentCount) errs := make(ErrorSlice, documentCount) silent := false for i := 0; i < documentCount; i++ { doc := documentsVal.Index(i) ctx, err := withDocumentAt(ctx, i) if err != nil { return nil, nil, WithStack(err) } var key string if keys != nil { key = keys[i] } else { var err error key, err = getKeyFromDocument(doc) if err != nil { errs[i] = err continue } } meta, cs, err := c.replaceDocument(ctx, key, doc.Interface()) if cs.Silent { silent = true } else { metas[i], errs[i] = meta, err } } if silent { return nil, nil, nil } return metas, errs, nil }
go
func (c *vertexCollection) ReplaceDocuments(ctx context.Context, keys []string, documents interface{}) (DocumentMetaSlice, ErrorSlice, error) { documentsVal := reflect.ValueOf(documents) switch documentsVal.Kind() { case reflect.Array, reflect.Slice: // OK default: return nil, nil, WithStack(InvalidArgumentError{Message: fmt.Sprintf("documents data must be of kind Array, got %s", documentsVal.Kind())}) } documentCount := documentsVal.Len() if keys != nil { if len(keys) != documentCount { return nil, nil, WithStack(InvalidArgumentError{Message: fmt.Sprintf("expected %d keys, got %d", documentCount, len(keys))}) } for _, key := range keys { if err := validateKey(key); err != nil { return nil, nil, WithStack(err) } } } metas := make(DocumentMetaSlice, documentCount) errs := make(ErrorSlice, documentCount) silent := false for i := 0; i < documentCount; i++ { doc := documentsVal.Index(i) ctx, err := withDocumentAt(ctx, i) if err != nil { return nil, nil, WithStack(err) } var key string if keys != nil { key = keys[i] } else { var err error key, err = getKeyFromDocument(doc) if err != nil { errs[i] = err continue } } meta, cs, err := c.replaceDocument(ctx, key, doc.Interface()) if cs.Silent { silent = true } else { metas[i], errs[i] = meta, err } } if silent { return nil, nil, nil } return metas, errs, nil }
[ "func", "(", "c", "*", "vertexCollection", ")", "ReplaceDocuments", "(", "ctx", "context", ".", "Context", ",", "keys", "[", "]", "string", ",", "documents", "interface", "{", "}", ")", "(", "DocumentMetaSlice", ",", "ErrorSlice", ",", "error", ")", "{", "documentsVal", ":=", "reflect", ".", "ValueOf", "(", "documents", ")", "\n", "switch", "documentsVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Array", ",", "reflect", ".", "Slice", ":", "// OK", "default", ":", "return", "nil", ",", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "documentsVal", ".", "Kind", "(", ")", ")", "}", ")", "\n", "}", "\n", "documentCount", ":=", "documentsVal", ".", "Len", "(", ")", "\n", "if", "keys", "!=", "nil", "{", "if", "len", "(", "keys", ")", "!=", "documentCount", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "documentCount", ",", "len", "(", "keys", ")", ")", "}", ")", "\n", "}", "\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "if", "err", ":=", "validateKey", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "metas", ":=", "make", "(", "DocumentMetaSlice", ",", "documentCount", ")", "\n", "errs", ":=", "make", "(", "ErrorSlice", ",", "documentCount", ")", "\n", "silent", ":=", "false", "\n", "for", "i", ":=", "0", ";", "i", "<", "documentCount", ";", "i", "++", "{", "doc", ":=", "documentsVal", ".", "Index", "(", "i", ")", "\n", "ctx", ",", "err", ":=", "withDocumentAt", "(", "ctx", ",", "i", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "key", "string", "\n", "if", "keys", "!=", "nil", "{", "key", "=", "keys", "[", "i", "]", "\n", "}", "else", "{", "var", "err", "error", "\n", "key", ",", "err", "=", "getKeyFromDocument", "(", "doc", ")", "\n", "if", "err", "!=", "nil", "{", "errs", "[", "i", "]", "=", "err", "\n", "continue", "\n", "}", "\n", "}", "\n", "meta", ",", "cs", ",", "err", ":=", "c", ".", "replaceDocument", "(", "ctx", ",", "key", ",", "doc", ".", "Interface", "(", ")", ")", "\n", "if", "cs", ".", "Silent", "{", "silent", "=", "true", "\n", "}", "else", "{", "metas", "[", "i", "]", ",", "errs", "[", "i", "]", "=", "meta", ",", "err", "\n", "}", "\n", "}", "\n", "if", "silent", "{", "return", "nil", ",", "nil", ",", "nil", "\n", "}", "\n", "return", "metas", ",", "errs", ",", "nil", "\n", "}" ]
// ReplaceDocuments replaces multiple documents with given keys in the collection with the documents given in the documents argument. // The replacements are loaded from the given documents slice, the documents meta data are returned. // To return the NEW documents, prepare a context with `WithReturnNew` with a slice of documents. // To return the OLD documents, prepare a context with `WithReturnOld` with a slice of documents. // To wait until documents has been synced to disk, prepare a context with `WithWaitForSync`. // If no document exists with a given key, a NotFoundError is returned at its errors index.
[ "ReplaceDocuments", "replaces", "multiple", "documents", "with", "given", "keys", "in", "the", "collection", "with", "the", "documents", "given", "in", "the", "documents", "argument", ".", "The", "replacements", "are", "loaded", "from", "the", "given", "documents", "slice", "the", "documents", "meta", "data", "are", "returned", ".", "To", "return", "the", "NEW", "documents", "prepare", "a", "context", "with", "WithReturnNew", "with", "a", "slice", "of", "documents", ".", "To", "return", "the", "OLD", "documents", "prepare", "a", "context", "with", "WithReturnOld", "with", "a", "slice", "of", "documents", ".", "To", "wait", "until", "documents", "has", "been", "synced", "to", "disk", "prepare", "a", "context", "with", "WithWaitForSync", ".", "If", "no", "document", "exists", "with", "a", "given", "key", "a", "NotFoundError", "is", "returned", "at", "its", "errors", "index", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vertex_collection_documents_impl.go#L412-L462
5,769
arangodb/go-driver
vertex_collection_documents_impl.go
RemoveDocument
func (c *vertexCollection) RemoveDocument(ctx context.Context, key string) (DocumentMeta, error) { meta, _, err := c.removeDocument(ctx, key) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
go
func (c *vertexCollection) RemoveDocument(ctx context.Context, key string) (DocumentMeta, error) { meta, _, err := c.removeDocument(ctx, key) if err != nil { return DocumentMeta{}, WithStack(err) } return meta, nil }
[ "func", "(", "c", "*", "vertexCollection", ")", "RemoveDocument", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "(", "DocumentMeta", ",", "error", ")", "{", "meta", ",", "_", ",", "err", ":=", "c", ".", "removeDocument", "(", "ctx", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "DocumentMeta", "{", "}", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "meta", ",", "nil", "\n", "}" ]
// RemoveDocument removes a single document with given key from the collection. // The document meta data is returned. // To return the OLD document, prepare a context with `WithReturnOld`. // To wait until removal has been synced to disk, prepare a context with `WithWaitForSync`. // If no document exists with given key, a NotFoundError is returned.
[ "RemoveDocument", "removes", "a", "single", "document", "with", "given", "key", "from", "the", "collection", ".", "The", "document", "meta", "data", "is", "returned", ".", "To", "return", "the", "OLD", "document", "prepare", "a", "context", "with", "WithReturnOld", ".", "To", "wait", "until", "removal", "has", "been", "synced", "to", "disk", "prepare", "a", "context", "with", "WithWaitForSync", ".", "If", "no", "document", "exists", "with", "given", "key", "a", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vertex_collection_documents_impl.go#L469-L475
5,770
arangodb/go-driver
database_views_impl.go
View
func (d *database) View(ctx context.Context, name string) (View, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view", escapedName)) if err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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 viewInfo if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } view, err := newView(name, data.Type, d) if err != nil { return nil, WithStack(err) } return view, nil }
go
func (d *database) View(ctx context.Context, name string) (View, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view", escapedName)) if err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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 viewInfo if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } view, err := newView(name, data.Type, d) if err != nil { return nil, WithStack(err) } return view, nil }
[ "func", "(", "d", "*", "database", ")", "View", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "View", ",", "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", "applyContextSettings", "(", "ctx", ",", "req", ")", "\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", "viewInfo", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "view", ",", "err", ":=", "newView", "(", "name", ",", "data", ".", "Type", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "view", ",", "nil", "\n", "}" ]
// View opens a connection to an existing view within the database. // If no collection with given name exists, an NotFoundError is returned.
[ "View", "opens", "a", "connection", "to", "an", "existing", "view", "within", "the", "database", ".", "If", "no", "collection", "with", "given", "name", "exists", "an", "NotFoundError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_views_impl.go#L42-L65
5,771
arangodb/go-driver
database_views_impl.go
ViewExists
func (d *database) ViewExists(ctx context.Context, name string) (bool, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view", escapedName)) if err != nil { return false, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.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 (d *database) ViewExists(ctx context.Context, name string) (bool, error) { escapedName := pathEscape(name) req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view", escapedName)) if err != nil { return false, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.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", "(", "d", "*", "database", ")", "ViewExists", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "escapedName", ":=", "pathEscape", "(", "name", ")", "\n", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ",", "escapedName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "d", ".", "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", "}" ]
// ViewExists returns true if a view with given name exists within the database.
[ "ViewExists", "returns", "true", "if", "a", "view", "with", "given", "name", "exists", "within", "the", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_views_impl.go#L68-L86
5,772
arangodb/go-driver
database_views_impl.go
Views
func (d *database) Views(ctx context.Context) ([]View, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view")) if err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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 getViewResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]View, 0, len(data.Result)) for _, info := range data.Result { view, err := newView(info.Name, info.Type, d) if err != nil { return nil, WithStack(err) } result = append(result, view) } return result, nil }
go
func (d *database) Views(ctx context.Context) ([]View, error) { req, err := d.conn.NewRequest("GET", path.Join(d.relPath(), "_api/view")) if err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) 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 getViewResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]View, 0, len(data.Result)) for _, info := range data.Result { view, err := newView(info.Name, info.Type, d) if err != nil { return nil, WithStack(err) } result = append(result, view) } return result, nil }
[ "func", "(", "d", "*", "database", ")", "Views", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "View", ",", "error", ")", "{", "req", ",", "err", ":=", "d", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "d", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "applyContextSettings", "(", "ctx", ",", "req", ")", "\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", "getViewResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "View", ",", "0", ",", "len", "(", "data", ".", "Result", ")", ")", "\n", "for", "_", ",", "info", ":=", "range", "data", ".", "Result", "{", "view", ",", "err", ":=", "newView", "(", "info", ".", "Name", ",", "info", ".", "Type", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "view", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Views returns a list of all views in the database.
[ "Views", "returns", "a", "list", "of", "all", "views", "in", "the", "database", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_views_impl.go#L89-L115
5,773
arangodb/go-driver
database_views_impl.go
CreateArangoSearchView
func (d *database) CreateArangoSearchView(ctx context.Context, name string, options *ArangoSearchViewProperties) (ArangoSearchView, error) { input := struct { Name string `json:"name"` Type ViewType `json:"type"` ArangoSearchViewProperties // `json:"properties"` }{ Name: name, Type: ViewTypeArangoSearch, } if options != nil { input.ArangoSearchViewProperties = *options } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/view")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } view, err := newView(name, input.Type, d) if err != nil { return nil, WithStack(err) } result, err := view.ArangoSearchView() if err != nil { return nil, WithStack(err) } return result, nil }
go
func (d *database) CreateArangoSearchView(ctx context.Context, name string, options *ArangoSearchViewProperties) (ArangoSearchView, error) { input := struct { Name string `json:"name"` Type ViewType `json:"type"` ArangoSearchViewProperties // `json:"properties"` }{ Name: name, Type: ViewTypeArangoSearch, } if options != nil { input.ArangoSearchViewProperties = *options } req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/view")) if err != nil { return nil, WithStack(err) } if _, err := req.SetBody(input); err != nil { return nil, WithStack(err) } applyContextSettings(ctx, req) resp, err := d.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(201); err != nil { return nil, WithStack(err) } view, err := newView(name, input.Type, d) if err != nil { return nil, WithStack(err) } result, err := view.ArangoSearchView() if err != nil { return nil, WithStack(err) } return result, nil }
[ "func", "(", "d", "*", "database", ")", "CreateArangoSearchView", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "options", "*", "ArangoSearchViewProperties", ")", "(", "ArangoSearchView", ",", "error", ")", "{", "input", ":=", "struct", "{", "Name", "string", "`json:\"name\"`", "\n", "Type", "ViewType", "`json:\"type\"`", "\n", "ArangoSearchViewProperties", "// `json:\"properties\"`", "\n", "}", "{", "Name", ":", "name", ",", "Type", ":", "ViewTypeArangoSearch", ",", "}", "\n", "if", "options", "!=", "nil", "{", "input", ".", "ArangoSearchViewProperties", "=", "*", "options", "\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", "applyContextSettings", "(", "ctx", ",", "req", ")", "\n", "resp", ",", "err", ":=", "d", ".", "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", "view", ",", "err", ":=", "newView", "(", "name", ",", "input", ".", "Type", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ",", "err", ":=", "view", ".", "ArangoSearchView", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// CreateArangoSearchView creates a new view of type ArangoSearch, // with given name and options, and opens a connection to it. // If a view with given name already exists within the database, a ConflictError is returned.
[ "CreateArangoSearchView", "creates", "a", "new", "view", "of", "type", "ArangoSearch", "with", "given", "name", "and", "options", "and", "opens", "a", "connection", "to", "it", ".", "If", "a", "view", "with", "given", "name", "already", "exists", "within", "the", "database", "a", "ConflictError", "is", "returned", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/database_views_impl.go#L120-L157
5,774
arangodb/go-driver
graph_vertex_collections_impl.go
VertexCollection
func (g *graph) VertexCollection(ctx context.Context, name string) (Collection, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) if err != nil { return nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } for _, n := range data.Collections { if n == name { ec, err := newVertexCollection(name, g) if err != nil { return nil, WithStack(err) } return ec, nil } } return nil, WithStack(newArangoError(404, 0, "not found")) }
go
func (g *graph) VertexCollection(ctx context.Context, name string) (Collection, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) if err != nil { return nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } for _, n := range data.Collections { if n == name { ec, err := newVertexCollection(name, g) if err != nil { return nil, WithStack(err) } return ec, nil } } return nil, WithStack(newArangoError(404, 0, "not found")) }
[ "func", "(", "g", "*", "graph", ")", "VertexCollection", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "Collection", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "g", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "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", "listVertexCollectionResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "n", ":=", "range", "data", ".", "Collections", "{", "if", "n", "==", "name", "{", "ec", ",", "err", ":=", "newVertexCollection", "(", "name", ",", "g", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "ec", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "WithStack", "(", "newArangoError", "(", "404", ",", "0", ",", "\"", "\"", ")", ")", "\n", "}" ]
// VertexCollection opens a connection to an existing edge-collection within the graph. // If no edge-collection with given name exists, an NotFoundError is returned.
[ "VertexCollection", "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_vertex_collections_impl.go#L36-L62
5,775
arangodb/go-driver
graph_vertex_collections_impl.go
VertexCollectionExists
func (g *graph) VertexCollectionExists(ctx context.Context, name string) (bool, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) 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 listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return false, WithStack(err) } for _, n := range data.Collections { if n == name { return true, nil } } return false, nil }
go
func (g *graph) VertexCollectionExists(ctx context.Context, name string) (bool, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) 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 listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return false, WithStack(err) } for _, n := range data.Collections { if n == name { return true, nil } } return false, nil }
[ "func", "(", "g", "*", "graph", ")", "VertexCollectionExists", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "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", "listVertexCollectionResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "for", "_", ",", "n", ":=", "range", "data", ".", "Collections", "{", "if", "n", "==", "name", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// VertexCollectionExists returns true if an edge-collection with given name exists within the graph.
[ "VertexCollectionExists", "returns", "true", "if", "an", "edge", "-", "collection", "with", "given", "name", "exists", "within", "the", "graph", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_vertex_collections_impl.go#L65-L87
5,776
arangodb/go-driver
graph_vertex_collections_impl.go
VertexCollections
func (g *graph) VertexCollections(ctx context.Context) ([]Collection, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) if err != nil { return nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Collection, 0, len(data.Collections)) for _, name := range data.Collections { ec, err := newVertexCollection(name, g) if err != nil { return nil, WithStack(err) } result = append(result, ec) } return result, nil }
go
func (g *graph) VertexCollections(ctx context.Context) ([]Collection, error) { req, err := g.conn.NewRequest("GET", path.Join(g.relPath(), "vertex")) if err != nil { return nil, WithStack(err) } resp, err := g.conn.Do(ctx, req) if err != nil { return nil, WithStack(err) } if err := resp.CheckStatus(200); err != nil { return nil, WithStack(err) } var data listVertexCollectionResponse if err := resp.ParseBody("", &data); err != nil { return nil, WithStack(err) } result := make([]Collection, 0, len(data.Collections)) for _, name := range data.Collections { ec, err := newVertexCollection(name, g) if err != nil { return nil, WithStack(err) } result = append(result, ec) } return result, nil }
[ "func", "(", "g", "*", "graph", ")", "VertexCollections", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Collection", ",", "error", ")", "{", "req", ",", "err", ":=", "g", ".", "conn", ".", "NewRequest", "(", "\"", "\"", ",", "path", ".", "Join", "(", "g", ".", "relPath", "(", ")", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "g", ".", "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", "listVertexCollectionResponse", "\n", "if", "err", ":=", "resp", ".", "ParseBody", "(", "\"", "\"", ",", "&", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "Collection", ",", "0", ",", "len", "(", "data", ".", "Collections", ")", ")", "\n", "for", "_", ",", "name", ":=", "range", "data", ".", "Collections", "{", "ec", ",", "err", ":=", "newVertexCollection", "(", "name", ",", "g", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "ec", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// VertexCollections returns all edge collections of this graph
[ "VertexCollections", "returns", "all", "edge", "collections", "of", "this", "graph" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/graph_vertex_collections_impl.go#L90-L115
5,777
arangodb/go-driver
http/response_vpack.go
Endpoint
func (r *httpVPackResponse) Endpoint() string { u := *r.resp.Request.URL u.Path = "" return u.String() }
go
func (r *httpVPackResponse) Endpoint() string { u := *r.resp.Request.URL u.Path = "" return u.String() }
[ "func", "(", "r", "*", "httpVPackResponse", ")", "Endpoint", "(", ")", "string", "{", "u", ":=", "*", "r", ".", "resp", ".", "Request", ".", "URL", "\n", "u", ".", "Path", "=", "\"", "\"", "\n", "return", "u", ".", "String", "(", ")", "\n", "}" ]
// Endpoint returns the endpoint that handled the request.
[ "Endpoint", "returns", "the", "endpoint", "that", "handled", "the", "request", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/response_vpack.go#L47-L51
5,778
arangodb/go-driver
http/response_vpack.go
getSlice
func (r *httpVPackResponse) getSlice() (velocypack.Slice, error) { if r.slice == nil { r.slice = velocypack.Slice(r.rawResponse) //fmt.Println(r.slice) } return r.slice, nil }
go
func (r *httpVPackResponse) getSlice() (velocypack.Slice, error) { if r.slice == nil { r.slice = velocypack.Slice(r.rawResponse) //fmt.Println(r.slice) } return r.slice, nil }
[ "func", "(", "r", "*", "httpVPackResponse", ")", "getSlice", "(", ")", "(", "velocypack", ".", "Slice", ",", "error", ")", "{", "if", "r", ".", "slice", "==", "nil", "{", "r", ".", "slice", "=", "velocypack", ".", "Slice", "(", "r", ".", "rawResponse", ")", "\n", "//fmt.Println(r.slice)", "}", "\n", "return", "r", ".", "slice", ",", "nil", "\n", "}" ]
// getSlice reads the slice from the response if needed.
[ "getSlice", "reads", "the", "slice", "from", "the", "response", "if", "needed", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/http/response_vpack.go#L143-L149
5,779
arangodb/go-driver
client.go
String
func (v VersionInfo) String() string { result := fmt.Sprintf("%s, version %s, license %s", v.Server, v.Version, v.License) if len(v.Details) > 0 { lines := make([]string, 0, len(v.Details)) for k, v := range v.Details { lines = append(lines, fmt.Sprintf("%s: %v", k, v)) } sort.Strings(lines) result = result + "\n" + strings.Join(lines, "\n") } return result }
go
func (v VersionInfo) String() string { result := fmt.Sprintf("%s, version %s, license %s", v.Server, v.Version, v.License) if len(v.Details) > 0 { lines := make([]string, 0, len(v.Details)) for k, v := range v.Details { lines = append(lines, fmt.Sprintf("%s: %v", k, v)) } sort.Strings(lines) result = result + "\n" + strings.Join(lines, "\n") } return result }
[ "func", "(", "v", "VersionInfo", ")", "String", "(", ")", "string", "{", "result", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "Server", ",", "v", ".", "Version", ",", "v", ".", "License", ")", "\n", "if", "len", "(", "v", ".", "Details", ")", ">", "0", "{", "lines", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "v", ".", "Details", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "v", ".", "Details", "{", "lines", "=", "append", "(", "lines", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "lines", ")", "\n", "result", "=", "result", "+", "\"", "\\n", "\"", "+", "strings", ".", "Join", "(", "lines", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// String creates a string representation of the given VersionInfo.
[ "String", "creates", "a", "string", "representation", "of", "the", "given", "VersionInfo", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client.go#L108-L119
5,780
arangodb/go-driver
vst/protocol/chunk.go
buildChunks
func buildChunks(messageID uint64, maxChunkSize uint32, messageParts ...[]byte) ([]chunk, error) { if maxChunkSize <= maxChunkHeaderSize { return nil, fmt.Errorf("maxChunkSize is too small (%d)", maxChunkSize) } messageLength := uint64(0) for _, m := range messageParts { messageLength += uint64(len(m)) } minChunkCount := int(messageLength / uint64(maxChunkSize)) maxDataLength := int(maxChunkSize - maxChunkHeaderSize) chunks := make([]chunk, 0, minChunkCount+len(messageParts)) chunkIndex := uint32(0) for _, m := range messageParts { offset := 0 remaining := len(m) for remaining > 0 { dataLength := remaining if dataLength > maxDataLength { dataLength = maxDataLength } chunkX := chunkIndex << 1 c := chunk{ chunkX: chunkX, MessageID: messageID, MessageLength: messageLength, Data: m[offset : offset+dataLength], } chunks = append(chunks, c) remaining -= dataLength offset += dataLength chunkIndex++ } } // Set chunkX of first chunk if len(chunks) == 1 { chunks[0].chunkX = 3 } else { chunks[0].chunkX = uint32((len(chunks) << 1) + 1) } return chunks, nil }
go
func buildChunks(messageID uint64, maxChunkSize uint32, messageParts ...[]byte) ([]chunk, error) { if maxChunkSize <= maxChunkHeaderSize { return nil, fmt.Errorf("maxChunkSize is too small (%d)", maxChunkSize) } messageLength := uint64(0) for _, m := range messageParts { messageLength += uint64(len(m)) } minChunkCount := int(messageLength / uint64(maxChunkSize)) maxDataLength := int(maxChunkSize - maxChunkHeaderSize) chunks := make([]chunk, 0, minChunkCount+len(messageParts)) chunkIndex := uint32(0) for _, m := range messageParts { offset := 0 remaining := len(m) for remaining > 0 { dataLength := remaining if dataLength > maxDataLength { dataLength = maxDataLength } chunkX := chunkIndex << 1 c := chunk{ chunkX: chunkX, MessageID: messageID, MessageLength: messageLength, Data: m[offset : offset+dataLength], } chunks = append(chunks, c) remaining -= dataLength offset += dataLength chunkIndex++ } } // Set chunkX of first chunk if len(chunks) == 1 { chunks[0].chunkX = 3 } else { chunks[0].chunkX = uint32((len(chunks) << 1) + 1) } return chunks, nil }
[ "func", "buildChunks", "(", "messageID", "uint64", ",", "maxChunkSize", "uint32", ",", "messageParts", "...", "[", "]", "byte", ")", "(", "[", "]", "chunk", ",", "error", ")", "{", "if", "maxChunkSize", "<=", "maxChunkHeaderSize", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maxChunkSize", ")", "\n", "}", "\n", "messageLength", ":=", "uint64", "(", "0", ")", "\n", "for", "_", ",", "m", ":=", "range", "messageParts", "{", "messageLength", "+=", "uint64", "(", "len", "(", "m", ")", ")", "\n", "}", "\n", "minChunkCount", ":=", "int", "(", "messageLength", "/", "uint64", "(", "maxChunkSize", ")", ")", "\n", "maxDataLength", ":=", "int", "(", "maxChunkSize", "-", "maxChunkHeaderSize", ")", "\n", "chunks", ":=", "make", "(", "[", "]", "chunk", ",", "0", ",", "minChunkCount", "+", "len", "(", "messageParts", ")", ")", "\n", "chunkIndex", ":=", "uint32", "(", "0", ")", "\n", "for", "_", ",", "m", ":=", "range", "messageParts", "{", "offset", ":=", "0", "\n", "remaining", ":=", "len", "(", "m", ")", "\n", "for", "remaining", ">", "0", "{", "dataLength", ":=", "remaining", "\n", "if", "dataLength", ">", "maxDataLength", "{", "dataLength", "=", "maxDataLength", "\n", "}", "\n", "chunkX", ":=", "chunkIndex", "<<", "1", "\n", "c", ":=", "chunk", "{", "chunkX", ":", "chunkX", ",", "MessageID", ":", "messageID", ",", "MessageLength", ":", "messageLength", ",", "Data", ":", "m", "[", "offset", ":", "offset", "+", "dataLength", "]", ",", "}", "\n", "chunks", "=", "append", "(", "chunks", ",", "c", ")", "\n", "remaining", "-=", "dataLength", "\n", "offset", "+=", "dataLength", "\n", "chunkIndex", "++", "\n", "}", "\n", "}", "\n", "// Set chunkX of first chunk", "if", "len", "(", "chunks", ")", "==", "1", "{", "chunks", "[", "0", "]", ".", "chunkX", "=", "3", "\n", "}", "else", "{", "chunks", "[", "0", "]", ".", "chunkX", "=", "uint32", "(", "(", "len", "(", "chunks", ")", "<<", "1", ")", "+", "1", ")", "\n", "}", "\n", "return", "chunks", ",", "nil", "\n", "}" ]
// buildChunks splits a message consisting of 1 or more parts into chunks.
[ "buildChunks", "splits", "a", "message", "consisting", "of", "1", "or", "more", "parts", "into", "chunks", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vst/protocol/chunk.go#L44-L84
5,781
arangodb/go-driver
client_impl.go
NewClient
func NewClient(config ClientConfig) (Client, error) { if config.Connection == nil { return nil, WithStack(InvalidArgumentError{Message: "Connection is not set"}) } conn := config.Connection if config.Authentication != nil { var err error conn, err = conn.SetAuthentication(config.Authentication) if err != nil { return nil, WithStack(err) } } c := &client{ conn: conn, } if config.SynchronizeEndpointsInterval > 0 { go c.autoSynchronizeEndpoints(config.SynchronizeEndpointsInterval) } return c, nil }
go
func NewClient(config ClientConfig) (Client, error) { if config.Connection == nil { return nil, WithStack(InvalidArgumentError{Message: "Connection is not set"}) } conn := config.Connection if config.Authentication != nil { var err error conn, err = conn.SetAuthentication(config.Authentication) if err != nil { return nil, WithStack(err) } } c := &client{ conn: conn, } if config.SynchronizeEndpointsInterval > 0 { go c.autoSynchronizeEndpoints(config.SynchronizeEndpointsInterval) } return c, nil }
[ "func", "NewClient", "(", "config", "ClientConfig", ")", "(", "Client", ",", "error", ")", "{", "if", "config", ".", "Connection", "==", "nil", "{", "return", "nil", ",", "WithStack", "(", "InvalidArgumentError", "{", "Message", ":", "\"", "\"", "}", ")", "\n", "}", "\n", "conn", ":=", "config", ".", "Connection", "\n", "if", "config", ".", "Authentication", "!=", "nil", "{", "var", "err", "error", "\n", "conn", ",", "err", "=", "conn", ".", "SetAuthentication", "(", "config", ".", "Authentication", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "c", ":=", "&", "client", "{", "conn", ":", "conn", ",", "}", "\n", "if", "config", ".", "SynchronizeEndpointsInterval", ">", "0", "{", "go", "c", ".", "autoSynchronizeEndpoints", "(", "config", ".", "SynchronizeEndpointsInterval", ")", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewClient creates a new Client based on the given config setting.
[ "NewClient", "creates", "a", "new", "Client", "based", "on", "the", "given", "config", "setting", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_impl.go#L34-L53
5,782
arangodb/go-driver
client_impl.go
SynchronizeEndpoints
func (c *client) SynchronizeEndpoints(ctx context.Context) error { return c.SynchronizeEndpoints2(ctx, "") }
go
func (c *client) SynchronizeEndpoints(ctx context.Context) error { return c.SynchronizeEndpoints2(ctx, "") }
[ "func", "(", "c", "*", "client", ")", "SynchronizeEndpoints", "(", "ctx", "context", ".", "Context", ")", "error", "{", "return", "c", ".", "SynchronizeEndpoints2", "(", "ctx", ",", "\"", "\"", ")", "\n", "}" ]
// SynchronizeEndpoints fetches all endpoints from an ArangoDB cluster and updates the // connection to use those endpoints. // When this client is connected to a single server, nothing happens. // When this client is connected to a cluster of servers, the connection will be updated to reflect // the layout of the cluster.
[ "SynchronizeEndpoints", "fetches", "all", "endpoints", "from", "an", "ArangoDB", "cluster", "and", "updates", "the", "connection", "to", "use", "those", "endpoints", ".", "When", "this", "client", "is", "connected", "to", "a", "single", "server", "nothing", "happens", ".", "When", "this", "client", "is", "connected", "to", "a", "cluster", "of", "servers", "the", "connection", "will", "be", "updated", "to", "reflect", "the", "layout", "of", "the", "cluster", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_impl.go#L70-L72
5,783
arangodb/go-driver
client_impl.go
autoSynchronizeEndpoints
func (c *client) autoSynchronizeEndpoints(interval time.Duration) { for { // SynchronizeEndpoints endpoints c.SynchronizeEndpoints(nil) // Wait a bit time.Sleep(interval) } }
go
func (c *client) autoSynchronizeEndpoints(interval time.Duration) { for { // SynchronizeEndpoints endpoints c.SynchronizeEndpoints(nil) // Wait a bit time.Sleep(interval) } }
[ "func", "(", "c", "*", "client", ")", "autoSynchronizeEndpoints", "(", "interval", "time", ".", "Duration", ")", "{", "for", "{", "// SynchronizeEndpoints endpoints", "c", ".", "SynchronizeEndpoints", "(", "nil", ")", "\n\n", "// Wait a bit", "time", ".", "Sleep", "(", "interval", ")", "\n", "}", "\n", "}" ]
// autoSynchronizeEndpoints performs automatic endpoint synchronization.
[ "autoSynchronizeEndpoints", "performs", "automatic", "endpoint", "synchronization", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/client_impl.go#L108-L116
5,784
arangodb/go-driver
agency/agency.go
add
func (c WriteCondition) add(key []string, updater func(wc *writeCondition)) WriteCondition { if c.conditions == nil { c.conditions = make(map[string]writeCondition) } fullKey := createFullKey(key) wc := c.conditions[fullKey] updater(&wc) c.conditions[fullKey] = wc return c }
go
func (c WriteCondition) add(key []string, updater func(wc *writeCondition)) WriteCondition { if c.conditions == nil { c.conditions = make(map[string]writeCondition) } fullKey := createFullKey(key) wc := c.conditions[fullKey] updater(&wc) c.conditions[fullKey] = wc return c }
[ "func", "(", "c", "WriteCondition", ")", "add", "(", "key", "[", "]", "string", ",", "updater", "func", "(", "wc", "*", "writeCondition", ")", ")", "WriteCondition", "{", "if", "c", ".", "conditions", "==", "nil", "{", "c", ".", "conditions", "=", "make", "(", "map", "[", "string", "]", "writeCondition", ")", "\n", "}", "\n", "fullKey", ":=", "createFullKey", "(", "key", ")", "\n", "wc", ":=", "c", ".", "conditions", "[", "fullKey", "]", "\n", "updater", "(", "&", "wc", ")", "\n", "c", ".", "conditions", "[", "fullKey", "]", "=", "wc", "\n", "return", "c", "\n", "}" ]
// IfEmpty adds an empty check on the given key to the given condition // and returns the updated condition.
[ "IfEmpty", "adds", "an", "empty", "check", "on", "the", "given", "key", "to", "the", "given", "condition", "and", "returns", "the", "updated", "condition", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency.go#L74-L83
5,785
arangodb/go-driver
agency/agency.go
toMap
func (c WriteCondition) toMap() map[string]interface{} { result := make(map[string]interface{}) for k, v := range c.conditions { result[k] = v } return result }
go
func (c WriteCondition) toMap() map[string]interface{} { result := make(map[string]interface{}) for k, v := range c.conditions { result[k] = v } return result }
[ "func", "(", "c", "WriteCondition", ")", "toMap", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "result", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "c", ".", "conditions", "{", "result", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "result", "\n", "}" ]
// toMap convert the given condition to a map suitable for writeTransaction.
[ "toMap", "convert", "the", "given", "condition", "to", "a", "map", "suitable", "for", "writeTransaction", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency.go#L86-L92
5,786
arangodb/go-driver
agency/agency.go
IfEmpty
func (c WriteCondition) IfEmpty(key []string) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.OldEmpty = &condTrue }) }
go
func (c WriteCondition) IfEmpty(key []string) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.OldEmpty = &condTrue }) }
[ "func", "(", "c", "WriteCondition", ")", "IfEmpty", "(", "key", "[", "]", "string", ")", "WriteCondition", "{", "return", "c", ".", "add", "(", "key", ",", "func", "(", "wc", "*", "writeCondition", ")", "{", "wc", ".", "OldEmpty", "=", "&", "condTrue", "\n", "}", ")", "\n", "}" ]
// IfEmpty adds an "is empty" check on the given key to the given condition // and returns the updated condition.
[ "IfEmpty", "adds", "an", "is", "empty", "check", "on", "the", "given", "key", "to", "the", "given", "condition", "and", "returns", "the", "updated", "condition", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency.go#L96-L100
5,787
arangodb/go-driver
agency/agency.go
IfIsArray
func (c WriteCondition) IfIsArray(key []string) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.IsArray = &condTrue }) }
go
func (c WriteCondition) IfIsArray(key []string) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.IsArray = &condTrue }) }
[ "func", "(", "c", "WriteCondition", ")", "IfIsArray", "(", "key", "[", "]", "string", ")", "WriteCondition", "{", "return", "c", ".", "add", "(", "key", ",", "func", "(", "wc", "*", "writeCondition", ")", "{", "wc", ".", "IsArray", "=", "&", "condTrue", "\n", "}", ")", "\n", "}" ]
// IfIsArray adds an "is-array" check on the given key to the given condition // and returns the updated condition.
[ "IfIsArray", "adds", "an", "is", "-", "array", "check", "on", "the", "given", "key", "to", "the", "given", "condition", "and", "returns", "the", "updated", "condition", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency.go#L104-L108
5,788
arangodb/go-driver
agency/agency.go
IfEqualTo
func (c WriteCondition) IfEqualTo(key []string, oldValue interface{}) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.Old = oldValue }) }
go
func (c WriteCondition) IfEqualTo(key []string, oldValue interface{}) WriteCondition { return c.add(key, func(wc *writeCondition) { wc.Old = oldValue }) }
[ "func", "(", "c", "WriteCondition", ")", "IfEqualTo", "(", "key", "[", "]", "string", ",", "oldValue", "interface", "{", "}", ")", "WriteCondition", "{", "return", "c", ".", "add", "(", "key", ",", "func", "(", "wc", "*", "writeCondition", ")", "{", "wc", ".", "Old", "=", "oldValue", "\n", "}", ")", "\n", "}" ]
// IfEqualTo adds an "value equals oldValue" check to given old value on the // given key to the given condition and returns the updated condition.
[ "IfEqualTo", "adds", "an", "value", "equals", "oldValue", "check", "to", "given", "old", "value", "on", "the", "given", "key", "to", "the", "given", "condition", "and", "returns", "the", "updated", "condition", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/agency/agency.go#L112-L116
5,789
arangodb/go-driver
vertex_collection_impl.go
newVertexCollection
func newVertexCollection(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 &vertexCollection{ name: name, g: g, conn: g.db.conn, }, nil }
go
func newVertexCollection(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 &vertexCollection{ name: name, g: g, conn: g.db.conn, }, nil }
[ "func", "newVertexCollection", "(", "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", "&", "vertexCollection", "{", "name", ":", "name", ",", "g", ":", "g", ",", "conn", ":", "g", ".", "db", ".", "conn", ",", "}", ",", "nil", "\n", "}" ]
// newVertexCollection creates a new Vertex Collection implementation.
[ "newVertexCollection", "creates", "a", "new", "Vertex", "Collection", "implementation", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vertex_collection_impl.go#L31-L43
5,790
arangodb/go-driver
vertex_collection_impl.go
Revision
func (c *vertexCollection) Revision(ctx context.Context) (string, error) { result, err := c.rawCollection().Revision(ctx) if err != nil { return "", WithStack(err) } return result, nil }
go
func (c *vertexCollection) Revision(ctx context.Context) (string, error) { result, err := c.rawCollection().Revision(ctx) if err != nil { return "", WithStack(err) } return result, nil }
[ "func", "(", "c", "*", "vertexCollection", ")", "Revision", "(", "ctx", "context", ".", "Context", ")", "(", "string", ",", "error", ")", "{", "result", ",", "err", ":=", "c", ".", "rawCollection", "(", ")", ".", "Revision", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Revision fetches the revision ID of the collection. // The revision ID is a server-generated string that clients can use to check whether data // in a collection has changed since the last revision check.
[ "Revision", "fetches", "the", "revision", "ID", "of", "the", "collection", ".", "The", "revision", "ID", "is", "a", "server", "-", "generated", "string", "that", "clients", "can", "use", "to", "check", "whether", "data", "in", "a", "collection", "has", "changed", "since", "the", "last", "revision", "check", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/vertex_collection_impl.go#L104-L110
5,791
arangodb/go-driver
authentication.go
BasicAuthentication
func BasicAuthentication(userName, password string) Authentication { return &userNameAuthentication{ authType: AuthenticationTypeBasic, userName: userName, password: password, } }
go
func BasicAuthentication(userName, password string) Authentication { return &userNameAuthentication{ authType: AuthenticationTypeBasic, userName: userName, password: password, } }
[ "func", "BasicAuthentication", "(", "userName", ",", "password", "string", ")", "Authentication", "{", "return", "&", "userNameAuthentication", "{", "authType", ":", "AuthenticationTypeBasic", ",", "userName", ":", "userName", ",", "password", ":", "password", ",", "}", "\n", "}" ]
// BasicAuthentication creates an authentication implementation based on the given username & password.
[ "BasicAuthentication", "creates", "an", "authentication", "implementation", "based", "on", "the", "given", "username", "&", "password", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/authentication.go#L46-L52
5,792
arangodb/go-driver
authentication.go
JWTAuthentication
func JWTAuthentication(userName, password string) Authentication { return &userNameAuthentication{ authType: AuthenticationTypeJWT, userName: userName, password: password, } }
go
func JWTAuthentication(userName, password string) Authentication { return &userNameAuthentication{ authType: AuthenticationTypeJWT, userName: userName, password: password, } }
[ "func", "JWTAuthentication", "(", "userName", ",", "password", "string", ")", "Authentication", "{", "return", "&", "userNameAuthentication", "{", "authType", ":", "AuthenticationTypeJWT", ",", "userName", ":", "userName", ",", "password", ":", "password", ",", "}", "\n", "}" ]
// JWTAuthentication creates a JWT token authentication implementation based on the given username & password.
[ "JWTAuthentication", "creates", "a", "JWT", "token", "authentication", "implementation", "based", "on", "the", "given", "username", "&", "password", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/authentication.go#L55-L61
5,793
arangodb/go-driver
authentication.go
Get
func (a *userNameAuthentication) Get(property string) string { switch property { case "username": return a.userName case "password": return a.password default: return "" } }
go
func (a *userNameAuthentication) Get(property string) string { switch property { case "username": return a.userName case "password": return a.password default: return "" } }
[ "func", "(", "a", "*", "userNameAuthentication", ")", "Get", "(", "property", "string", ")", "string", "{", "switch", "property", "{", "case", "\"", "\"", ":", "return", "a", ".", "userName", "\n", "case", "\"", "\"", ":", "return", "a", ".", "password", "\n", "default", ":", "return", "\"", "\"", "\n", "}", "\n", "}" ]
// Get returns a configuration property of the authentication. // Supported properties depend on type of authentication.
[ "Get", "returns", "a", "configuration", "property", "of", "the", "authentication", ".", "Supported", "properties", "depend", "on", "type", "of", "authentication", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/authentication.go#L77-L86
5,794
arangodb/go-driver
version.go
Major
func (v Version) Major() int { parts := strings.Split(string(v), ".") result, _ := strconv.Atoi(parts[0]) return result }
go
func (v Version) Major() int { parts := strings.Split(string(v), ".") result, _ := strconv.Atoi(parts[0]) return result }
[ "func", "(", "v", "Version", ")", "Major", "(", ")", "int", "{", "parts", ":=", "strings", ".", "Split", "(", "string", "(", "v", ")", ",", "\"", "\"", ")", "\n", "result", ",", "_", ":=", "strconv", ".", "Atoi", "(", "parts", "[", "0", "]", ")", "\n", "return", "result", "\n", "}" ]
// Major returns the major part of the version // E.g. "3.1.7" -> 3
[ "Major", "returns", "the", "major", "part", "of", "the", "version", "E", ".", "g", ".", "3", ".", "1", ".", "7", "-", ">", "3" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/version.go#L36-L40
5,795
arangodb/go-driver
version.go
Minor
func (v Version) Minor() int { parts := strings.Split(string(v), ".") if len(parts) >= 2 { result, _ := strconv.Atoi(parts[1]) return result } return 0 }
go
func (v Version) Minor() int { parts := strings.Split(string(v), ".") if len(parts) >= 2 { result, _ := strconv.Atoi(parts[1]) return result } return 0 }
[ "func", "(", "v", "Version", ")", "Minor", "(", ")", "int", "{", "parts", ":=", "strings", ".", "Split", "(", "string", "(", "v", ")", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">=", "2", "{", "result", ",", "_", ":=", "strconv", ".", "Atoi", "(", "parts", "[", "1", "]", ")", "\n", "return", "result", "\n", "}", "\n", "return", "0", "\n", "}" ]
// Minor returns the minor part of the version. // E.g. "3.1.7" -> 1
[ "Minor", "returns", "the", "minor", "part", "of", "the", "version", ".", "E", ".", "g", ".", "3", ".", "1", ".", "7", "-", ">", "1" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/version.go#L44-L51
5,796
arangodb/go-driver
version.go
Sub
func (v Version) Sub() string { parts := strings.SplitN(string(v), ".", 3) if len(parts) == 3 { return parts[2] } return "" }
go
func (v Version) Sub() string { parts := strings.SplitN(string(v), ".", 3) if len(parts) == 3 { return parts[2] } return "" }
[ "func", "(", "v", "Version", ")", "Sub", "(", ")", "string", "{", "parts", ":=", "strings", ".", "SplitN", "(", "string", "(", "v", ")", ",", "\"", "\"", ",", "3", ")", "\n", "if", "len", "(", "parts", ")", "==", "3", "{", "return", "parts", "[", "2", "]", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// Sub returns the sub part of the version. // E.g. "3.1.7" -> "7"
[ "Sub", "returns", "the", "sub", "part", "of", "the", "version", ".", "E", ".", "g", ".", "3", ".", "1", ".", "7", "-", ">", "7" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/version.go#L55-L61
5,797
arangodb/go-driver
version.go
SubInt
func (v Version) SubInt() (int, bool) { result, err := strconv.Atoi(v.Sub()) return result, err == nil }
go
func (v Version) SubInt() (int, bool) { result, err := strconv.Atoi(v.Sub()) return result, err == nil }
[ "func", "(", "v", "Version", ")", "SubInt", "(", ")", "(", "int", ",", "bool", ")", "{", "result", ",", "err", ":=", "strconv", ".", "Atoi", "(", "v", ".", "Sub", "(", ")", ")", "\n", "return", "result", ",", "err", "==", "nil", "\n", "}" ]
// SubInt returns the sub part of the version as integer. // The bool return value indicates if the sub part is indeed a number. // E.g. "3.1.7" -> 7, true // E.g. "3.1.foo" -> 0, false
[ "SubInt", "returns", "the", "sub", "part", "of", "the", "version", "as", "integer", ".", "The", "bool", "return", "value", "indicates", "if", "the", "sub", "part", "is", "indeed", "a", "number", ".", "E", ".", "g", ".", "3", ".", "1", ".", "7", "-", ">", "7", "true", "E", ".", "g", ".", "3", ".", "1", ".", "foo", "-", ">", "0", "false" ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/version.go#L67-L70
5,798
arangodb/go-driver
meta.go
Keys
func (l DocumentMetaSlice) Keys() []string { keys := make([]string, len(l)) for i, m := range l { keys[i] = m.Key } return keys }
go
func (l DocumentMetaSlice) Keys() []string { keys := make([]string, len(l)) for i, m := range l { keys[i] = m.Key } return keys }
[ "func", "(", "l", "DocumentMetaSlice", ")", "Keys", "(", ")", "[", "]", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "l", ")", ")", "\n", "for", "i", ",", "m", ":=", "range", "l", "{", "keys", "[", "i", "]", "=", "m", ".", "Key", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// Keys returns the keys of all elements.
[ "Keys", "returns", "the", "keys", "of", "all", "elements", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/meta.go#L44-L50
5,799
arangodb/go-driver
meta.go
Revs
func (l DocumentMetaSlice) Revs() []string { revs := make([]string, len(l)) for i, m := range l { revs[i] = m.Rev } return revs }
go
func (l DocumentMetaSlice) Revs() []string { revs := make([]string, len(l)) for i, m := range l { revs[i] = m.Rev } return revs }
[ "func", "(", "l", "DocumentMetaSlice", ")", "Revs", "(", ")", "[", "]", "string", "{", "revs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "l", ")", ")", "\n", "for", "i", ",", "m", ":=", "range", "l", "{", "revs", "[", "i", "]", "=", "m", ".", "Rev", "\n", "}", "\n", "return", "revs", "\n", "}" ]
// Revs returns the revisions of all elements.
[ "Revs", "returns", "the", "revisions", "of", "all", "elements", "." ]
b14f41496c3dc1253a16c06bbc405605934b214a
https://github.com/arangodb/go-driver/blob/b14f41496c3dc1253a16c06bbc405605934b214a/meta.go#L53-L59