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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
justinas/nosurf
handler.go
extractToken
func extractToken(r *http.Request) []byte { // Prefer the header over form value sentToken := r.Header.Get(HeaderName) // Then POST values if len(sentToken) == 0 { sentToken = r.PostFormValue(FormFieldName) } // If all else fails, try a multipart value. // PostFormValue() will already have called ParseMultipartForm() if len(sentToken) == 0 && r.MultipartForm != nil { vals := r.MultipartForm.Value[FormFieldName] if len(vals) != 0 { sentToken = vals[0] } } return b64decode(sentToken) }
go
func extractToken(r *http.Request) []byte { // Prefer the header over form value sentToken := r.Header.Get(HeaderName) // Then POST values if len(sentToken) == 0 { sentToken = r.PostFormValue(FormFieldName) } // If all else fails, try a multipart value. // PostFormValue() will already have called ParseMultipartForm() if len(sentToken) == 0 && r.MultipartForm != nil { vals := r.MultipartForm.Value[FormFieldName] if len(vals) != 0 { sentToken = vals[0] } } return b64decode(sentToken) }
[ "func", "extractToken", "(", "r", "*", "http", ".", "Request", ")", "[", "]", "byte", "{", "// Prefer the header over form value", "sentToken", ":=", "r", ".", "Header", ".", "Get", "(", "HeaderName", ")", "\n\n", "// Then POST values", "if", "len", "(", "se...
// Extracts the "sent" token from the request // and returns an unmasked version of it
[ "Extracts", "the", "sent", "token", "from", "the", "request", "and", "returns", "an", "unmasked", "version", "of", "it" ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L68-L87
train
justinas/nosurf
handler.go
New
func New(handler http.Handler) *CSRFHandler { baseCookie := http.Cookie{} baseCookie.MaxAge = MaxAge csrf := &CSRFHandler{successHandler: handler, failureHandler: http.HandlerFunc(defaultFailureHandler), baseCookie: baseCookie, } return csrf }
go
func New(handler http.Handler) *CSRFHandler { baseCookie := http.Cookie{} baseCookie.MaxAge = MaxAge csrf := &CSRFHandler{successHandler: handler, failureHandler: http.HandlerFunc(defaultFailureHandler), baseCookie: baseCookie, } return csrf }
[ "func", "New", "(", "handler", "http", ".", "Handler", ")", "*", "CSRFHandler", "{", "baseCookie", ":=", "http", ".", "Cookie", "{", "}", "\n", "baseCookie", ".", "MaxAge", "=", "MaxAge", "\n\n", "csrf", ":=", "&", "CSRFHandler", "{", "successHandler", "...
// Constructs a new CSRFHandler that calls // the specified handler if the CSRF check succeeds.
[ "Constructs", "a", "new", "CSRFHandler", "that", "calls", "the", "specified", "handler", "if", "the", "CSRF", "check", "succeeds", "." ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L91-L101
train
justinas/nosurf
handler.go
RegenerateToken
func (h *CSRFHandler) RegenerateToken(w http.ResponseWriter, r *http.Request) string { token := generateToken() h.setTokenCookie(w, r, token) return Token(r) }
go
func (h *CSRFHandler) RegenerateToken(w http.ResponseWriter, r *http.Request) string { token := generateToken() h.setTokenCookie(w, r, token) return Token(r) }
[ "func", "(", "h", "*", "CSRFHandler", ")", "RegenerateToken", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "string", "{", "token", ":=", "generateToken", "(", ")", "\n", "h", ".", "setTokenCookie", "(", "w", ",",...
// Generates a new token, sets it on the given request and returns it
[ "Generates", "a", "new", "token", "sets", "it", "on", "the", "given", "request", "and", "returns", "it" ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L197-L202
train
justinas/nosurf
context_legacy.go
ctxSetToken
func ctxSetToken(req *http.Request, token []byte) *http.Request { cmMutex.Lock() defer cmMutex.Unlock() ctx, ok := contextMap[req] if !ok { ctx = new(csrfContext) contextMap[req] = ctx } ctx.token = b64encode(maskToken(token)) return req }
go
func ctxSetToken(req *http.Request, token []byte) *http.Request { cmMutex.Lock() defer cmMutex.Unlock() ctx, ok := contextMap[req] if !ok { ctx = new(csrfContext) contextMap[req] = ctx } ctx.token = b64encode(maskToken(token)) return req }
[ "func", "ctxSetToken", "(", "req", "*", "http", ".", "Request", ",", "token", "[", "]", "byte", ")", "*", "http", ".", "Request", "{", "cmMutex", ".", "Lock", "(", ")", "\n", "defer", "cmMutex", ".", "Unlock", "(", ")", "\n\n", "ctx", ",", "ok", ...
// Takes a raw token, masks it with a per-request key, // encodes in base64 and makes it available to the wrapped handler
[ "Takes", "a", "raw", "token", "masks", "it", "with", "a", "per", "-", "request", "key", "encodes", "in", "base64", "and", "makes", "it", "available", "to", "the", "wrapped", "handler" ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/context_legacy.go#L67-L80
train
justinas/nosurf
token.go
verifyMasked
func verifyMasked(realToken, sentToken []byte) bool { sentPlain := unmaskToken(sentToken) return subtle.ConstantTimeCompare(realToken, sentPlain) == 1 }
go
func verifyMasked(realToken, sentToken []byte) bool { sentPlain := unmaskToken(sentToken) return subtle.ConstantTimeCompare(realToken, sentPlain) == 1 }
[ "func", "verifyMasked", "(", "realToken", ",", "sentToken", "[", "]", "byte", ")", "bool", "{", "sentPlain", ":=", "unmaskToken", "(", "sentToken", ")", "\n", "return", "subtle", ".", "ConstantTimeCompare", "(", "realToken", ",", "sentPlain", ")", "==", "1",...
// Verifies the masked token
[ "Verifies", "the", "masked", "token" ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/token.go#L86-L89
train
justinas/nosurf
exempt.go
IsExempt
func (h *CSRFHandler) IsExempt(r *http.Request) bool { if h.exemptFunc != nil && h.exemptFunc(r) { return true } path := r.URL.Path if sContains(h.exemptPaths, path) { return true } // then the globs for _, glob := range h.exemptGlobs { matched, err := pathModule.Match(glob, path) if matched && err == nil { return true } } // finally, the regexps for _, re := range h.exemptRegexps { if re.MatchString(path) { return true } } return false }
go
func (h *CSRFHandler) IsExempt(r *http.Request) bool { if h.exemptFunc != nil && h.exemptFunc(r) { return true } path := r.URL.Path if sContains(h.exemptPaths, path) { return true } // then the globs for _, glob := range h.exemptGlobs { matched, err := pathModule.Match(glob, path) if matched && err == nil { return true } } // finally, the regexps for _, re := range h.exemptRegexps { if re.MatchString(path) { return true } } return false }
[ "func", "(", "h", "*", "CSRFHandler", ")", "IsExempt", "(", "r", "*", "http", ".", "Request", ")", "bool", "{", "if", "h", ".", "exemptFunc", "!=", "nil", "&&", "h", ".", "exemptFunc", "(", "r", ")", "{", "return", "true", "\n", "}", "\n\n", "pat...
// Checks if the given request is exempt from CSRF checks. // It checks the ExemptFunc first, then the exact paths, // then the globs and finally the regexps.
[ "Checks", "if", "the", "given", "request", "is", "exempt", "from", "CSRF", "checks", ".", "It", "checks", "the", "ExemptFunc", "first", "then", "the", "exact", "paths", "then", "the", "globs", "and", "finally", "the", "regexps", "." ]
05988550ea1890c49b702363e53b3afa7aad2b4b
https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/exempt.go#L14-L40
train
prometheus/haproxy_exporter
haproxy_exporter.go
NewExporter
func NewExporter(uri string, sslVerify bool, selectedServerMetrics map[int]*prometheus.Desc, timeout time.Duration) (*Exporter, error) { u, err := url.Parse(uri) if err != nil { return nil, err } var fetch func() (io.ReadCloser, error) switch u.Scheme { case "http", "https", "file": fetch = fetchHTTP(uri, sslVerify, timeout) case "unix": fetch = fetchUnix(u, timeout) default: return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme) } return &Exporter{ URI: uri, fetch: fetch, up: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Name: "up", Help: "Was the last scrape of haproxy successful.", }), totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_total_scrapes", Help: "Current total HAProxy scrapes.", }), csvParseFailures: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_csv_parse_failures", Help: "Number of errors while parsing CSV.", }), serverMetrics: selectedServerMetrics, }, nil }
go
func NewExporter(uri string, sslVerify bool, selectedServerMetrics map[int]*prometheus.Desc, timeout time.Duration) (*Exporter, error) { u, err := url.Parse(uri) if err != nil { return nil, err } var fetch func() (io.ReadCloser, error) switch u.Scheme { case "http", "https", "file": fetch = fetchHTTP(uri, sslVerify, timeout) case "unix": fetch = fetchUnix(u, timeout) default: return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme) } return &Exporter{ URI: uri, fetch: fetch, up: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Name: "up", Help: "Was the last scrape of haproxy successful.", }), totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_total_scrapes", Help: "Current total HAProxy scrapes.", }), csvParseFailures: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_csv_parse_failures", Help: "Number of errors while parsing CSV.", }), serverMetrics: selectedServerMetrics, }, nil }
[ "func", "NewExporter", "(", "uri", "string", ",", "sslVerify", "bool", ",", "selectedServerMetrics", "map", "[", "int", "]", "*", "prometheus", ".", "Desc", ",", "timeout", "time", ".", "Duration", ")", "(", "*", "Exporter", ",", "error", ")", "{", "u", ...
// NewExporter returns an initialized Exporter.
[ "NewExporter", "returns", "an", "initialized", "Exporter", "." ]
f9813cf8bc6d469e80f7e6007a66c095b45616ed
https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L188-L224
train
prometheus/haproxy_exporter
haproxy_exporter.go
Describe
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { for _, m := range frontendMetrics { ch <- m } for _, m := range backendMetrics { ch <- m } for _, m := range e.serverMetrics { ch <- m } ch <- haproxyUp ch <- e.totalScrapes.Desc() ch <- e.csvParseFailures.Desc() }
go
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { for _, m := range frontendMetrics { ch <- m } for _, m := range backendMetrics { ch <- m } for _, m := range e.serverMetrics { ch <- m } ch <- haproxyUp ch <- e.totalScrapes.Desc() ch <- e.csvParseFailures.Desc() }
[ "func", "(", "e", "*", "Exporter", ")", "Describe", "(", "ch", "chan", "<-", "*", "prometheus", ".", "Desc", ")", "{", "for", "_", ",", "m", ":=", "range", "frontendMetrics", "{", "ch", "<-", "m", "\n", "}", "\n", "for", "_", ",", "m", ":=", "r...
// Describe describes all the metrics ever exported by the HAProxy exporter. It // implements prometheus.Collector.
[ "Describe", "describes", "all", "the", "metrics", "ever", "exported", "by", "the", "HAProxy", "exporter", ".", "It", "implements", "prometheus", ".", "Collector", "." ]
f9813cf8bc6d469e80f7e6007a66c095b45616ed
https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L228-L241
train
prometheus/haproxy_exporter
haproxy_exporter.go
Collect
func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.mutex.Lock() // To protect metrics from concurrent collects. defer e.mutex.Unlock() up := e.scrape(ch) ch <- prometheus.MustNewConstMetric(haproxyUp, prometheus.GaugeValue, up) ch <- e.totalScrapes ch <- e.csvParseFailures }
go
func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.mutex.Lock() // To protect metrics from concurrent collects. defer e.mutex.Unlock() up := e.scrape(ch) ch <- prometheus.MustNewConstMetric(haproxyUp, prometheus.GaugeValue, up) ch <- e.totalScrapes ch <- e.csvParseFailures }
[ "func", "(", "e", "*", "Exporter", ")", "Collect", "(", "ch", "chan", "<-", "prometheus", ".", "Metric", ")", "{", "e", ".", "mutex", ".", "Lock", "(", ")", "// To protect metrics from concurrent collects.", "\n", "defer", "e", ".", "mutex", ".", "Unlock",...
// Collect fetches the stats from configured HAProxy location and delivers them // as Prometheus metrics. It implements prometheus.Collector.
[ "Collect", "fetches", "the", "stats", "from", "configured", "HAProxy", "location", "and", "delivers", "them", "as", "Prometheus", "metrics", ".", "It", "implements", "prometheus", ".", "Collector", "." ]
f9813cf8bc6d469e80f7e6007a66c095b45616ed
https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L245-L254
train
prometheus/haproxy_exporter
haproxy_exporter.go
filterServerMetrics
func filterServerMetrics(filter string) (map[int]*prometheus.Desc, error) { metrics := map[int]*prometheus.Desc{} if len(filter) == 0 { return metrics, nil } selected := map[int]struct{}{} for _, f := range strings.Split(filter, ",") { field, err := strconv.Atoi(f) if err != nil { return nil, fmt.Errorf("invalid server metric field number: %v", f) } selected[field] = struct{}{} } for field, metric := range serverMetrics { if _, ok := selected[field]; ok { metrics[field] = metric } } return metrics, nil }
go
func filterServerMetrics(filter string) (map[int]*prometheus.Desc, error) { metrics := map[int]*prometheus.Desc{} if len(filter) == 0 { return metrics, nil } selected := map[int]struct{}{} for _, f := range strings.Split(filter, ",") { field, err := strconv.Atoi(f) if err != nil { return nil, fmt.Errorf("invalid server metric field number: %v", f) } selected[field] = struct{}{} } for field, metric := range serverMetrics { if _, ok := selected[field]; ok { metrics[field] = metric } } return metrics, nil }
[ "func", "filterServerMetrics", "(", "filter", "string", ")", "(", "map", "[", "int", "]", "*", "prometheus", ".", "Desc", ",", "error", ")", "{", "metrics", ":=", "map", "[", "int", "]", "*", "prometheus", ".", "Desc", "{", "}", "\n", "if", "len", ...
// filterServerMetrics returns the set of server metrics specified by the comma // separated filter.
[ "filterServerMetrics", "returns", "the", "set", "of", "server", "metrics", "specified", "by", "the", "comma", "separated", "filter", "." ]
f9813cf8bc6d469e80f7e6007a66c095b45616ed
https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L407-L428
train
go-chat-bot/bot
rocket/rocket.go
Run
func Run(c *Config) { config = c client = rest.NewClient(config.Server, config.Port, config.UseTLS, config.Debug) err := client.Login(api.UserCredentials{Email: config.Email, Name: config.User, Password: config.Password}) if err != nil { log.Fatalf("login err: %s\n", err) } b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: config.Server, }, ) b.Disable([]string{"url"}) msgChan := client.GetAllMessages() for { select { case msgs := <-msgChan: for _, msg := range msgs { if !ownMessage(c, msg) { b.MessageReceived( &bot.ChannelData{ Protocol: protocol, Server: "", Channel: msg.ChannelId, IsPrivate: false, }, &bot.Message{Text: msg.Text}, &bot.User{ID: msg.User.Id, RealName: msg.User.UserName, Nick: msg.User.UserName, IsBot: false}) } } } } }
go
func Run(c *Config) { config = c client = rest.NewClient(config.Server, config.Port, config.UseTLS, config.Debug) err := client.Login(api.UserCredentials{Email: config.Email, Name: config.User, Password: config.Password}) if err != nil { log.Fatalf("login err: %s\n", err) } b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: config.Server, }, ) b.Disable([]string{"url"}) msgChan := client.GetAllMessages() for { select { case msgs := <-msgChan: for _, msg := range msgs { if !ownMessage(c, msg) { b.MessageReceived( &bot.ChannelData{ Protocol: protocol, Server: "", Channel: msg.ChannelId, IsPrivate: false, }, &bot.Message{Text: msg.Text}, &bot.User{ID: msg.User.Id, RealName: msg.User.UserName, Nick: msg.User.UserName, IsBot: false}) } } } } }
[ "func", "Run", "(", "c", "*", "Config", ")", "{", "config", "=", "c", "\n", "client", "=", "rest", ".", "NewClient", "(", "config", ".", "Server", ",", "config", ".", "Port", ",", "config", ".", "UseTLS", ",", "config", ".", "Debug", ")", "\n", "...
// Run reads the Config, connect to the specified rocket.chat server and starts the bot.
[ "Run", "reads", "the", "Config", "connect", "to", "the", "specified", "rocket", ".", "chat", "server", "and", "starts", "the", "bot", "." ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/rocket/rocket.go#L52-L91
train
go-chat-bot/bot
cmd.go
URI
func (c *ChannelData) URI() string { return fmt.Sprintf("%s://%s/%s", c.Protocol, c.Server, c.Channel) }
go
func (c *ChannelData) URI() string { return fmt.Sprintf("%s://%s/%s", c.Protocol, c.Server, c.Channel) }
[ "func", "(", "c", "*", "ChannelData", ")", "URI", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "Protocol", ",", "c", ".", "Server", ",", "c", ".", "Channel", ")", "\n", "}" ]
// URI gives back an URI-fied string containing protocol, server and channel.
[ "URI", "gives", "back", "an", "URI", "-", "fied", "string", "containing", "protocol", "server", "and", "channel", "." ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L38-L40
train
go-chat-bot/bot
cmd.go
RegisterCommandV2
func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2) { commands[command] = &customCommand{ Version: v2, Cmd: command, CmdFuncV2: cmdFunc, Description: description, ExampleArgs: exampleArgs, } }
go
func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2) { commands[command] = &customCommand{ Version: v2, Cmd: command, CmdFuncV2: cmdFunc, Description: description, ExampleArgs: exampleArgs, } }
[ "func", "RegisterCommandV2", "(", "command", ",", "description", ",", "exampleArgs", "string", ",", "cmdFunc", "activeCmdFuncV2", ")", "{", "commands", "[", "command", "]", "=", "&", "customCommand", "{", "Version", ":", "v2", ",", "Cmd", ":", "command", ","...
// RegisterCommandV2 adds a new command to the bot. // It is the same as RegisterCommand but the command can specify the channel to reply to
[ "RegisterCommandV2", "adds", "a", "new", "command", "to", "the", "bot", ".", "It", "is", "the", "same", "as", "RegisterCommand", "but", "the", "command", "can", "specify", "the", "channel", "to", "reply", "to" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L196-L204
train
go-chat-bot/bot
cmd.go
RegisterCommandV3
func RegisterCommandV3(command, description, exampleArgs string, cmdFunc activeCmdFuncV3) { commands[command] = &customCommand{ Version: v3, Cmd: command, CmdFuncV3: cmdFunc, Description: description, ExampleArgs: exampleArgs, } }
go
func RegisterCommandV3(command, description, exampleArgs string, cmdFunc activeCmdFuncV3) { commands[command] = &customCommand{ Version: v3, Cmd: command, CmdFuncV3: cmdFunc, Description: description, ExampleArgs: exampleArgs, } }
[ "func", "RegisterCommandV3", "(", "command", ",", "description", ",", "exampleArgs", "string", ",", "cmdFunc", "activeCmdFuncV3", ")", "{", "commands", "[", "command", "]", "=", "&", "customCommand", "{", "Version", ":", "v3", ",", "Cmd", ":", "command", ","...
// RegisterCommandV3 adds a new command to the bot. // It is the same as RegisterCommand but the command return a chan
[ "RegisterCommandV3", "adds", "a", "new", "command", "to", "the", "bot", ".", "It", "is", "the", "same", "as", "RegisterCommand", "but", "the", "command", "return", "a", "chan" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L208-L216
train
go-chat-bot/bot
cmd.go
Disable
func (b *Bot) Disable(cmds []string) { b.disabledCmds = append(b.disabledCmds, cmds...) }
go
func (b *Bot) Disable(cmds []string) { b.disabledCmds = append(b.disabledCmds, cmds...) }
[ "func", "(", "b", "*", "Bot", ")", "Disable", "(", "cmds", "[", "]", "string", ")", "{", "b", ".", "disabledCmds", "=", "append", "(", "b", ".", "disabledCmds", ",", "cmds", "...", ")", "\n", "}" ]
// Disable allows disabling commands that were registered. // It is useful when running multiple bot instances to disabled some plugins like url which // is already present on some protocols.
[ "Disable", "allows", "disabling", "commands", "that", "were", "registered", ".", "It", "is", "useful", "when", "running", "multiple", "bot", "instances", "to", "disabled", "some", "plugins", "like", "url", "which", "is", "already", "present", "on", "some", "pr...
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L296-L298
train
go-chat-bot/bot
bot.go
New
func New(h *Handlers, bc *Config) *Bot { if h.Errored == nil { h.Errored = logErrorHandler } b := &Bot{ handlers: h, cron: cron.New(), msgsToSend: make(chan responseMessage, MsgBuffer), done: make(chan struct{}), Protocol: bc.Protocol, Server: bc.Server, } // Launch the background goroutine that isolates the possibly non-threadsafe // message sending logic of the underlying transport layer. go b.processMessages() b.startMessageStreams() b.startPeriodicCommands() return b }
go
func New(h *Handlers, bc *Config) *Bot { if h.Errored == nil { h.Errored = logErrorHandler } b := &Bot{ handlers: h, cron: cron.New(), msgsToSend: make(chan responseMessage, MsgBuffer), done: make(chan struct{}), Protocol: bc.Protocol, Server: bc.Server, } // Launch the background goroutine that isolates the possibly non-threadsafe // message sending logic of the underlying transport layer. go b.processMessages() b.startMessageStreams() b.startPeriodicCommands() return b }
[ "func", "New", "(", "h", "*", "Handlers", ",", "bc", "*", "Config", ")", "*", "Bot", "{", "if", "h", ".", "Errored", "==", "nil", "{", "h", ".", "Errored", "=", "logErrorHandler", "\n", "}", "\n\n", "b", ":=", "&", "Bot", "{", "handlers", ":", ...
// New configures a new bot instance
[ "New", "configures", "a", "new", "bot", "instance" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L77-L99
train
go-chat-bot/bot
bot.go
MessageReceived
func (b *Bot) MessageReceived(channel *ChannelData, message *Message, sender *User) { command, err := parse(message.Text, channel, sender) if err != nil { b.SendMessage(channel.Channel, err.Error(), sender) return } if command == nil { b.executePassiveCommands(&PassiveCmd{ Raw: message.Text, MessageData: message, Channel: channel.Channel, ChannelData: channel, User: sender, }) return } if b.isDisabled(command.Command) { return } switch command.Command { case helpCommand: b.help(command) default: b.handleCmd(command) } }
go
func (b *Bot) MessageReceived(channel *ChannelData, message *Message, sender *User) { command, err := parse(message.Text, channel, sender) if err != nil { b.SendMessage(channel.Channel, err.Error(), sender) return } if command == nil { b.executePassiveCommands(&PassiveCmd{ Raw: message.Text, MessageData: message, Channel: channel.Channel, ChannelData: channel, User: sender, }) return } if b.isDisabled(command.Command) { return } switch command.Command { case helpCommand: b.help(command) default: b.handleCmd(command) } }
[ "func", "(", "b", "*", "Bot", ")", "MessageReceived", "(", "channel", "*", "ChannelData", ",", "message", "*", "Message", ",", "sender", "*", "User", ")", "{", "command", ",", "err", ":=", "parse", "(", "message", ".", "Text", ",", "channel", ",", "s...
// MessageReceived must be called by the protocol upon receiving a message
[ "MessageReceived", "must", "be", "called", "by", "the", "protocol", "upon", "receiving", "a", "message" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L160-L188
train
go-chat-bot/bot
bot.go
SendMessage
func (b *Bot) SendMessage(target string, message string, sender *User) { message = b.executeFilterCommands(&FilterCmd{ Target: target, Message: message, User: sender}) if message == "" { return } select { case b.msgsToSend <- responseMessage{target, message, sender}: default: b.errored("Failed to queue message to send.", errors.New("Too busy")) } }
go
func (b *Bot) SendMessage(target string, message string, sender *User) { message = b.executeFilterCommands(&FilterCmd{ Target: target, Message: message, User: sender}) if message == "" { return } select { case b.msgsToSend <- responseMessage{target, message, sender}: default: b.errored("Failed to queue message to send.", errors.New("Too busy")) } }
[ "func", "(", "b", "*", "Bot", ")", "SendMessage", "(", "target", "string", ",", "message", "string", ",", "sender", "*", "User", ")", "{", "message", "=", "b", ".", "executeFilterCommands", "(", "&", "FilterCmd", "{", "Target", ":", "target", ",", "Mes...
// SendMessage queues a message for a target recipient, optionally from a particular sender.
[ "SendMessage", "queues", "a", "message", "for", "a", "target", "recipient", "optionally", "from", "a", "particular", "sender", "." ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L191-L205
train
go-chat-bot/bot
slack/slack.go
FindUserBySlackID
func FindUserBySlackID(userID string) *bot.User { slackUser, err := api.GetUserInfo(userID) if err != nil { fmt.Printf("Error retrieving slack user: %s\n", err) return &bot.User{ ID: userID, IsBot: false} } return &bot.User{ ID: userID, Nick: slackUser.Name, RealName: slackUser.Profile.RealName, IsBot: slackUser.IsBot} }
go
func FindUserBySlackID(userID string) *bot.User { slackUser, err := api.GetUserInfo(userID) if err != nil { fmt.Printf("Error retrieving slack user: %s\n", err) return &bot.User{ ID: userID, IsBot: false} } return &bot.User{ ID: userID, Nick: slackUser.Name, RealName: slackUser.Profile.RealName, IsBot: slackUser.IsBot} }
[ "func", "FindUserBySlackID", "(", "userID", "string", ")", "*", "bot", ".", "User", "{", "slackUser", ",", "err", ":=", "api", ".", "GetUserInfo", "(", "userID", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ...
// FindUserBySlackID converts a slack.User into a bot.User struct
[ "FindUserBySlackID", "converts", "a", "slack", ".", "User", "into", "a", "bot", ".", "User", "struct" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L42-L55
train
go-chat-bot/bot
slack/slack.go
extractUser
func extractUser(event *slack.MessageEvent) *bot.User { var isBot bool var userID string if len(event.User) == 0 { userID = event.BotID isBot = true } else { userID = event.User isBot = false } user := FindUserBySlackID(userID) if len(user.Nick) == 0 { user.IsBot = isBot } return user }
go
func extractUser(event *slack.MessageEvent) *bot.User { var isBot bool var userID string if len(event.User) == 0 { userID = event.BotID isBot = true } else { userID = event.User isBot = false } user := FindUserBySlackID(userID) if len(user.Nick) == 0 { user.IsBot = isBot } return user }
[ "func", "extractUser", "(", "event", "*", "slack", ".", "MessageEvent", ")", "*", "bot", ".", "User", "{", "var", "isBot", "bool", "\n", "var", "userID", "string", "\n", "if", "len", "(", "event", ".", "User", ")", "==", "0", "{", "userID", "=", "e...
// Extracts user information from slack API
[ "Extracts", "user", "information", "from", "slack", "API" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L58-L74
train
go-chat-bot/bot
slack/slack.go
RunWithFilter
func RunWithFilter(token string, customMessageFilter MessageFilter) { if customMessageFilter == nil { panic("A valid message filter must be provided.") } messageFilter = customMessageFilter Run(token) }
go
func RunWithFilter(token string, customMessageFilter MessageFilter) { if customMessageFilter == nil { panic("A valid message filter must be provided.") } messageFilter = customMessageFilter Run(token) }
[ "func", "RunWithFilter", "(", "token", "string", ",", "customMessageFilter", "MessageFilter", ")", "{", "if", "customMessageFilter", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "messageFilter", "=", "customMessageFilter", "\n", "Run", "("...
// RunWithFilter executes the bot and sets up a message filter which will // receive all the messages before they are sent to slack
[ "RunWithFilter", "executes", "the", "bot", "and", "sets", "up", "a", "message", "filter", "which", "will", "receive", "all", "the", "messages", "before", "they", "are", "sent", "to", "slack" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L118-L124
train
go-chat-bot/bot
slack/slack.go
Run
func Run(token string) { api = slack.New(token) rtm = api.NewRTM() teaminfo, _ = api.GetTeamInfo() b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: teaminfo.Domain, }, ) b.Disable([]string{"url"}) go rtm.ManageConnection() Loop: for { select { case msg := <-rtm.IncomingEvents: switch ev := msg.Data.(type) { case *slack.HelloEvent: readBotInfo(api) readChannelData(api) case *slack.ChannelCreatedEvent: readChannelData(api) case *slack.ChannelRenameEvent: readChannelData(api) case *slack.MessageEvent: if !ev.Hidden && !ownMessage(ev.User) { C := channelList[ev.Channel] var channel = ev.Channel if C.IsChannel { channel = fmt.Sprintf("#%s", C.Name) } go b.MessageReceived( &bot.ChannelData{ Protocol: "slack", Server: teaminfo.Domain, Channel: channel, HumanName: C.Name, IsPrivate: !C.IsChannel, }, extractText(ev), extractUser(ev), ) } case *slack.RTMError: fmt.Printf("Error: %s\n", ev.Error()) case *slack.InvalidAuthEvent: fmt.Printf("Invalid credentials") break Loop } } } }
go
func Run(token string) { api = slack.New(token) rtm = api.NewRTM() teaminfo, _ = api.GetTeamInfo() b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: teaminfo.Domain, }, ) b.Disable([]string{"url"}) go rtm.ManageConnection() Loop: for { select { case msg := <-rtm.IncomingEvents: switch ev := msg.Data.(type) { case *slack.HelloEvent: readBotInfo(api) readChannelData(api) case *slack.ChannelCreatedEvent: readChannelData(api) case *slack.ChannelRenameEvent: readChannelData(api) case *slack.MessageEvent: if !ev.Hidden && !ownMessage(ev.User) { C := channelList[ev.Channel] var channel = ev.Channel if C.IsChannel { channel = fmt.Sprintf("#%s", C.Name) } go b.MessageReceived( &bot.ChannelData{ Protocol: "slack", Server: teaminfo.Domain, Channel: channel, HumanName: C.Name, IsPrivate: !C.IsChannel, }, extractText(ev), extractUser(ev), ) } case *slack.RTMError: fmt.Printf("Error: %s\n", ev.Error()) case *slack.InvalidAuthEvent: fmt.Printf("Invalid credentials") break Loop } } } }
[ "func", "Run", "(", "token", "string", ")", "{", "api", "=", "slack", ".", "New", "(", "token", ")", "\n", "rtm", "=", "api", ".", "NewRTM", "(", ")", "\n", "teaminfo", ",", "_", "=", "api", ".", "GetTeamInfo", "(", ")", "\n\n", "b", ":=", "bot...
// Run connects to slack RTM API using the provided token
[ "Run", "connects", "to", "slack", "RTM", "API", "using", "the", "provided", "token" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L127-L187
train
go-chat-bot/bot
irc/irc.go
SetUpConn
func SetUpConn(c *Config) (*bot.Bot, *ircevent.Connection) { return SetUp(c), ircConn }
go
func SetUpConn(c *Config) (*bot.Bot, *ircevent.Connection) { return SetUp(c), ircConn }
[ "func", "SetUpConn", "(", "c", "*", "Config", ")", "(", "*", "bot", ".", "Bot", ",", "*", "ircevent", ".", "Connection", ")", "{", "return", "SetUp", "(", "c", ")", ",", "ircConn", "\n", "}" ]
// SetUpConn wraps SetUp and returns ircConn in addition to bot
[ "SetUpConn", "wraps", "SetUp", "and", "returns", "ircConn", "in", "addition", "to", "bot" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/irc/irc.go#L128-L130
train
go-chat-bot/bot
irc/irc.go
Run
func Run(c *Config) { if c != nil { SetUp(c) } err := ircConn.Connect(config.Server) if err != nil { log.Fatal(err) } ircConn.Loop() }
go
func Run(c *Config) { if c != nil { SetUp(c) } err := ircConn.Connect(config.Server) if err != nil { log.Fatal(err) } ircConn.Loop() }
[ "func", "Run", "(", "c", "*", "Config", ")", "{", "if", "c", "!=", "nil", "{", "SetUp", "(", "c", ")", "\n", "}", "\n\n", "err", ":=", "ircConn", ".", "Connect", "(", "config", ".", "Server", ")", "\n", "if", "err", "!=", "nil", "{", "log", "...
// Run reads the Config, connect to the specified IRC server and starts the bot. // The bot will automatically join all the channels specified in the configuration
[ "Run", "reads", "the", "Config", "connect", "to", "the", "specified", "IRC", "server", "and", "starts", "the", "bot", ".", "The", "bot", "will", "automatically", "join", "all", "the", "channels", "specified", "in", "the", "configuration" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/irc/irc.go#L134-L144
train
go-chat-bot/bot
telegram/telegram.go
Run
func Run(token string, debug bool) { var err error tg, err = tgbotapi.NewBotAPI(token) if err != nil { log.Fatal(err) } tg.Debug = debug log.Printf("Authorized on account %s", tg.Self.UserName) u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates, err := tg.GetUpdatesChan(u) if err != nil { log.Fatal(err) } b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: server, }, ) b.Disable([]string{"url"}) for update := range updates { target := &bot.ChannelData{ Protocol: protocol, Server: server, Channel: strconv.FormatInt(update.Message.Chat.ID, 10), IsPrivate: update.Message.Chat.IsPrivate()} name := []string{update.Message.From.FirstName, update.Message.From.LastName} message := &bot.Message{ Text: update.Message.Text, } b.MessageReceived(target, message, &bot.User{ ID: strconv.Itoa(update.Message.From.ID), Nick: update.Message.From.UserName, RealName: strings.Join(name, " ")}) } }
go
func Run(token string, debug bool) { var err error tg, err = tgbotapi.NewBotAPI(token) if err != nil { log.Fatal(err) } tg.Debug = debug log.Printf("Authorized on account %s", tg.Self.UserName) u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates, err := tg.GetUpdatesChan(u) if err != nil { log.Fatal(err) } b := bot.New(&bot.Handlers{ Response: responseHandler, }, &bot.Config{ Protocol: protocol, Server: server, }, ) b.Disable([]string{"url"}) for update := range updates { target := &bot.ChannelData{ Protocol: protocol, Server: server, Channel: strconv.FormatInt(update.Message.Chat.ID, 10), IsPrivate: update.Message.Chat.IsPrivate()} name := []string{update.Message.From.FirstName, update.Message.From.LastName} message := &bot.Message{ Text: update.Message.Text, } b.MessageReceived(target, message, &bot.User{ ID: strconv.Itoa(update.Message.From.ID), Nick: update.Message.From.UserName, RealName: strings.Join(name, " ")}) } }
[ "func", "Run", "(", "token", "string", ",", "debug", "bool", ")", "{", "var", "err", "error", "\n", "tg", ",", "err", "=", "tgbotapi", ".", "NewBotAPI", "(", "token", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")",...
// Run executes the bot and connects to Telegram using the provided token. Use the debug flag if you wish to see all traffic logged
[ "Run", "executes", "the", "bot", "and", "connects", "to", "Telegram", "using", "the", "provided", "token", ".", "Use", "the", "debug", "flag", "if", "you", "wish", "to", "see", "all", "traffic", "logged" ]
a72276ecd4eadb8f0129aa19caad1fc180d8f0f7
https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/telegram/telegram.go#L34-L79
train
stathat/consistent
consistent.go
New
func New() *Consistent { c := new(Consistent) c.NumberOfReplicas = 20 c.circle = make(map[uint32]string) c.members = make(map[string]bool) return c }
go
func New() *Consistent { c := new(Consistent) c.NumberOfReplicas = 20 c.circle = make(map[uint32]string) c.members = make(map[string]bool) return c }
[ "func", "New", "(", ")", "*", "Consistent", "{", "c", ":=", "new", "(", "Consistent", ")", "\n", "c", ".", "NumberOfReplicas", "=", "20", "\n", "c", ".", "circle", "=", "make", "(", "map", "[", "uint32", "]", "string", ")", "\n", "c", ".", "membe...
// New creates a new Consistent object with a default setting of 20 replicas for each entry. // // To change the number of replicas, set NumberOfReplicas before adding entries.
[ "New", "creates", "a", "new", "Consistent", "object", "with", "a", "default", "setting", "of", "20", "replicas", "for", "each", "entry", ".", "To", "change", "the", "number", "of", "replicas", "set", "NumberOfReplicas", "before", "adding", "entries", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L59-L65
train
stathat/consistent
consistent.go
eltKey
func (c *Consistent) eltKey(elt string, idx int) string { // return elt + "|" + strconv.Itoa(idx) return strconv.Itoa(idx) + elt }
go
func (c *Consistent) eltKey(elt string, idx int) string { // return elt + "|" + strconv.Itoa(idx) return strconv.Itoa(idx) + elt }
[ "func", "(", "c", "*", "Consistent", ")", "eltKey", "(", "elt", "string", ",", "idx", "int", ")", "string", "{", "// return elt + \"|\" + strconv.Itoa(idx)", "return", "strconv", ".", "Itoa", "(", "idx", ")", "+", "elt", "\n", "}" ]
// eltKey generates a string key for an element with an index.
[ "eltKey", "generates", "a", "string", "key", "for", "an", "element", "with", "an", "index", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L68-L71
train
stathat/consistent
consistent.go
Add
func (c *Consistent) Add(elt string) { c.Lock() defer c.Unlock() c.add(elt) }
go
func (c *Consistent) Add(elt string) { c.Lock() defer c.Unlock() c.add(elt) }
[ "func", "(", "c", "*", "Consistent", ")", "Add", "(", "elt", "string", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "c", ".", "add", "(", "elt", ")", "\n", "}" ]
// Add inserts a string element in the consistent hash.
[ "Add", "inserts", "a", "string", "element", "in", "the", "consistent", "hash", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L74-L78
train
stathat/consistent
consistent.go
Remove
func (c *Consistent) Remove(elt string) { c.Lock() defer c.Unlock() c.remove(elt) }
go
func (c *Consistent) Remove(elt string) { c.Lock() defer c.Unlock() c.remove(elt) }
[ "func", "(", "c", "*", "Consistent", ")", "Remove", "(", "elt", "string", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "c", ".", "remove", "(", "elt", ")", "\n", "}" ]
// Remove removes an element from the hash.
[ "Remove", "removes", "an", "element", "from", "the", "hash", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L91-L95
train
stathat/consistent
consistent.go
Set
func (c *Consistent) Set(elts []string) { c.Lock() defer c.Unlock() for k := range c.members { found := false for _, v := range elts { if k == v { found = true break } } if !found { c.remove(k) } } for _, v := range elts { _, exists := c.members[v] if exists { continue } c.add(v) } }
go
func (c *Consistent) Set(elts []string) { c.Lock() defer c.Unlock() for k := range c.members { found := false for _, v := range elts { if k == v { found = true break } } if !found { c.remove(k) } } for _, v := range elts { _, exists := c.members[v] if exists { continue } c.add(v) } }
[ "func", "(", "c", "*", "Consistent", ")", "Set", "(", "elts", "[", "]", "string", ")", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n", "for", "k", ":=", "range", "c", ".", "members", "{", "found", ":=", "fa...
// Set sets all the elements in the hash. If there are existing elements not // present in elts, they will be removed.
[ "Set", "sets", "all", "the", "elements", "in", "the", "hash", ".", "If", "there", "are", "existing", "elements", "not", "present", "in", "elts", "they", "will", "be", "removed", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L109-L131
train
stathat/consistent
consistent.go
Get
func (c *Consistent) Get(name string) (string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return "", ErrEmptyCircle } key := c.hashKey(name) i := c.search(key) return c.circle[c.sortedHashes[i]], nil }
go
func (c *Consistent) Get(name string) (string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return "", ErrEmptyCircle } key := c.hashKey(name) i := c.search(key) return c.circle[c.sortedHashes[i]], nil }
[ "func", "(", "c", "*", "Consistent", ")", "Get", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "c", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "c", ".", "circle", ")", "=...
// Get returns an element close to where name hashes to in the circle.
[ "Get", "returns", "an", "element", "close", "to", "where", "name", "hashes", "to", "in", "the", "circle", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L144-L153
train
stathat/consistent
consistent.go
GetTwo
func (c *Consistent) GetTwo(name string) (string, string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return "", "", ErrEmptyCircle } key := c.hashKey(name) i := c.search(key) a := c.circle[c.sortedHashes[i]] if c.count == 1 { return a, "", nil } start := i var b string for i = start + 1; i != start; i++ { if i >= len(c.sortedHashes) { i = 0 } b = c.circle[c.sortedHashes[i]] if b != a { break } } return a, b, nil }
go
func (c *Consistent) GetTwo(name string) (string, string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return "", "", ErrEmptyCircle } key := c.hashKey(name) i := c.search(key) a := c.circle[c.sortedHashes[i]] if c.count == 1 { return a, "", nil } start := i var b string for i = start + 1; i != start; i++ { if i >= len(c.sortedHashes) { i = 0 } b = c.circle[c.sortedHashes[i]] if b != a { break } } return a, b, nil }
[ "func", "(", "c", "*", "Consistent", ")", "GetTwo", "(", "name", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "c", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "c", ".", ...
// GetTwo returns the two closest distinct elements to the name input in the circle.
[ "GetTwo", "returns", "the", "two", "closest", "distinct", "elements", "to", "the", "name", "input", "in", "the", "circle", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L167-L193
train
stathat/consistent
consistent.go
GetN
func (c *Consistent) GetN(name string, n int) ([]string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return nil, ErrEmptyCircle } if c.count < int64(n) { n = int(c.count) } var ( key = c.hashKey(name) i = c.search(key) start = i res = make([]string, 0, n) elem = c.circle[c.sortedHashes[i]] ) res = append(res, elem) if len(res) == n { return res, nil } for i = start + 1; i != start; i++ { if i >= len(c.sortedHashes) { i = 0 } elem = c.circle[c.sortedHashes[i]] if !sliceContainsMember(res, elem) { res = append(res, elem) } if len(res) == n { break } } return res, nil }
go
func (c *Consistent) GetN(name string, n int) ([]string, error) { c.RLock() defer c.RUnlock() if len(c.circle) == 0 { return nil, ErrEmptyCircle } if c.count < int64(n) { n = int(c.count) } var ( key = c.hashKey(name) i = c.search(key) start = i res = make([]string, 0, n) elem = c.circle[c.sortedHashes[i]] ) res = append(res, elem) if len(res) == n { return res, nil } for i = start + 1; i != start; i++ { if i >= len(c.sortedHashes) { i = 0 } elem = c.circle[c.sortedHashes[i]] if !sliceContainsMember(res, elem) { res = append(res, elem) } if len(res) == n { break } } return res, nil }
[ "func", "(", "c", "*", "Consistent", ")", "GetN", "(", "name", "string", ",", "n", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "c", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "RUnlock", "(", ")", "\n\n", "if", "len", "(...
// GetN returns the N closest distinct elements to the name input in the circle.
[ "GetN", "returns", "the", "N", "closest", "distinct", "elements", "to", "the", "name", "input", "in", "the", "circle", "." ]
ad91dc4a3a642859730ff3d65929fce009bfdc23
https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L196-L236
train
tecbot/gorocksdb
ratelimiter.go
NewRateLimiter
func NewRateLimiter(rate_bytes_per_sec, refill_period_us int64, fairness int32) *RateLimiter { return NewNativeRateLimiter(C.rocksdb_ratelimiter_create( C.int64_t(rate_bytes_per_sec), C.int64_t(refill_period_us), C.int32_t(fairness), )) }
go
func NewRateLimiter(rate_bytes_per_sec, refill_period_us int64, fairness int32) *RateLimiter { return NewNativeRateLimiter(C.rocksdb_ratelimiter_create( C.int64_t(rate_bytes_per_sec), C.int64_t(refill_period_us), C.int32_t(fairness), )) }
[ "func", "NewRateLimiter", "(", "rate_bytes_per_sec", ",", "refill_period_us", "int64", ",", "fairness", "int32", ")", "*", "RateLimiter", "{", "return", "NewNativeRateLimiter", "(", "C", ".", "rocksdb_ratelimiter_create", "(", "C", ".", "int64_t", "(", "rate_bytes_p...
// NewDefaultRateLimiter creates a default RateLimiter object.
[ "NewDefaultRateLimiter", "creates", "a", "default", "RateLimiter", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/ratelimiter.go#L14-L20
train
tecbot/gorocksdb
ratelimiter.go
Destroy
func (self *RateLimiter) Destroy() { C.rocksdb_ratelimiter_destroy(self.c) self.c = nil }
go
func (self *RateLimiter) Destroy() { C.rocksdb_ratelimiter_destroy(self.c) self.c = nil }
[ "func", "(", "self", "*", "RateLimiter", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_ratelimiter_destroy", "(", "self", ".", "c", ")", "\n", "self", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the RateLimiter object.
[ "Destroy", "deallocates", "the", "RateLimiter", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/ratelimiter.go#L28-L31
train
tecbot/gorocksdb
dbpath.go
NewDBPath
func NewDBPath(path string, target_size uint64) *DBPath { cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) return NewNativeDBPath(C.rocksdb_dbpath_create(cpath, C.uint64_t(target_size))) }
go
func NewDBPath(path string, target_size uint64) *DBPath { cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) return NewNativeDBPath(C.rocksdb_dbpath_create(cpath, C.uint64_t(target_size))) }
[ "func", "NewDBPath", "(", "path", "string", ",", "target_size", "uint64", ")", "*", "DBPath", "{", "cpath", ":=", "C", ".", "CString", "(", "path", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cpath", ")", ")", "\n", "...
// NewDBPath creates a DBPath object // with the given path and target_size.
[ "NewDBPath", "creates", "a", "DBPath", "object", "with", "the", "given", "path", "and", "target_size", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/dbpath.go#L15-L19
train
tecbot/gorocksdb
dbpath.go
NewDBPathsFromData
func NewDBPathsFromData(paths []string, target_sizes []uint64) []*DBPath { dbpaths := make([]*DBPath, len(paths)) for i, path := range paths { targetSize := target_sizes[i] dbpaths[i] = NewDBPath(path, targetSize) } return dbpaths }
go
func NewDBPathsFromData(paths []string, target_sizes []uint64) []*DBPath { dbpaths := make([]*DBPath, len(paths)) for i, path := range paths { targetSize := target_sizes[i] dbpaths[i] = NewDBPath(path, targetSize) } return dbpaths }
[ "func", "NewDBPathsFromData", "(", "paths", "[", "]", "string", ",", "target_sizes", "[", "]", "uint64", ")", "[", "]", "*", "DBPath", "{", "dbpaths", ":=", "make", "(", "[", "]", "*", "DBPath", ",", "len", "(", "paths", ")", ")", "\n", "for", "i",...
// NewDBPathsFromData creates a slice with allocated DBPath objects // from paths and target_sizes.
[ "NewDBPathsFromData", "creates", "a", "slice", "with", "allocated", "DBPath", "objects", "from", "paths", "and", "target_sizes", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/dbpath.go#L33-L41
train
tecbot/gorocksdb
options_read.go
Destroy
func (opts *ReadOptions) Destroy() { C.rocksdb_readoptions_destroy(opts.c) opts.c = nil }
go
func (opts *ReadOptions) Destroy() { C.rocksdb_readoptions_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "ReadOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_readoptions_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the ReadOptions object.
[ "Destroy", "deallocates", "the", "ReadOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_read.go#L122-L125
train
tecbot/gorocksdb
transaction.go
Commit
func (transaction *Transaction) Commit() error { var ( cErr *C.char ) C.rocksdb_transaction_commit(transaction.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (transaction *Transaction) Commit() error { var ( cErr *C.char ) C.rocksdb_transaction_commit(transaction.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "transaction", "*", "Transaction", ")", "Commit", "(", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", ")", "\n", "C", ".", "rocksdb_transaction_commit", "(", "transaction", ".", "c", ",", "&", "cErr", ")", "\n", "if"...
// Commit commits the transaction to the database.
[ "Commit", "commits", "the", "transaction", "to", "the", "database", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L23-L33
train
tecbot/gorocksdb
transaction.go
Rollback
func (transaction *Transaction) Rollback() error { var ( cErr *C.char ) C.rocksdb_transaction_rollback(transaction.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (transaction *Transaction) Rollback() error { var ( cErr *C.char ) C.rocksdb_transaction_rollback(transaction.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "transaction", "*", "Transaction", ")", "Rollback", "(", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", ")", "\n", "C", ".", "rocksdb_transaction_rollback", "(", "transaction", ".", "c", ",", "&", "cErr", ")", "\n\n", ...
// Rollback performs a rollback on the transaction.
[ "Rollback", "performs", "a", "rollback", "on", "the", "transaction", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L36-L47
train
tecbot/gorocksdb
transaction.go
Put
func (transaction *Transaction) Put(key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_transaction_put( transaction.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (transaction *Transaction) Put(key, value []byte) error { var ( cErr *C.char cKey = byteToChar(key) cValue = byteToChar(value) ) C.rocksdb_transaction_put( transaction.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value)), &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "transaction", "*", "Transaction", ")", "Put", "(", "key", ",", "value", "[", "]", "byte", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cKey", "=", "byteToChar", "(", "key", ")", "\n", "cValue", "=", "byteToChar...
// Put writes data associated with a key to the transaction.
[ "Put", "writes", "data", "associated", "with", "a", "key", "to", "the", "transaction", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L84-L98
train
tecbot/gorocksdb
transaction.go
Delete
func (transaction *Transaction) Delete(key []byte) error { var ( cErr *C.char cKey = byteToChar(key) ) C.rocksdb_transaction_delete(transaction.c, cKey, C.size_t(len(key)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (transaction *Transaction) Delete(key []byte) error { var ( cErr *C.char cKey = byteToChar(key) ) C.rocksdb_transaction_delete(transaction.c, cKey, C.size_t(len(key)), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "transaction", "*", "Transaction", ")", "Delete", "(", "key", "[", "]", "byte", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cKey", "=", "byteToChar", "(", "key", ")", "\n", ")", "\n", "C", ".", "rocksdb_transac...
// Delete removes the data associated with the key from the transaction.
[ "Delete", "removes", "the", "data", "associated", "with", "the", "key", "from", "the", "transaction", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L101-L112
train
tecbot/gorocksdb
transaction.go
NewIterator
func (transaction *Transaction) NewIterator(opts *ReadOptions) *Iterator { return NewNativeIterator( unsafe.Pointer(C.rocksdb_transaction_create_iterator(transaction.c, opts.c))) }
go
func (transaction *Transaction) NewIterator(opts *ReadOptions) *Iterator { return NewNativeIterator( unsafe.Pointer(C.rocksdb_transaction_create_iterator(transaction.c, opts.c))) }
[ "func", "(", "transaction", "*", "Transaction", ")", "NewIterator", "(", "opts", "*", "ReadOptions", ")", "*", "Iterator", "{", "return", "NewNativeIterator", "(", "unsafe", ".", "Pointer", "(", "C", ".", "rocksdb_transaction_create_iterator", "(", "transaction", ...
// NewIterator returns an Iterator over the database that uses the // ReadOptions given.
[ "NewIterator", "returns", "an", "Iterator", "over", "the", "database", "that", "uses", "the", "ReadOptions", "given", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L116-L119
train
tecbot/gorocksdb
transaction.go
Destroy
func (transaction *Transaction) Destroy() { C.rocksdb_transaction_destroy(transaction.c) transaction.c = nil }
go
func (transaction *Transaction) Destroy() { C.rocksdb_transaction_destroy(transaction.c) transaction.c = nil }
[ "func", "(", "transaction", "*", "Transaction", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_transaction_destroy", "(", "transaction", ".", "c", ")", "\n", "transaction", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the transaction object.
[ "Destroy", "deallocates", "the", "transaction", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/transaction.go#L122-L125
train
tecbot/gorocksdb
backup.go
GetTimestamp
func (b *BackupEngineInfo) GetTimestamp(index int) int64 { return int64(C.rocksdb_backup_engine_info_timestamp(b.c, C.int(index))) }
go
func (b *BackupEngineInfo) GetTimestamp(index int) int64 { return int64(C.rocksdb_backup_engine_info_timestamp(b.c, C.int(index))) }
[ "func", "(", "b", "*", "BackupEngineInfo", ")", "GetTimestamp", "(", "index", "int", ")", "int64", "{", "return", "int64", "(", "C", ".", "rocksdb_backup_engine_info_timestamp", "(", "b", ".", "c", ",", "C", ".", "int", "(", "index", ")", ")", ")", "\n...
// GetTimestamp gets the timestamp at which the backup index was taken.
[ "GetTimestamp", "gets", "the", "timestamp", "at", "which", "the", "backup", "index", "was", "taken", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L24-L26
train
tecbot/gorocksdb
backup.go
GetBackupId
func (b *BackupEngineInfo) GetBackupId(index int) int64 { return int64(C.rocksdb_backup_engine_info_backup_id(b.c, C.int(index))) }
go
func (b *BackupEngineInfo) GetBackupId(index int) int64 { return int64(C.rocksdb_backup_engine_info_backup_id(b.c, C.int(index))) }
[ "func", "(", "b", "*", "BackupEngineInfo", ")", "GetBackupId", "(", "index", "int", ")", "int64", "{", "return", "int64", "(", "C", ".", "rocksdb_backup_engine_info_backup_id", "(", "b", ".", "c", ",", "C", ".", "int", "(", "index", ")", ")", ")", "\n"...
// GetBackupId gets an id that uniquely identifies a backup // regardless of its position.
[ "GetBackupId", "gets", "an", "id", "that", "uniquely", "identifies", "a", "backup", "regardless", "of", "its", "position", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L30-L32
train
tecbot/gorocksdb
backup.go
GetSize
func (b *BackupEngineInfo) GetSize(index int) int64 { return int64(C.rocksdb_backup_engine_info_size(b.c, C.int(index))) }
go
func (b *BackupEngineInfo) GetSize(index int) int64 { return int64(C.rocksdb_backup_engine_info_size(b.c, C.int(index))) }
[ "func", "(", "b", "*", "BackupEngineInfo", ")", "GetSize", "(", "index", "int", ")", "int64", "{", "return", "int64", "(", "C", ".", "rocksdb_backup_engine_info_size", "(", "b", ".", "c", ",", "C", ".", "int", "(", "index", ")", ")", ")", "\n", "}" ]
// GetSize get the size of the backup in bytes.
[ "GetSize", "get", "the", "size", "of", "the", "backup", "in", "bytes", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L35-L37
train
tecbot/gorocksdb
backup.go
GetNumFiles
func (b *BackupEngineInfo) GetNumFiles(index int) int32 { return int32(C.rocksdb_backup_engine_info_number_files(b.c, C.int(index))) }
go
func (b *BackupEngineInfo) GetNumFiles(index int) int32 { return int32(C.rocksdb_backup_engine_info_number_files(b.c, C.int(index))) }
[ "func", "(", "b", "*", "BackupEngineInfo", ")", "GetNumFiles", "(", "index", "int", ")", "int32", "{", "return", "int32", "(", "C", ".", "rocksdb_backup_engine_info_number_files", "(", "b", ".", "c", ",", "C", ".", "int", "(", "index", ")", ")", ")", "...
// GetNumFiles gets the number of files in the backup index.
[ "GetNumFiles", "gets", "the", "number", "of", "files", "in", "the", "backup", "index", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L40-L42
train
tecbot/gorocksdb
backup.go
Destroy
func (b *BackupEngineInfo) Destroy() { C.rocksdb_backup_engine_info_destroy(b.c) b.c = nil }
go
func (b *BackupEngineInfo) Destroy() { C.rocksdb_backup_engine_info_destroy(b.c) b.c = nil }
[ "func", "(", "b", "*", "BackupEngineInfo", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_backup_engine_info_destroy", "(", "b", ".", "c", ")", "\n", "b", ".", "c", "=", "nil", "\n", "}" ]
// Destroy destroys the backup engine info instance.
[ "Destroy", "destroys", "the", "backup", "engine", "info", "instance", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L45-L48
train
tecbot/gorocksdb
backup.go
SetKeepLogFiles
func (ro *RestoreOptions) SetKeepLogFiles(v int) { C.rocksdb_restore_options_set_keep_log_files(ro.c, C.int(v)) }
go
func (ro *RestoreOptions) SetKeepLogFiles(v int) { C.rocksdb_restore_options_set_keep_log_files(ro.c, C.int(v)) }
[ "func", "(", "ro", "*", "RestoreOptions", ")", "SetKeepLogFiles", "(", "v", "int", ")", "{", "C", ".", "rocksdb_restore_options_set_keep_log_files", "(", "ro", ".", "c", ",", "C", ".", "int", "(", "v", ")", ")", "\n", "}" ]
// SetKeepLogFiles is used to set or unset the keep_log_files option // If true, restore won't overwrite the existing log files in wal_dir. It will // also move all log files from archive directory to wal_dir. // By default, this is false.
[ "SetKeepLogFiles", "is", "used", "to", "set", "or", "unset", "the", "keep_log_files", "option", "If", "true", "restore", "won", "t", "overwrite", "the", "existing", "log", "files", "in", "wal_dir", ".", "It", "will", "also", "move", "all", "log", "files", ...
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L67-L69
train
tecbot/gorocksdb
backup.go
OpenBackupEngine
func OpenBackupEngine(opts *Options, path string) (*BackupEngine, error) { var cErr *C.char cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) be := C.rocksdb_backup_engine_open(opts.c, cpath, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &BackupEngine{ c: be, path: path, opts: opts, }, nil }
go
func OpenBackupEngine(opts *Options, path string) (*BackupEngine, error) { var cErr *C.char cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) be := C.rocksdb_backup_engine_open(opts.c, cpath, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &BackupEngine{ c: be, path: path, opts: opts, }, nil }
[ "func", "OpenBackupEngine", "(", "opts", "*", "Options", ",", "path", "string", ")", "(", "*", "BackupEngine", ",", "error", ")", "{", "var", "cErr", "*", "C", ".", "char", "\n", "cpath", ":=", "C", ".", "CString", "(", "path", ")", "\n", "defer", ...
// OpenBackupEngine opens a backup engine with specified options.
[ "OpenBackupEngine", "opens", "a", "backup", "engine", "with", "specified", "options", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L85-L100
train
tecbot/gorocksdb
backup.go
CreateNewBackup
func (b *BackupEngine) CreateNewBackup(db *DB) error { var cErr *C.char C.rocksdb_backup_engine_create_new_backup(b.c, db.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (b *BackupEngine) CreateNewBackup(db *DB) error { var cErr *C.char C.rocksdb_backup_engine_create_new_backup(b.c, db.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "b", "*", "BackupEngine", ")", "CreateNewBackup", "(", "db", "*", "DB", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n\n", "C", ".", "rocksdb_backup_engine_create_new_backup", "(", "b", ".", "c", ",", "db", ".", "c", ",", "...
// CreateNewBackup takes a new backup from db.
[ "CreateNewBackup", "takes", "a", "new", "backup", "from", "db", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L108-L118
train
tecbot/gorocksdb
backup.go
GetInfo
func (b *BackupEngine) GetInfo() *BackupEngineInfo { return &BackupEngineInfo{ c: C.rocksdb_backup_engine_get_backup_info(b.c), } }
go
func (b *BackupEngine) GetInfo() *BackupEngineInfo { return &BackupEngineInfo{ c: C.rocksdb_backup_engine_get_backup_info(b.c), } }
[ "func", "(", "b", "*", "BackupEngine", ")", "GetInfo", "(", ")", "*", "BackupEngineInfo", "{", "return", "&", "BackupEngineInfo", "{", "c", ":", "C", ".", "rocksdb_backup_engine_get_backup_info", "(", "b", ".", "c", ")", ",", "}", "\n", "}" ]
// GetInfo gets an object that gives information about // the backups that have already been taken
[ "GetInfo", "gets", "an", "object", "that", "gives", "information", "about", "the", "backups", "that", "have", "already", "been", "taken" ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L122-L126
train
tecbot/gorocksdb
backup.go
Close
func (b *BackupEngine) Close() { C.rocksdb_backup_engine_close(b.c) b.c = nil }
go
func (b *BackupEngine) Close() { C.rocksdb_backup_engine_close(b.c) b.c = nil }
[ "func", "(", "b", "*", "BackupEngine", ")", "Close", "(", ")", "{", "C", ".", "rocksdb_backup_engine_close", "(", "b", ".", "c", ")", "\n", "b", ".", "c", "=", "nil", "\n", "}" ]
// Close close the backup engine and cleans up state // The backups already taken remain on storage.
[ "Close", "close", "the", "backup", "engine", "and", "cleans", "up", "state", "The", "backups", "already", "taken", "remain", "on", "storage", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/backup.go#L149-L152
train
tecbot/gorocksdb
options_env.go
Destroy
func (opts *EnvOptions) Destroy() { C.rocksdb_envoptions_destroy(opts.c) opts.c = nil }
go
func (opts *EnvOptions) Destroy() { C.rocksdb_envoptions_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "EnvOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_envoptions_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the EnvOptions object.
[ "Destroy", "deallocates", "the", "EnvOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_env.go#L22-L25
train
tecbot/gorocksdb
sst_file_writer.go
NewSSTFileWriter
func NewSSTFileWriter(opts *EnvOptions, dbOpts *Options) *SSTFileWriter { c := C.rocksdb_sstfilewriter_create(opts.c, dbOpts.c) return &SSTFileWriter{c: c} }
go
func NewSSTFileWriter(opts *EnvOptions, dbOpts *Options) *SSTFileWriter { c := C.rocksdb_sstfilewriter_create(opts.c, dbOpts.c) return &SSTFileWriter{c: c} }
[ "func", "NewSSTFileWriter", "(", "opts", "*", "EnvOptions", ",", "dbOpts", "*", "Options", ")", "*", "SSTFileWriter", "{", "c", ":=", "C", ".", "rocksdb_sstfilewriter_create", "(", "opts", ".", "c", ",", "dbOpts", ".", "c", ")", "\n", "return", "&", "SST...
// NewSSTFileWriter creates an SSTFileWriter object.
[ "NewSSTFileWriter", "creates", "an", "SSTFileWriter", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/sst_file_writer.go#L19-L22
train
tecbot/gorocksdb
sst_file_writer.go
Open
func (w *SSTFileWriter) Open(path string) error { var ( cErr *C.char cPath = C.CString(path) ) defer C.free(unsafe.Pointer(cPath)) C.rocksdb_sstfilewriter_open(w.c, cPath, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (w *SSTFileWriter) Open(path string) error { var ( cErr *C.char cPath = C.CString(path) ) defer C.free(unsafe.Pointer(cPath)) C.rocksdb_sstfilewriter_open(w.c, cPath, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "w", "*", "SSTFileWriter", ")", "Open", "(", "path", "string", ")", "error", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cPath", "=", "C", ".", "CString", "(", "path", ")", "\n", ")", "\n", "defer", "C", ".", "free", "("...
// Open prepares SstFileWriter to write into file located at "path".
[ "Open", "prepares", "SstFileWriter", "to", "write", "into", "file", "located", "at", "path", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/sst_file_writer.go#L25-L37
train
tecbot/gorocksdb
sst_file_writer.go
Finish
func (w *SSTFileWriter) Finish() error { var cErr *C.char C.rocksdb_sstfilewriter_finish(w.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
go
func (w *SSTFileWriter) Finish() error { var cErr *C.char C.rocksdb_sstfilewriter_finish(w.c, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return errors.New(C.GoString(cErr)) } return nil }
[ "func", "(", "w", "*", "SSTFileWriter", ")", "Finish", "(", ")", "error", "{", "var", "cErr", "*", "C", ".", "char", "\n", "C", ".", "rocksdb_sstfilewriter_finish", "(", "w", ".", "c", ",", "&", "cErr", ")", "\n", "if", "cErr", "!=", "nil", "{", ...
// Finish finishes writing to sst file and close file.
[ "Finish", "finishes", "writing", "to", "sst", "file", "and", "close", "file", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/sst_file_writer.go#L54-L62
train
tecbot/gorocksdb
options_transactiondb.go
Destroy
func (opts *TransactionDBOptions) Destroy() { C.rocksdb_transactiondb_options_destroy(opts.c) opts.c = nil }
go
func (opts *TransactionDBOptions) Destroy() { C.rocksdb_transactiondb_options_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "TransactionDBOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_transactiondb_options_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the TransactionDBOptions object.
[ "Destroy", "deallocates", "the", "TransactionDBOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_transactiondb.go#L69-L72
train
tecbot/gorocksdb
cache.go
NewLRUCache
func NewLRUCache(capacity int) *Cache { return NewNativeCache(C.rocksdb_cache_create_lru(C.size_t(capacity))) }
go
func NewLRUCache(capacity int) *Cache { return NewNativeCache(C.rocksdb_cache_create_lru(C.size_t(capacity))) }
[ "func", "NewLRUCache", "(", "capacity", "int", ")", "*", "Cache", "{", "return", "NewNativeCache", "(", "C", ".", "rocksdb_cache_create_lru", "(", "C", ".", "size_t", "(", "capacity", ")", ")", ")", "\n", "}" ]
// NewLRUCache creates a new LRU Cache object with the capacity given.
[ "NewLRUCache", "creates", "a", "new", "LRU", "Cache", "object", "with", "the", "capacity", "given", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/cache.go#L12-L14
train
tecbot/gorocksdb
cache.go
Destroy
func (c *Cache) Destroy() { C.rocksdb_cache_destroy(c.c) c.c = nil }
go
func (c *Cache) Destroy() { C.rocksdb_cache_destroy(c.c) c.c = nil }
[ "func", "(", "c", "*", "Cache", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_cache_destroy", "(", "c", ".", "c", ")", "\n", "c", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the Cache object.
[ "Destroy", "deallocates", "the", "Cache", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/cache.go#L32-L35
train
tecbot/gorocksdb
options_block_based_table.go
Destroy
func (opts *BlockBasedTableOptions) Destroy() { C.rocksdb_block_based_options_destroy(opts.c) opts.c = nil opts.cache = nil opts.compCache = nil }
go
func (opts *BlockBasedTableOptions) Destroy() { C.rocksdb_block_based_options_destroy(opts.c) opts.c = nil opts.cache = nil opts.compCache = nil }
[ "func", "(", "opts", "*", "BlockBasedTableOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_block_based_options_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "opts", ".", "cache", "=", "nil", "\n", "opts", "....
// Destroy deallocates the BlockBasedTableOptions object.
[ "Destroy", "deallocates", "the", "BlockBasedTableOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_block_based_table.go#L44-L49
train
tecbot/gorocksdb
options_compaction.go
Destroy
func (opts *UniversalCompactionOptions) Destroy() { C.rocksdb_universal_compaction_options_destroy(opts.c) opts.c = nil }
go
func (opts *UniversalCompactionOptions) Destroy() { C.rocksdb_universal_compaction_options_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "UniversalCompactionOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_universal_compaction_options_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the UniversalCompactionOptions object.
[ "Destroy", "deallocates", "the", "UniversalCompactionOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_compaction.go#L127-L130
train
tecbot/gorocksdb
slice.go
NewSlice
func NewSlice(data *C.char, size C.size_t) *Slice { return &Slice{data, size, false} }
go
func NewSlice(data *C.char, size C.size_t) *Slice { return &Slice{data, size, false} }
[ "func", "NewSlice", "(", "data", "*", "C", ".", "char", ",", "size", "C", ".", "size_t", ")", "*", "Slice", "{", "return", "&", "Slice", "{", "data", ",", "size", ",", "false", "}", "\n", "}" ]
// NewSlice returns a slice with the given data.
[ "NewSlice", "returns", "a", "slice", "with", "the", "given", "data", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/slice.go#L23-L25
train
tecbot/gorocksdb
slice.go
StringToSlice
func StringToSlice(data string) *Slice { return NewSlice(C.CString(data), C.size_t(len(data))) }
go
func StringToSlice(data string) *Slice { return NewSlice(C.CString(data), C.size_t(len(data))) }
[ "func", "StringToSlice", "(", "data", "string", ")", "*", "Slice", "{", "return", "NewSlice", "(", "C", ".", "CString", "(", "data", ")", ",", "C", ".", "size_t", "(", "len", "(", "data", ")", ")", ")", "\n", "}" ]
// StringToSlice is similar to NewSlice, but can be called with // a Go string type. This exists to make testing integration // with Gorocksdb easier.
[ "StringToSlice", "is", "similar", "to", "NewSlice", "but", "can", "be", "called", "with", "a", "Go", "string", "type", ".", "This", "exists", "to", "make", "testing", "integration", "with", "Gorocksdb", "easier", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/slice.go#L30-L32
train
tecbot/gorocksdb
slice.go
Free
func (s *Slice) Free() { if !s.freed { C.free(unsafe.Pointer(s.data)) s.freed = true } }
go
func (s *Slice) Free() { if !s.freed { C.free(unsafe.Pointer(s.data)) s.freed = true } }
[ "func", "(", "s", "*", "Slice", ")", "Free", "(", ")", "{", "if", "!", "s", ".", "freed", "{", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "s", ".", "data", ")", ")", "\n", "s", ".", "freed", "=", "true", "\n", "}", "\n", "}" ]
// Free frees the slice data.
[ "Free", "frees", "the", "slice", "data", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/slice.go#L45-L50
train
tecbot/gorocksdb
options.go
IncreaseParallelism
func (opts *Options) IncreaseParallelism(total_threads int) { C.rocksdb_options_increase_parallelism(opts.c, C.int(total_threads)) }
go
func (opts *Options) IncreaseParallelism(total_threads int) { C.rocksdb_options_increase_parallelism(opts.c, C.int(total_threads)) }
[ "func", "(", "opts", "*", "Options", ")", "IncreaseParallelism", "(", "total_threads", "int", ")", "{", "C", ".", "rocksdb_options_increase_parallelism", "(", "opts", ".", "c", ",", "C", ".", "int", "(", "total_threads", ")", ")", "\n", "}" ]
// IncreaseParallelism sets the parallelism. // // By default, RocksDB uses only one background thread for flush and // compaction. Calling this function will set it up such that total of // `total_threads` is used. Good value for `total_threads` is the number of // cores. You almost definitely want to call this function if your system is // bottlenecked by RocksDB.
[ "IncreaseParallelism", "sets", "the", "parallelism", ".", "By", "default", "RocksDB", "uses", "only", "one", "background", "thread", "for", "flush", "and", "compaction", ".", "Calling", "this", "function", "will", "set", "it", "up", "such", "that", "total", "o...
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L251-L253
train
tecbot/gorocksdb
options.go
OptimizeUniversalStyleCompaction
func (opts *Options) OptimizeUniversalStyleCompaction(memtable_memory_budget uint64) { C.rocksdb_options_optimize_universal_style_compaction(opts.c, C.uint64_t(memtable_memory_budget)) }
go
func (opts *Options) OptimizeUniversalStyleCompaction(memtable_memory_budget uint64) { C.rocksdb_options_optimize_universal_style_compaction(opts.c, C.uint64_t(memtable_memory_budget)) }
[ "func", "(", "opts", "*", "Options", ")", "OptimizeUniversalStyleCompaction", "(", "memtable_memory_budget", "uint64", ")", "{", "C", ".", "rocksdb_options_optimize_universal_style_compaction", "(", "opts", ".", "c", ",", "C", ".", "uint64_t", "(", "memtable_memory_bu...
// OptimizeUniversalStyleCompaction optimize the DB for universal compaction. // See note on OptimizeLevelStyleCompaction.
[ "OptimizeUniversalStyleCompaction", "optimize", "the", "DB", "for", "universal", "compaction", ".", "See", "note", "on", "OptimizeLevelStyleCompaction", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L296-L298
train
tecbot/gorocksdb
options.go
SetMinLevelToCompress
func (opts *Options) SetMinLevelToCompress(value int) { C.rocksdb_options_set_min_level_to_compress(opts.c, C.int(value)) }
go
func (opts *Options) SetMinLevelToCompress(value int) { C.rocksdb_options_set_min_level_to_compress(opts.c, C.int(value)) }
[ "func", "(", "opts", "*", "Options", ")", "SetMinLevelToCompress", "(", "value", "int", ")", "{", "C", ".", "rocksdb_options_set_min_level_to_compress", "(", "opts", ".", "c", ",", "C", ".", "int", "(", "value", ")", ")", "\n", "}" ]
// SetMinLevelToCompress sets the start level to use compression.
[ "SetMinLevelToCompress", "sets", "the", "start", "level", "to", "use", "compression", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L391-L393
train
tecbot/gorocksdb
options.go
SetCreateIfMissingColumnFamilies
func (opts *Options) SetCreateIfMissingColumnFamilies(value bool) { C.rocksdb_options_set_create_missing_column_families(opts.c, boolToChar(value)) }
go
func (opts *Options) SetCreateIfMissingColumnFamilies(value bool) { C.rocksdb_options_set_create_missing_column_families(opts.c, boolToChar(value)) }
[ "func", "(", "opts", "*", "Options", ")", "SetCreateIfMissingColumnFamilies", "(", "value", "bool", ")", "{", "C", ".", "rocksdb_options_set_create_missing_column_families", "(", "opts", ".", "c", ",", "boolToChar", "(", "value", ")", ")", "\n", "}" ]
// SetCreateIfMissingColumnFamilies specifies whether the column families // should be created if they are missing.
[ "SetCreateIfMissingColumnFamilies", "specifies", "whether", "the", "column", "families", "should", "be", "created", "if", "they", "are", "missing", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L1086-L1088
train
tecbot/gorocksdb
options.go
SetBlockBasedTableFactory
func (opts *Options) SetBlockBasedTableFactory(value *BlockBasedTableOptions) { opts.bbto = value C.rocksdb_options_set_block_based_table_factory(opts.c, value.c) }
go
func (opts *Options) SetBlockBasedTableFactory(value *BlockBasedTableOptions) { opts.bbto = value C.rocksdb_options_set_block_based_table_factory(opts.c, value.c) }
[ "func", "(", "opts", "*", "Options", ")", "SetBlockBasedTableFactory", "(", "value", "*", "BlockBasedTableOptions", ")", "{", "opts", ".", "bbto", "=", "value", "\n", "C", ".", "rocksdb_options_set_block_based_table_factory", "(", "opts", ".", "c", ",", "value",...
// SetBlockBasedTableFactory sets the block based table factory.
[ "SetBlockBasedTableFactory", "sets", "the", "block", "based", "table", "factory", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L1091-L1094
train
tecbot/gorocksdb
options.go
Destroy
func (opts *Options) Destroy() { C.rocksdb_options_destroy(opts.c) if opts.ccmp != nil { C.rocksdb_comparator_destroy(opts.ccmp) } if opts.cst != nil { C.rocksdb_slicetransform_destroy(opts.cst) } if opts.ccf != nil { C.rocksdb_compactionfilter_destroy(opts.ccf) } opts.c = nil opts.env = nil opts.bbto = nil }
go
func (opts *Options) Destroy() { C.rocksdb_options_destroy(opts.c) if opts.ccmp != nil { C.rocksdb_comparator_destroy(opts.ccmp) } if opts.cst != nil { C.rocksdb_slicetransform_destroy(opts.cst) } if opts.ccf != nil { C.rocksdb_compactionfilter_destroy(opts.ccf) } opts.c = nil opts.env = nil opts.bbto = nil }
[ "func", "(", "opts", "*", "Options", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_options_destroy", "(", "opts", ".", "c", ")", "\n", "if", "opts", ".", "ccmp", "!=", "nil", "{", "C", ".", "rocksdb_comparator_destroy", "(", "opts", ".", "ccmp", ...
// Destroy deallocates the Options object.
[ "Destroy", "deallocates", "the", "Options", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options.go#L1112-L1126
train
tecbot/gorocksdb
options_ingest.go
SetMoveFiles
func (opts *IngestExternalFileOptions) SetMoveFiles(flag bool) { C.rocksdb_ingestexternalfileoptions_set_move_files(opts.c, boolToChar(flag)) }
go
func (opts *IngestExternalFileOptions) SetMoveFiles(flag bool) { C.rocksdb_ingestexternalfileoptions_set_move_files(opts.c, boolToChar(flag)) }
[ "func", "(", "opts", "*", "IngestExternalFileOptions", ")", "SetMoveFiles", "(", "flag", "bool", ")", "{", "C", ".", "rocksdb_ingestexternalfileoptions_set_move_files", "(", "opts", ".", "c", ",", "boolToChar", "(", "flag", ")", ")", "\n", "}" ]
// SetMoveFiles specifies if it should move the files instead of copying them. // Default to false.
[ "SetMoveFiles", "specifies", "if", "it", "should", "move", "the", "files", "instead", "of", "copying", "them", ".", "Default", "to", "false", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_ingest.go#L23-L25
train
tecbot/gorocksdb
options_ingest.go
SetSnapshotConsistency
func (opts *IngestExternalFileOptions) SetSnapshotConsistency(flag bool) { C.rocksdb_ingestexternalfileoptions_set_snapshot_consistency(opts.c, boolToChar(flag)) }
go
func (opts *IngestExternalFileOptions) SetSnapshotConsistency(flag bool) { C.rocksdb_ingestexternalfileoptions_set_snapshot_consistency(opts.c, boolToChar(flag)) }
[ "func", "(", "opts", "*", "IngestExternalFileOptions", ")", "SetSnapshotConsistency", "(", "flag", "bool", ")", "{", "C", ".", "rocksdb_ingestexternalfileoptions_set_snapshot_consistency", "(", "opts", ".", "c", ",", "boolToChar", "(", "flag", ")", ")", "\n", "}" ...
// SetSnapshotConsistency if specifies the consistency. // If set to false, an ingested file key could appear in existing snapshots that were created before the // file was ingested. // Default to true.
[ "SetSnapshotConsistency", "if", "specifies", "the", "consistency", ".", "If", "set", "to", "false", "an", "ingested", "file", "key", "could", "appear", "in", "existing", "snapshots", "that", "were", "created", "before", "the", "file", "was", "ingested", ".", "...
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_ingest.go#L31-L33
train
tecbot/gorocksdb
options_ingest.go
Destroy
func (opts *IngestExternalFileOptions) Destroy() { C.rocksdb_ingestexternalfileoptions_destroy(opts.c) opts.c = nil }
go
func (opts *IngestExternalFileOptions) Destroy() { C.rocksdb_ingestexternalfileoptions_destroy(opts.c) opts.c = nil }
[ "func", "(", "opts", "*", "IngestExternalFileOptions", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_ingestexternalfileoptions_destroy", "(", "opts", ".", "c", ")", "\n", "opts", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the IngestExternalFileOptions object.
[ "Destroy", "deallocates", "the", "IngestExternalFileOptions", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/options_ingest.go#L62-L65
train
tecbot/gorocksdb
iterator.go
ValidForPrefix
func (iter *Iterator) ValidForPrefix(prefix []byte) bool { if C.rocksdb_iter_valid(iter.c) == 0 { return false } key := iter.Key() result := bytes.HasPrefix(key.Data(), prefix) key.Free() return result }
go
func (iter *Iterator) ValidForPrefix(prefix []byte) bool { if C.rocksdb_iter_valid(iter.c) == 0 { return false } key := iter.Key() result := bytes.HasPrefix(key.Data(), prefix) key.Free() return result }
[ "func", "(", "iter", "*", "Iterator", ")", "ValidForPrefix", "(", "prefix", "[", "]", "byte", ")", "bool", "{", "if", "C", ".", "rocksdb_iter_valid", "(", "iter", ".", "c", ")", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "key", ":=", "it...
// ValidForPrefix returns false only when an Iterator has iterated past the // first or the last key in the database or the specified prefix.
[ "ValidForPrefix", "returns", "false", "only", "when", "an", "Iterator", "has", "iterated", "past", "the", "first", "or", "the", "last", "key", "in", "the", "database", "or", "the", "specified", "prefix", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/iterator.go#L46-L55
train
tecbot/gorocksdb
iterator.go
Key
func (iter *Iterator) Key() *Slice { var cLen C.size_t cKey := C.rocksdb_iter_key(iter.c, &cLen) if cKey == nil { return nil } return &Slice{cKey, cLen, true} }
go
func (iter *Iterator) Key() *Slice { var cLen C.size_t cKey := C.rocksdb_iter_key(iter.c, &cLen) if cKey == nil { return nil } return &Slice{cKey, cLen, true} }
[ "func", "(", "iter", "*", "Iterator", ")", "Key", "(", ")", "*", "Slice", "{", "var", "cLen", "C", ".", "size_t", "\n", "cKey", ":=", "C", ".", "rocksdb_iter_key", "(", "iter", ".", "c", ",", "&", "cLen", ")", "\n", "if", "cKey", "==", "nil", "...
// Key returns the key the iterator currently holds.
[ "Key", "returns", "the", "key", "the", "iterator", "currently", "holds", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/iterator.go#L58-L65
train
tecbot/gorocksdb
iterator.go
Value
func (iter *Iterator) Value() *Slice { var cLen C.size_t cVal := C.rocksdb_iter_value(iter.c, &cLen) if cVal == nil { return nil } return &Slice{cVal, cLen, true} }
go
func (iter *Iterator) Value() *Slice { var cLen C.size_t cVal := C.rocksdb_iter_value(iter.c, &cLen) if cVal == nil { return nil } return &Slice{cVal, cLen, true} }
[ "func", "(", "iter", "*", "Iterator", ")", "Value", "(", ")", "*", "Slice", "{", "var", "cLen", "C", ".", "size_t", "\n", "cVal", ":=", "C", ".", "rocksdb_iter_value", "(", "iter", ".", "c", ",", "&", "cLen", ")", "\n", "if", "cVal", "==", "nil",...
// Value returns the value in the database the iterator currently holds.
[ "Value", "returns", "the", "value", "in", "the", "database", "the", "iterator", "currently", "holds", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/iterator.go#L68-L75
train
tecbot/gorocksdb
iterator.go
Seek
func (iter *Iterator) Seek(key []byte) { cKey := byteToChar(key) C.rocksdb_iter_seek(iter.c, cKey, C.size_t(len(key))) }
go
func (iter *Iterator) Seek(key []byte) { cKey := byteToChar(key) C.rocksdb_iter_seek(iter.c, cKey, C.size_t(len(key))) }
[ "func", "(", "iter", "*", "Iterator", ")", "Seek", "(", "key", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "C", ".", "rocksdb_iter_seek", "(", "iter", ".", "c", ",", "cKey", ",", "C", ".", "size_t", "(", "len", ...
// Seek moves the iterator to the position greater than or equal to the key.
[ "Seek", "moves", "the", "iterator", "to", "the", "position", "greater", "than", "or", "equal", "to", "the", "key", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/iterator.go#L98-L101
train
tecbot/gorocksdb
iterator.go
SeekForPrev
func (iter *Iterator) SeekForPrev(key []byte) { cKey := byteToChar(key) C.rocksdb_iter_seek_for_prev(iter.c, cKey, C.size_t(len(key))) }
go
func (iter *Iterator) SeekForPrev(key []byte) { cKey := byteToChar(key) C.rocksdb_iter_seek_for_prev(iter.c, cKey, C.size_t(len(key))) }
[ "func", "(", "iter", "*", "Iterator", ")", "SeekForPrev", "(", "key", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "C", ".", "rocksdb_iter_seek_for_prev", "(", "iter", ".", "c", ",", "cKey", ",", "C", ".", "size_t", ...
// SeekForPrev moves the iterator to the last key that less than or equal // to the target key, in contrast with Seek.
[ "SeekForPrev", "moves", "the", "iterator", "to", "the", "last", "key", "that", "less", "than", "or", "equal", "to", "the", "target", "key", "in", "contrast", "with", "Seek", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/iterator.go#L105-L108
train
tecbot/gorocksdb
write_batch.go
WriteBatchFrom
func WriteBatchFrom(data []byte) *WriteBatch { return NewNativeWriteBatch(C.rocksdb_writebatch_create_from(byteToChar(data), C.size_t(len(data)))) }
go
func WriteBatchFrom(data []byte) *WriteBatch { return NewNativeWriteBatch(C.rocksdb_writebatch_create_from(byteToChar(data), C.size_t(len(data)))) }
[ "func", "WriteBatchFrom", "(", "data", "[", "]", "byte", ")", "*", "WriteBatch", "{", "return", "NewNativeWriteBatch", "(", "C", ".", "rocksdb_writebatch_create_from", "(", "byteToChar", "(", "data", ")", ",", "C", ".", "size_t", "(", "len", "(", "data", "...
// WriteBatchFrom creates a write batch from a serialized WriteBatch.
[ "WriteBatchFrom", "creates", "a", "write", "batch", "from", "a", "serialized", "WriteBatch", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L26-L28
train
tecbot/gorocksdb
write_batch.go
Put
func (wb *WriteBatch) Put(key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_put(wb.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
go
func (wb *WriteBatch) Put(key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_put(wb.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "Put", "(", "key", ",", "value", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "cValue", ":=", "byteToChar", "(", "value", ")", "\n", "C", ".", "rocksdb_writebatch_put", "(",...
// Put queues a key-value pair.
[ "Put", "queues", "a", "key", "-", "value", "pair", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L31-L35
train
tecbot/gorocksdb
write_batch.go
PutCF
func (wb *WriteBatch) PutCF(cf *ColumnFamilyHandle, key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_put_cf(wb.c, cf.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
go
func (wb *WriteBatch) PutCF(cf *ColumnFamilyHandle, key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_put_cf(wb.c, cf.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "PutCF", "(", "cf", "*", "ColumnFamilyHandle", ",", "key", ",", "value", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "cValue", ":=", "byteToChar", "(", "value", ")", "\n", ...
// PutCF queues a key-value pair in a column family.
[ "PutCF", "queues", "a", "key", "-", "value", "pair", "in", "a", "column", "family", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L38-L42
train
tecbot/gorocksdb
write_batch.go
Merge
func (wb *WriteBatch) Merge(key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_merge(wb.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
go
func (wb *WriteBatch) Merge(key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_merge(wb.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "Merge", "(", "key", ",", "value", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "cValue", ":=", "byteToChar", "(", "value", ")", "\n", "C", ".", "rocksdb_writebatch_merge", ...
// Merge queues a merge of "value" with the existing value of "key".
[ "Merge", "queues", "a", "merge", "of", "value", "with", "the", "existing", "value", "of", "key", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L45-L49
train
tecbot/gorocksdb
write_batch.go
MergeCF
func (wb *WriteBatch) MergeCF(cf *ColumnFamilyHandle, key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_merge_cf(wb.c, cf.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
go
func (wb *WriteBatch) MergeCF(cf *ColumnFamilyHandle, key, value []byte) { cKey := byteToChar(key) cValue := byteToChar(value) C.rocksdb_writebatch_merge_cf(wb.c, cf.c, cKey, C.size_t(len(key)), cValue, C.size_t(len(value))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "MergeCF", "(", "cf", "*", "ColumnFamilyHandle", ",", "key", ",", "value", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "cValue", ":=", "byteToChar", "(", "value", ")", "\n"...
// MergeCF queues a merge of "value" with the existing value of "key" in a // column family.
[ "MergeCF", "queues", "a", "merge", "of", "value", "with", "the", "existing", "value", "of", "key", "in", "a", "column", "family", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L53-L57
train
tecbot/gorocksdb
write_batch.go
Delete
func (wb *WriteBatch) Delete(key []byte) { cKey := byteToChar(key) C.rocksdb_writebatch_delete(wb.c, cKey, C.size_t(len(key))) }
go
func (wb *WriteBatch) Delete(key []byte) { cKey := byteToChar(key) C.rocksdb_writebatch_delete(wb.c, cKey, C.size_t(len(key))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "Delete", "(", "key", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "C", ".", "rocksdb_writebatch_delete", "(", "wb", ".", "c", ",", "cKey", ",", "C", ".", "size_t", "(", ...
// Delete queues a deletion of the data at key.
[ "Delete", "queues", "a", "deletion", "of", "the", "data", "at", "key", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L60-L63
train
tecbot/gorocksdb
write_batch.go
DeleteCF
func (wb *WriteBatch) DeleteCF(cf *ColumnFamilyHandle, key []byte) { cKey := byteToChar(key) C.rocksdb_writebatch_delete_cf(wb.c, cf.c, cKey, C.size_t(len(key))) }
go
func (wb *WriteBatch) DeleteCF(cf *ColumnFamilyHandle, key []byte) { cKey := byteToChar(key) C.rocksdb_writebatch_delete_cf(wb.c, cf.c, cKey, C.size_t(len(key))) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "DeleteCF", "(", "cf", "*", "ColumnFamilyHandle", ",", "key", "[", "]", "byte", ")", "{", "cKey", ":=", "byteToChar", "(", "key", ")", "\n", "C", ".", "rocksdb_writebatch_delete_cf", "(", "wb", ".", "c", ",", ...
// DeleteCF queues a deletion of the data at key in a column family.
[ "DeleteCF", "queues", "a", "deletion", "of", "the", "data", "at", "key", "in", "a", "column", "family", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L66-L69
train
tecbot/gorocksdb
write_batch.go
Data
func (wb *WriteBatch) Data() []byte { var cSize C.size_t cValue := C.rocksdb_writebatch_data(wb.c, &cSize) return charToByte(cValue, cSize) }
go
func (wb *WriteBatch) Data() []byte { var cSize C.size_t cValue := C.rocksdb_writebatch_data(wb.c, &cSize) return charToByte(cValue, cSize) }
[ "func", "(", "wb", "*", "WriteBatch", ")", "Data", "(", ")", "[", "]", "byte", "{", "var", "cSize", "C", ".", "size_t", "\n", "cValue", ":=", "C", ".", "rocksdb_writebatch_data", "(", "wb", ".", "c", ",", "&", "cSize", ")", "\n", "return", "charToB...
// Data returns the serialized version of this batch.
[ "Data", "returns", "the", "serialized", "version", "of", "this", "batch", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L72-L76
train
tecbot/gorocksdb
write_batch.go
NewIterator
func (wb *WriteBatch) NewIterator() *WriteBatchIterator { data := wb.Data() if len(data) < 8+4 { return &WriteBatchIterator{} } return &WriteBatchIterator{data: data[12:]} }
go
func (wb *WriteBatch) NewIterator() *WriteBatchIterator { data := wb.Data() if len(data) < 8+4 { return &WriteBatchIterator{} } return &WriteBatchIterator{data: data[12:]} }
[ "func", "(", "wb", "*", "WriteBatch", ")", "NewIterator", "(", ")", "*", "WriteBatchIterator", "{", "data", ":=", "wb", ".", "Data", "(", ")", "\n", "if", "len", "(", "data", ")", "<", "8", "+", "4", "{", "return", "&", "WriteBatchIterator", "{", "...
// NewIterator returns a iterator to iterate over the records in the batch.
[ "NewIterator", "returns", "a", "iterator", "to", "iterate", "over", "the", "records", "in", "the", "batch", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L84-L90
train
tecbot/gorocksdb
write_batch.go
Destroy
func (wb *WriteBatch) Destroy() { C.rocksdb_writebatch_destroy(wb.c) wb.c = nil }
go
func (wb *WriteBatch) Destroy() { C.rocksdb_writebatch_destroy(wb.c) wb.c = nil }
[ "func", "(", "wb", "*", "WriteBatch", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_writebatch_destroy", "(", "wb", ".", "c", ")", "\n", "wb", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the WriteBatch object.
[ "Destroy", "deallocates", "the", "WriteBatch", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L98-L101
train
tecbot/gorocksdb
write_batch.go
Next
func (iter *WriteBatchIterator) Next() bool { if iter.err != nil || len(iter.data) == 0 { return false } // reset the current record iter.record.CF = 0 iter.record.Key = nil iter.record.Value = nil // parse the record type iter.record.Type = iter.decodeRecType() switch iter.record.Type { case WriteBatchDeletionRecord, WriteBatchSingleDeletionRecord: iter.record.Key = iter.decodeSlice() case WriteBatchCFDeletionRecord, WriteBatchCFSingleDeletionRecord: iter.record.CF = int(iter.decodeVarint()) if iter.err == nil { iter.record.Key = iter.decodeSlice() } case WriteBatchValueRecord, WriteBatchMergeRecord, WriteBatchRangeDeletion, WriteBatchBlobIndex: iter.record.Key = iter.decodeSlice() if iter.err == nil { iter.record.Value = iter.decodeSlice() } case WriteBatchCFValueRecord, WriteBatchCFRangeDeletion, WriteBatchCFMergeRecord, WriteBatchCFBlobIndex: iter.record.CF = int(iter.decodeVarint()) if iter.err == nil { iter.record.Key = iter.decodeSlice() } if iter.err == nil { iter.record.Value = iter.decodeSlice() } case WriteBatchLogDataRecord: iter.record.Value = iter.decodeSlice() case WriteBatchNoopRecord, WriteBatchBeginPrepareXIDRecord, WriteBatchBeginPersistedPrepareXIDRecord: case WriteBatchEndPrepareXIDRecord, WriteBatchCommitXIDRecord, WriteBatchRollbackXIDRecord: iter.record.Value = iter.decodeSlice() default: iter.err = errors.New("unsupported wal record type") } return iter.err == nil }
go
func (iter *WriteBatchIterator) Next() bool { if iter.err != nil || len(iter.data) == 0 { return false } // reset the current record iter.record.CF = 0 iter.record.Key = nil iter.record.Value = nil // parse the record type iter.record.Type = iter.decodeRecType() switch iter.record.Type { case WriteBatchDeletionRecord, WriteBatchSingleDeletionRecord: iter.record.Key = iter.decodeSlice() case WriteBatchCFDeletionRecord, WriteBatchCFSingleDeletionRecord: iter.record.CF = int(iter.decodeVarint()) if iter.err == nil { iter.record.Key = iter.decodeSlice() } case WriteBatchValueRecord, WriteBatchMergeRecord, WriteBatchRangeDeletion, WriteBatchBlobIndex: iter.record.Key = iter.decodeSlice() if iter.err == nil { iter.record.Value = iter.decodeSlice() } case WriteBatchCFValueRecord, WriteBatchCFRangeDeletion, WriteBatchCFMergeRecord, WriteBatchCFBlobIndex: iter.record.CF = int(iter.decodeVarint()) if iter.err == nil { iter.record.Key = iter.decodeSlice() } if iter.err == nil { iter.record.Value = iter.decodeSlice() } case WriteBatchLogDataRecord: iter.record.Value = iter.decodeSlice() case WriteBatchNoopRecord, WriteBatchBeginPrepareXIDRecord, WriteBatchBeginPersistedPrepareXIDRecord: case WriteBatchEndPrepareXIDRecord, WriteBatchCommitXIDRecord, WriteBatchRollbackXIDRecord: iter.record.Value = iter.decodeSlice() default: iter.err = errors.New("unsupported wal record type") } return iter.err == nil }
[ "func", "(", "iter", "*", "WriteBatchIterator", ")", "Next", "(", ")", "bool", "{", "if", "iter", ".", "err", "!=", "nil", "||", "len", "(", "iter", ".", "data", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "// reset the current record", ...
// Next returns the next record. // Returns false if no further record exists.
[ "Next", "returns", "the", "next", "record", ".", "Returns", "false", "if", "no", "further", "record", "exists", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/write_batch.go#L147-L209
train
tecbot/gorocksdb
slice_transform.go
NewFixedPrefixTransform
func NewFixedPrefixTransform(prefixLen int) SliceTransform { return NewNativeSliceTransform(C.rocksdb_slicetransform_create_fixed_prefix(C.size_t(prefixLen))) }
go
func NewFixedPrefixTransform(prefixLen int) SliceTransform { return NewNativeSliceTransform(C.rocksdb_slicetransform_create_fixed_prefix(C.size_t(prefixLen))) }
[ "func", "NewFixedPrefixTransform", "(", "prefixLen", "int", ")", "SliceTransform", "{", "return", "NewNativeSliceTransform", "(", "C", ".", "rocksdb_slicetransform_create_fixed_prefix", "(", "C", ".", "size_t", "(", "prefixLen", ")", ")", ")", "\n", "}" ]
// NewFixedPrefixTransform creates a new fixed prefix transform.
[ "NewFixedPrefixTransform", "creates", "a", "new", "fixed", "prefix", "transform", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/slice_transform.go#L22-L24
train
tecbot/gorocksdb
cow.go
NewCOWList
func NewCOWList() *COWList { var list []interface{} v := &atomic.Value{} v.Store(list) return &COWList{v: v, mu: new(sync.Mutex)} }
go
func NewCOWList() *COWList { var list []interface{} v := &atomic.Value{} v.Store(list) return &COWList{v: v, mu: new(sync.Mutex)} }
[ "func", "NewCOWList", "(", ")", "*", "COWList", "{", "var", "list", "[", "]", "interface", "{", "}", "\n", "v", ":=", "&", "atomic", ".", "Value", "{", "}", "\n", "v", ".", "Store", "(", "list", ")", "\n", "return", "&", "COWList", "{", "v", ":...
// NewCOWList creates a new COWList.
[ "NewCOWList", "creates", "a", "new", "COWList", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/cow.go#L18-L23
train
tecbot/gorocksdb
cow.go
Append
func (c *COWList) Append(i interface{}) int { c.mu.Lock() defer c.mu.Unlock() list := c.v.Load().([]interface{}) newLen := len(list) + 1 newList := make([]interface{}, newLen) copy(newList, list) newList[newLen-1] = i c.v.Store(newList) return newLen - 1 }
go
func (c *COWList) Append(i interface{}) int { c.mu.Lock() defer c.mu.Unlock() list := c.v.Load().([]interface{}) newLen := len(list) + 1 newList := make([]interface{}, newLen) copy(newList, list) newList[newLen-1] = i c.v.Store(newList) return newLen - 1 }
[ "func", "(", "c", "*", "COWList", ")", "Append", "(", "i", "interface", "{", "}", ")", "int", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "list", ":=", "c", ".", "v", ".", "Load"...
// Append appends an item to the COWList and returns the index for that item.
[ "Append", "appends", "an", "item", "to", "the", "COWList", "and", "returns", "the", "index", "for", "that", "item", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/cow.go#L26-L36
train
tecbot/gorocksdb
cow.go
Get
func (c *COWList) Get(index int) interface{} { list := c.v.Load().([]interface{}) return list[index] }
go
func (c *COWList) Get(index int) interface{} { list := c.v.Load().([]interface{}) return list[index] }
[ "func", "(", "c", "*", "COWList", ")", "Get", "(", "index", "int", ")", "interface", "{", "}", "{", "list", ":=", "c", ".", "v", ".", "Load", "(", ")", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "return", "list", "[", "index", "]",...
// Get gets the item at index.
[ "Get", "gets", "the", "item", "at", "index", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/cow.go#L39-L42
train
tecbot/gorocksdb
env.go
SetHighPriorityBackgroundThreads
func (env *Env) SetHighPriorityBackgroundThreads(n int) { C.rocksdb_env_set_high_priority_background_threads(env.c, C.int(n)) }
go
func (env *Env) SetHighPriorityBackgroundThreads(n int) { C.rocksdb_env_set_high_priority_background_threads(env.c, C.int(n)) }
[ "func", "(", "env", "*", "Env", ")", "SetHighPriorityBackgroundThreads", "(", "n", "int", ")", "{", "C", ".", "rocksdb_env_set_high_priority_background_threads", "(", "env", ".", "c", ",", "C", ".", "int", "(", "n", ")", ")", "\n", "}" ]
// SetHighPriorityBackgroundThreads sets the size of the high priority // thread pool that can be used to prevent compactions from stalling // memtable flushes.
[ "SetHighPriorityBackgroundThreads", "sets", "the", "size", "of", "the", "high", "priority", "thread", "pool", "that", "can", "be", "used", "to", "prevent", "compactions", "from", "stalling", "memtable", "flushes", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/env.go#L32-L34
train
tecbot/gorocksdb
env.go
Destroy
func (env *Env) Destroy() { C.rocksdb_env_destroy(env.c) env.c = nil }
go
func (env *Env) Destroy() { C.rocksdb_env_destroy(env.c) env.c = nil }
[ "func", "(", "env", "*", "Env", ")", "Destroy", "(", ")", "{", "C", ".", "rocksdb_env_destroy", "(", "env", ".", "c", ")", "\n", "env", ".", "c", "=", "nil", "\n", "}" ]
// Destroy deallocates the Env object.
[ "Destroy", "deallocates", "the", "Env", "object", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/env.go#L37-L40
train
tecbot/gorocksdb
db.go
OpenDb
func OpenDb(opts *Options, name string) (*DB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_open(opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &DB{ name: name, c: db, opts: opts, }, nil }
go
func OpenDb(opts *Options, name string) (*DB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_open(opts.c, cName, &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &DB{ name: name, c: db, opts: opts, }, nil }
[ "func", "OpenDb", "(", "opts", "*", "Options", ",", "name", "string", ")", "(", "*", "DB", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cName", "=", "C", ".", "CString", "(", "name", ")", "\n", ")", "\n", "defer", ...
// OpenDb opens a database with the specified options.
[ "OpenDb", "opens", "a", "database", "with", "the", "specified", "options", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L27-L43
train
tecbot/gorocksdb
db.go
OpenDbForReadOnly
func OpenDbForReadOnly(opts *Options, name string, errorIfLogFileExist bool) (*DB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_open_for_read_only(opts.c, cName, boolToChar(errorIfLogFileExist), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &DB{ name: name, c: db, opts: opts, }, nil }
go
func OpenDbForReadOnly(opts *Options, name string, errorIfLogFileExist bool) (*DB, error) { var ( cErr *C.char cName = C.CString(name) ) defer C.free(unsafe.Pointer(cName)) db := C.rocksdb_open_for_read_only(opts.c, cName, boolToChar(errorIfLogFileExist), &cErr) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, errors.New(C.GoString(cErr)) } return &DB{ name: name, c: db, opts: opts, }, nil }
[ "func", "OpenDbForReadOnly", "(", "opts", "*", "Options", ",", "name", "string", ",", "errorIfLogFileExist", "bool", ")", "(", "*", "DB", ",", "error", ")", "{", "var", "(", "cErr", "*", "C", ".", "char", "\n", "cName", "=", "C", ".", "CString", "(",...
// OpenDbForReadOnly opens a database with the specified options for readonly usage.
[ "OpenDbForReadOnly", "opens", "a", "database", "with", "the", "specified", "options", "for", "readonly", "usage", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L46-L62
train
tecbot/gorocksdb
db.go
OpenDbColumnFamilies
func OpenDbColumnFamilies( opts *Options, name string, cfNames []string, cfOpts []*Options, ) (*DB, []*ColumnFamilyHandle, error) { numColumnFamilies := len(cfNames) if numColumnFamilies != len(cfOpts) { return nil, nil, errors.New("must provide the same number of column family names and options") } cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) cNames := make([]*C.char, numColumnFamilies) for i, s := range cfNames { cNames[i] = C.CString(s) } defer func() { for _, s := range cNames { C.free(unsafe.Pointer(s)) } }() cOpts := make([]*C.rocksdb_options_t, numColumnFamilies) for i, o := range cfOpts { cOpts[i] = o.c } cHandles := make([]*C.rocksdb_column_family_handle_t, numColumnFamilies) var cErr *C.char db := C.rocksdb_open_column_families( opts.c, cName, C.int(numColumnFamilies), &cNames[0], &cOpts[0], &cHandles[0], &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, nil, errors.New(C.GoString(cErr)) } cfHandles := make([]*ColumnFamilyHandle, numColumnFamilies) for i, c := range cHandles { cfHandles[i] = NewNativeColumnFamilyHandle(c) } return &DB{ name: name, c: db, opts: opts, }, cfHandles, nil }
go
func OpenDbColumnFamilies( opts *Options, name string, cfNames []string, cfOpts []*Options, ) (*DB, []*ColumnFamilyHandle, error) { numColumnFamilies := len(cfNames) if numColumnFamilies != len(cfOpts) { return nil, nil, errors.New("must provide the same number of column family names and options") } cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) cNames := make([]*C.char, numColumnFamilies) for i, s := range cfNames { cNames[i] = C.CString(s) } defer func() { for _, s := range cNames { C.free(unsafe.Pointer(s)) } }() cOpts := make([]*C.rocksdb_options_t, numColumnFamilies) for i, o := range cfOpts { cOpts[i] = o.c } cHandles := make([]*C.rocksdb_column_family_handle_t, numColumnFamilies) var cErr *C.char db := C.rocksdb_open_column_families( opts.c, cName, C.int(numColumnFamilies), &cNames[0], &cOpts[0], &cHandles[0], &cErr, ) if cErr != nil { defer C.free(unsafe.Pointer(cErr)) return nil, nil, errors.New(C.GoString(cErr)) } cfHandles := make([]*ColumnFamilyHandle, numColumnFamilies) for i, c := range cHandles { cfHandles[i] = NewNativeColumnFamilyHandle(c) } return &DB{ name: name, c: db, opts: opts, }, cfHandles, nil }
[ "func", "OpenDbColumnFamilies", "(", "opts", "*", "Options", ",", "name", "string", ",", "cfNames", "[", "]", "string", ",", "cfOpts", "[", "]", "*", "Options", ",", ")", "(", "*", "DB", ",", "[", "]", "*", "ColumnFamilyHandle", ",", "error", ")", "{...
// OpenDbColumnFamilies opens a database with the specified column families.
[ "OpenDbColumnFamilies", "opens", "a", "database", "with", "the", "specified", "column", "families", "." ]
8752a943348155073ae407010e2b75c40480271a
https://github.com/tecbot/gorocksdb/blob/8752a943348155073ae407010e2b75c40480271a/db.go#L65-L121
train