id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
123,300
mweagle/Sparta
aws/step/glue.go
NewGlueState
func NewGlueState(stateName string, parameters GlueParameters) *GlueState { sns := &GlueState{ BaseTask: BaseTask{ baseInnerState: baseInnerState{ name: stateName, id: rand.Int63(), }, }, parameters: parameters, } return sns }
go
func NewGlueState(stateName string, parameters GlueParameters) *GlueState { sns := &GlueState{ BaseTask: BaseTask{ baseInnerState: baseInnerState{ name: stateName, id: rand.Int63(), }, }, parameters: parameters, } return sns }
[ "func", "NewGlueState", "(", "stateName", "string", ",", "parameters", "GlueParameters", ")", "*", "GlueState", "{", "sns", ":=", "&", "GlueState", "{", "BaseTask", ":", "BaseTask", "{", "baseInnerState", ":", "baseInnerState", "{", "name", ":", "stateName", "...
// NewGlueState returns an initialized GlueState
[ "NewGlueState", "returns", "an", "initialized", "GlueState" ]
a646ce10a6728e988448dc3f6f79cd3322854c61
https://github.com/mweagle/Sparta/blob/a646ce10a6728e988448dc3f6f79cd3322854c61/aws/step/glue.go#L37-L50
123,301
mwitkow/go-conntrack
listener_wrapper.go
TrackWithTcpKeepAlive
func TrackWithTcpKeepAlive(keepalive time.Duration) listenerOpt { return func(opts *listenerOpts) { opts.tcpKeepAlive = keepalive } }
go
func TrackWithTcpKeepAlive(keepalive time.Duration) listenerOpt { return func(opts *listenerOpts) { opts.tcpKeepAlive = keepalive } }
[ "func", "TrackWithTcpKeepAlive", "(", "keepalive", "time", ".", "Duration", ")", "listenerOpt", "{", "return", "func", "(", "opts", "*", "listenerOpts", ")", "{", "opts", ".", "tcpKeepAlive", "=", "keepalive", "\n", "}", "\n", "}" ]
// TrackWithTcpKeepAlive makes sure that any `net.TCPConn` that get accepted have a keep-alive. // This is useful for HTTP servers in order for, for example laptops, to not use up resources on the // server while they don't utilise their connection. // A value of 0 disables it.
[ "TrackWithTcpKeepAlive", "makes", "sure", "that", "any", "net", ".", "TCPConn", "that", "get", "accepted", "have", "a", "keep", "-", "alive", ".", "This", "is", "useful", "for", "HTTP", "servers", "in", "order", "for", "for", "example", "laptops", "to", "n...
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/listener_wrapper.go#L54-L58
123,302
mwitkow/go-conntrack
listener_wrapper.go
NewListener
func NewListener(inner net.Listener, optFuncs ...listenerOpt) net.Listener { opts := &listenerOpts{ name: defaultName, monitoring: true, tracing: false, } for _, f := range optFuncs { f(opts) } if opts.monitoring { preRegisterListenerMetrics(opts.name) } return &connTrackListener{ Listener: ...
go
func NewListener(inner net.Listener, optFuncs ...listenerOpt) net.Listener { opts := &listenerOpts{ name: defaultName, monitoring: true, tracing: false, } for _, f := range optFuncs { f(opts) } if opts.monitoring { preRegisterListenerMetrics(opts.name) } return &connTrackListener{ Listener: ...
[ "func", "NewListener", "(", "inner", "net", ".", "Listener", ",", "optFuncs", "...", "listenerOpt", ")", "net", ".", "Listener", "{", "opts", ":=", "&", "listenerOpts", "{", "name", ":", "defaultName", ",", "monitoring", ":", "true", ",", "tracing", ":", ...
// NewListener returns the given listener wrapped in connection tracking listener.
[ "NewListener", "returns", "the", "given", "listener", "wrapped", "in", "connection", "tracking", "listener", "." ]
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/listener_wrapper.go#L66-L82
123,303
mwitkow/go-conntrack
connhelpers/tls.go
TlsConfigWithHttp2Enabled
func TlsConfigWithHttp2Enabled(config *tls.Config) (*tls.Config, error) { // mostly based on http2 code in the standards library. if config.CipherSuites != nil { // If they already provided a CipherSuite list, return // an error if it has a bad order or is missing // ECDHE_RSA_WITH_AES_128_GCM_SHA256. const r...
go
func TlsConfigWithHttp2Enabled(config *tls.Config) (*tls.Config, error) { // mostly based on http2 code in the standards library. if config.CipherSuites != nil { // If they already provided a CipherSuite list, return // an error if it has a bad order or is missing // ECDHE_RSA_WITH_AES_128_GCM_SHA256. const r...
[ "func", "TlsConfigWithHttp2Enabled", "(", "config", "*", "tls", ".", "Config", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "// mostly based on http2 code in the standards library.", "if", "config", ".", "CipherSuites", "!=", "nil", "{", "// If the...
// TlsConfigWithHttp2Enabled makes it easy to configure the given `tls.Config` to prefer H2 connections. // This is useful if you can't use `http.ListenAndServerTLS` when using a custom `net.Listener`.
[ "TlsConfigWithHttp2Enabled", "makes", "it", "easy", "to", "configure", "the", "given", "tls", ".", "Config", "to", "prefer", "H2", "connections", ".", "This", "is", "useful", "if", "you", "can", "t", "use", "http", ".", "ListenAndServerTLS", "when", "using", ...
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/connhelpers/tls.go#L26-L60
123,304
mwitkow/go-conntrack
dialer_reporter.go
PreRegisterDialerMetrics
func PreRegisterDialerMetrics(dialerName string) { dialerAttemptedTotal.WithLabelValues(dialerName) dialerConnEstablishedTotal.WithLabelValues(dialerName) for _, reason := range []failureReason{failedTimeout, failedResolution, failedConnRefused, failedUnknown} { dialerConnFailedTotal.WithLabelValues(dialerName, st...
go
func PreRegisterDialerMetrics(dialerName string) { dialerAttemptedTotal.WithLabelValues(dialerName) dialerConnEstablishedTotal.WithLabelValues(dialerName) for _, reason := range []failureReason{failedTimeout, failedResolution, failedConnRefused, failedUnknown} { dialerConnFailedTotal.WithLabelValues(dialerName, st...
[ "func", "PreRegisterDialerMetrics", "(", "dialerName", "string", ")", "{", "dialerAttemptedTotal", ".", "WithLabelValues", "(", "dialerName", ")", "\n", "dialerConnEstablishedTotal", ".", "WithLabelValues", "(", "dialerName", ")", "\n", "for", "_", ",", "reason", ":...
// preRegisterDialerMetrics pre-populates Prometheus labels for the given dialer name, to avoid Prometheus missing labels issue.
[ "preRegisterDialerMetrics", "pre", "-", "populates", "Prometheus", "labels", "for", "the", "given", "dialer", "name", "to", "avoid", "Prometheus", "missing", "labels", "issue", "." ]
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/dialer_reporter.go#L66-L73
123,305
mwitkow/go-conntrack
dialer_wrapper.go
DialNameFromContext
func DialNameFromContext(ctx context.Context) string { val, ok := ctx.Value(dialerNameKey).(string) if !ok { return "" } return val }
go
func DialNameFromContext(ctx context.Context) string { val, ok := ctx.Value(dialerNameKey).(string) if !ok { return "" } return val }
[ "func", "DialNameFromContext", "(", "ctx", "context", ".", "Context", ")", "string", "{", "val", ",", "ok", ":=", "ctx", ".", "Value", "(", "dialerNameKey", ")", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", ...
// DialNameFromContext returns the name of the dialer from the context of the DialContext func, if any.
[ "DialNameFromContext", "returns", "the", "name", "of", "the", "dialer", "from", "the", "context", "of", "the", "DialContext", "func", "if", "any", "." ]
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/dialer_wrapper.go#L66-L72
123,306
mwitkow/go-conntrack
dialer_wrapper.go
DialNameToContext
func DialNameToContext(ctx context.Context, dialerName string) context.Context { return context.WithValue(ctx, dialerNameKey, dialerName) }
go
func DialNameToContext(ctx context.Context, dialerName string) context.Context { return context.WithValue(ctx, dialerNameKey, dialerName) }
[ "func", "DialNameToContext", "(", "ctx", "context", ".", "Context", ",", "dialerName", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "dialerNameKey", ",", "dialerName", ")", "\n", "}" ]
// DialNameToContext returns a context that will contain a dialer name override.
[ "DialNameToContext", "returns", "a", "context", "that", "will", "contain", "a", "dialer", "name", "override", "." ]
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/dialer_wrapper.go#L75-L77
123,307
mwitkow/go-conntrack
dialer_wrapper.go
NewDialContextFunc
func NewDialContextFunc(optFuncs ...dialerOpt) func(context.Context, string, string) (net.Conn, error) { opts := &dialerOpts{name: defaultName, monitoring: true, parentDialContextFunc: (&net.Dialer{}).DialContext} for _, f := range optFuncs { f(opts) } if opts.monitoring { PreRegisterDialerMetrics(opts.name) }...
go
func NewDialContextFunc(optFuncs ...dialerOpt) func(context.Context, string, string) (net.Conn, error) { opts := &dialerOpts{name: defaultName, monitoring: true, parentDialContextFunc: (&net.Dialer{}).DialContext} for _, f := range optFuncs { f(opts) } if opts.monitoring { PreRegisterDialerMetrics(opts.name) }...
[ "func", "NewDialContextFunc", "(", "optFuncs", "...", "dialerOpt", ")", "func", "(", "context", ".", "Context", ",", "string", ",", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "opts", ":=", "&", "dialerOpts", "{", "name", ":", "defa...
// NewDialContextFunc returns a `DialContext` function that tracks outbound connections. // The signature is compatible with `http.Tranport.DialContext` and is meant to be used there.
[ "NewDialContextFunc", "returns", "a", "DialContext", "function", "that", "tracks", "outbound", "connections", ".", "The", "signature", "is", "compatible", "with", "http", ".", "Tranport", ".", "DialContext", "and", "is", "meant", "to", "be", "used", "there", "."...
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/dialer_wrapper.go#L81-L96
123,308
mwitkow/go-conntrack
dialer_wrapper.go
NewDialFunc
func NewDialFunc(optFuncs ...dialerOpt) func(string, string) (net.Conn, error) { dialContextFunc := NewDialContextFunc(optFuncs...) return func(network string, addr string) (net.Conn, error) { return dialContextFunc(context.TODO(), network, addr) } }
go
func NewDialFunc(optFuncs ...dialerOpt) func(string, string) (net.Conn, error) { dialContextFunc := NewDialContextFunc(optFuncs...) return func(network string, addr string) (net.Conn, error) { return dialContextFunc(context.TODO(), network, addr) } }
[ "func", "NewDialFunc", "(", "optFuncs", "...", "dialerOpt", ")", "func", "(", "string", ",", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "dialContextFunc", ":=", "NewDialContextFunc", "(", "optFuncs", "...", ")", "\n", "return", "func",...
// NewDialFunc returns a `Dial` function that tracks outbound connections. // The signature is compatible with `http.Tranport.Dial` and is meant to be used there for Go < 1.7.
[ "NewDialFunc", "returns", "a", "Dial", "function", "that", "tracks", "outbound", "connections", ".", "The", "signature", "is", "compatible", "with", "http", ".", "Tranport", ".", "Dial", "and", "is", "meant", "to", "be", "used", "there", "for", "Go", "<", ...
cc309e4a22231782e8893f3c35ced0967807a33e
https://github.com/mwitkow/go-conntrack/blob/cc309e4a22231782e8893f3c35ced0967807a33e/dialer_wrapper.go#L100-L105
123,309
lox/httpcache
cache.go
NewVFSCache
func NewVFSCache(fs vfs.VFS) Cache { return &cache{fs: fs, stale: map[string]time.Time{}} }
go
func NewVFSCache(fs vfs.VFS) Cache { return &cache{fs: fs, stale: map[string]time.Time{}} }
[ "func", "NewVFSCache", "(", "fs", "vfs", ".", "VFS", ")", "Cache", "{", "return", "&", "cache", "{", "fs", ":", "fs", ",", "stale", ":", "map", "[", "string", "]", "time", ".", "Time", "{", "}", "}", "\n", "}" ]
// NewCache returns a cache backend off the provided VFS
[ "NewCache", "returns", "a", "cache", "backend", "off", "the", "provided", "VFS" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/cache.go#L53-L55
123,310
lox/httpcache
cache.go
NewDiskCache
func NewDiskCache(dir string) (Cache, error) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, err } fs, err := vfs.FS(dir) if err != nil { return nil, err } chfs, err := vfs.Chroot("/", fs) if err != nil { return nil, err } return NewVFSCache(chfs), nil }
go
func NewDiskCache(dir string) (Cache, error) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, err } fs, err := vfs.FS(dir) if err != nil { return nil, err } chfs, err := vfs.Chroot("/", fs) if err != nil { return nil, err } return NewVFSCache(chfs), nil }
[ "func", "NewDiskCache", "(", "dir", "string", ")", "(", "Cache", ",", "error", ")", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "dir", ",", "0777", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "fs", "...
// NewDiskCache returns a disk-backed cache
[ "NewDiskCache", "returns", "a", "disk", "-", "backed", "cache" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/cache.go#L63-L76
123,311
lox/httpcache
cache.go
Header
func (c *cache) Header(key string) (Header, error) { path := headerPrefix + formatPrefix + hashKey(key) f, err := c.fs.Open(path) if err != nil { if vfs.IsNotExist(err) { return Header{}, ErrNotFoundInCache } return Header{}, err } return readHeaders(bufio.NewReader(f)) }
go
func (c *cache) Header(key string) (Header, error) { path := headerPrefix + formatPrefix + hashKey(key) f, err := c.fs.Open(path) if err != nil { if vfs.IsNotExist(err) { return Header{}, ErrNotFoundInCache } return Header{}, err } return readHeaders(bufio.NewReader(f)) }
[ "func", "(", "c", "*", "cache", ")", "Header", "(", "key", "string", ")", "(", "Header", ",", "error", ")", "{", "path", ":=", "headerPrefix", "+", "formatPrefix", "+", "hashKey", "(", "key", ")", "\n", "f", ",", "err", ":=", "c", ".", "fs", ".",...
// Retrieve the Status and Headers for a given key path
[ "Retrieve", "the", "Status", "and", "Headers", "for", "a", "given", "key", "path" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/cache.go#L94-L105
123,312
lox/httpcache
cache.go
Store
func (c *cache) Store(res *Resource, keys ...string) error { var buf = &bytes.Buffer{} if length, err := strconv.ParseInt(res.Header().Get("Content-Length"), 10, 64); err == nil { if _, err = io.CopyN(buf, res, length); err != nil { return err } } else if _, err = io.Copy(buf, res); err != nil { return err...
go
func (c *cache) Store(res *Resource, keys ...string) error { var buf = &bytes.Buffer{} if length, err := strconv.ParseInt(res.Header().Get("Content-Length"), 10, 64); err == nil { if _, err = io.CopyN(buf, res, length); err != nil { return err } } else if _, err = io.Copy(buf, res); err != nil { return err...
[ "func", "(", "c", "*", "cache", ")", "Store", "(", "res", "*", "Resource", ",", "keys", "...", "string", ")", "error", "{", "var", "buf", "=", "&", "bytes", ".", "Buffer", "{", "}", "\n\n", "if", "length", ",", "err", ":=", "strconv", ".", "Parse...
// Store a resource against a number of keys
[ "Store", "a", "resource", "against", "a", "number", "of", "keys" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/cache.go#L108-L132
123,313
lox/httpcache
cache.go
Retrieve
func (c *cache) Retrieve(key string) (*Resource, error) { f, err := c.fs.Open(bodyPrefix + formatPrefix + hashKey(key)) if err != nil { if vfs.IsNotExist(err) { return nil, ErrNotFoundInCache } return nil, err } h, err := c.Header(key) if err != nil { if vfs.IsNotExist(err) { return nil, ErrNotFoundI...
go
func (c *cache) Retrieve(key string) (*Resource, error) { f, err := c.fs.Open(bodyPrefix + formatPrefix + hashKey(key)) if err != nil { if vfs.IsNotExist(err) { return nil, ErrNotFoundInCache } return nil, err } h, err := c.Header(key) if err != nil { if vfs.IsNotExist(err) { return nil, ErrNotFoundI...
[ "func", "(", "c", "*", "cache", ")", "Retrieve", "(", "key", "string", ")", "(", "*", "Resource", ",", "error", ")", "{", "f", ",", "err", ":=", "c", ".", "fs", ".", "Open", "(", "bodyPrefix", "+", "formatPrefix", "+", "hashKey", "(", "key", ")",...
// Retrieve returns a cached Resource for the given key
[ "Retrieve", "returns", "a", "cached", "Resource", "for", "the", "given", "key" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/cache.go#L153-L176
123,314
lox/httpcache
handler.go
freshness
func (h *Handler) freshness(res *Resource, r *cacheRequest) (time.Duration, error) { maxAge, err := res.MaxAge(h.Shared) if err != nil { return time.Duration(0), err } if r.CacheControl.Has("max-age") { reqMaxAge, err := r.CacheControl.Duration("max-age") if err != nil { return time.Duration(0), err } ...
go
func (h *Handler) freshness(res *Resource, r *cacheRequest) (time.Duration, error) { maxAge, err := res.MaxAge(h.Shared) if err != nil { return time.Duration(0), err } if r.CacheControl.Has("max-age") { reqMaxAge, err := r.CacheControl.Duration("max-age") if err != nil { return time.Duration(0), err } ...
[ "func", "(", "h", "*", "Handler", ")", "freshness", "(", "res", "*", "Resource", ",", "r", "*", "cacheRequest", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "maxAge", ",", "err", ":=", "res", ".", "MaxAge", "(", "h", ".", "Shared", ...
// freshness returns the duration that a requested resource will be fresh for
[ "freshness", "returns", "the", "duration", "that", "a", "requested", "resource", "will", "be", "fresh", "for" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/handler.go#L131-L164
123,315
lox/httpcache
handler.go
pipeUpstream
func (h *Handler) pipeUpstream(w http.ResponseWriter, r *cacheRequest) { rw := newResponseStreamer(w) rdr, err := rw.Stream.NextReader() if err != nil { debugf("error creating next stream reader: %v", err) w.Header().Set(CacheHeader, "SKIP") h.upstream.ServeHTTP(w, r.Request) return } defer rdr.Close() d...
go
func (h *Handler) pipeUpstream(w http.ResponseWriter, r *cacheRequest) { rw := newResponseStreamer(w) rdr, err := rw.Stream.NextReader() if err != nil { debugf("error creating next stream reader: %v", err) w.Header().Set(CacheHeader, "SKIP") h.upstream.ServeHTTP(w, r.Request) return } defer rdr.Close() d...
[ "func", "(", "h", "*", "Handler", ")", "pipeUpstream", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "cacheRequest", ")", "{", "rw", ":=", "newResponseStreamer", "(", "w", ")", "\n", "rdr", ",", "err", ":=", "rw", ".", "Stream", ".", "NextR...
// pipeUpstream makes the request via the upstream handler, the response is not stored or modified
[ "pipeUpstream", "makes", "the", "request", "via", "the", "upstream", "handler", "the", "response", "is", "not", "stored", "or", "modified" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/handler.go#L206-L236
123,316
lox/httpcache
handler.go
passUpstream
func (h *Handler) passUpstream(w http.ResponseWriter, r *cacheRequest) { rw := newResponseStreamer(w) rdr, err := rw.Stream.NextReader() if err != nil { debugf("error creating next stream reader: %v", err) w.Header().Set(CacheHeader, "SKIP") h.upstream.ServeHTTP(w, r.Request) return } t := Clock() debugf...
go
func (h *Handler) passUpstream(w http.ResponseWriter, r *cacheRequest) { rw := newResponseStreamer(w) rdr, err := rw.Stream.NextReader() if err != nil { debugf("error creating next stream reader: %v", err) w.Header().Set(CacheHeader, "SKIP") h.upstream.ServeHTTP(w, r.Request) return } t := Clock() debugf...
[ "func", "(", "h", "*", "Handler", ")", "passUpstream", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "cacheRequest", ")", "{", "rw", ":=", "newResponseStreamer", "(", "w", ")", "\n", "rdr", ",", "err", ":=", "rw", ".", "Stream", ".", "NextR...
// passUpstream makes the request via the upstream handler and stores the result
[ "passUpstream", "makes", "the", "request", "via", "the", "upstream", "handler", "and", "stores", "the", "result" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/handler.go#L239-L286
123,317
lox/httpcache
handler.go
lookup
func (h *Handler) lookup(req *cacheRequest) (*Resource, error) { res, err := h.cache.Retrieve(req.Key.String()) // HEAD requests can possibly be served from GET if err == ErrNotFoundInCache && req.Method == "HEAD" { res, err = h.cache.Retrieve(req.Key.ForMethod("GET").String()) if err != nil { return nil, er...
go
func (h *Handler) lookup(req *cacheRequest) (*Resource, error) { res, err := h.cache.Retrieve(req.Key.String()) // HEAD requests can possibly be served from GET if err == ErrNotFoundInCache && req.Method == "HEAD" { res, err = h.cache.Retrieve(req.Key.ForMethod("GET").String()) if err != nil { return nil, er...
[ "func", "(", "h", "*", "Handler", ")", "lookup", "(", "req", "*", "cacheRequest", ")", "(", "*", "Resource", ",", "error", ")", "{", "res", ",", "err", ":=", "h", ".", "cache", ".", "Retrieve", "(", "req", ".", "Key", ".", "String", "(", ")", "...
// lookupResource finds the best matching Resource for the // request, or nil and ErrNotFoundInCache if none is found
[ "lookupResource", "finds", "the", "best", "matching", "Resource", "for", "the", "request", "or", "nil", "and", "ErrNotFoundInCache", "if", "none", "is", "found" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/handler.go#L438-L467
123,318
lox/httpcache
handler.go
Resource
func (rw *responseStreamer) Resource() *Resource { r, err := rw.Stream.NextReader() if err == nil { b, err := ioutil.ReadAll(r) r.Close() if err == nil { return NewResourceBytes(rw.StatusCode, b, rw.Header()) } } return &Resource{ header: rw.Header(), statusCode: rw.StatusCode, ReadSeek...
go
func (rw *responseStreamer) Resource() *Resource { r, err := rw.Stream.NextReader() if err == nil { b, err := ioutil.ReadAll(r) r.Close() if err == nil { return NewResourceBytes(rw.StatusCode, b, rw.Header()) } } return &Resource{ header: rw.Header(), statusCode: rw.StatusCode, ReadSeek...
[ "func", "(", "rw", "*", "responseStreamer", ")", "Resource", "(", ")", "*", "Resource", "{", "r", ",", "err", ":=", "rw", ".", "Stream", ".", "NextReader", "(", ")", "\n", "if", "err", "==", "nil", "{", "b", ",", "err", ":=", "ioutil", ".", "Read...
// Resource returns a copy of the responseStreamer as a Resource object
[ "Resource", "returns", "a", "copy", "of", "the", "responseStreamer", "as", "a", "Resource", "object" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/handler.go#L565-L579
123,319
lox/httpcache
resource.go
Age
func (r *Resource) Age() (time.Duration, error) { var age time.Duration if ageInt, err := intHeader("Age", r.header); err == nil { age = time.Second * time.Duration(ageInt) } if proxyDate, err := timeHeader(ProxyDateHeader, r.header); err == nil { return Clock().Sub(proxyDate) + age, nil } if date, err := ...
go
func (r *Resource) Age() (time.Duration, error) { var age time.Duration if ageInt, err := intHeader("Age", r.header); err == nil { age = time.Second * time.Duration(ageInt) } if proxyDate, err := timeHeader(ProxyDateHeader, r.header); err == nil { return Clock().Sub(proxyDate) + age, nil } if date, err := ...
[ "func", "(", "r", "*", "Resource", ")", "Age", "(", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "var", "age", "time", ".", "Duration", "\n\n", "if", "ageInt", ",", "err", ":=", "intHeader", "(", "\"", "\"", ",", "r", ".", "header",...
// Calculate the age of the resource
[ "Calculate", "the", "age", "of", "the", "resource" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/resource.go#L144-L160
123,320
lox/httpcache
key.go
NewKey
func NewKey(method string, u *url.URL, h http.Header) Key { return Key{method: method, header: h, u: *u, vary: []string{}} }
go
func NewKey(method string, u *url.URL, h http.Header) Key { return Key{method: method, header: h, u: *u, vary: []string{}} }
[ "func", "NewKey", "(", "method", "string", ",", "u", "*", "url", ".", "URL", ",", "h", "http", ".", "Header", ")", "Key", "{", "return", "Key", "{", "method", ":", "method", ",", "header", ":", "h", ",", "u", ":", "*", "u", ",", "vary", ":", ...
// NewKey returns a new Key instance
[ "NewKey", "returns", "a", "new", "Key", "instance" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/key.go#L20-L22
123,321
lox/httpcache
key.go
NewRequestKey
func NewRequestKey(r *http.Request) Key { URL := r.URL if location := r.Header.Get("Content-Location"); location != "" { u, err := url.Parse(location) if err == nil { if !u.IsAbs() { u = r.URL.ResolveReference(u) } if u.Host != r.Host { debugf("illegal host %q in Content-Location", u.Host) } ...
go
func NewRequestKey(r *http.Request) Key { URL := r.URL if location := r.Header.Get("Content-Location"); location != "" { u, err := url.Parse(location) if err == nil { if !u.IsAbs() { u = r.URL.ResolveReference(u) } if u.Host != r.Host { debugf("illegal host %q in Content-Location", u.Host) } ...
[ "func", "NewRequestKey", "(", "r", "*", "http", ".", "Request", ")", "Key", "{", "URL", ":=", "r", ".", "URL", "\n\n", "if", "location", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ";", "location", "!=", "\"", "\"", "{", "u", ",...
// NewRequestKey generates a Key for a request
[ "NewRequestKey", "generates", "a", "Key", "for", "a", "request" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/key.go#L25-L46
123,322
lox/httpcache
key.go
ForMethod
func (k Key) ForMethod(method string) Key { k2 := k k2.method = method return k2 }
go
func (k Key) ForMethod(method string) Key { k2 := k k2.method = method return k2 }
[ "func", "(", "k", "Key", ")", "ForMethod", "(", "method", "string", ")", "Key", "{", "k2", ":=", "k", "\n", "k2", ".", "method", "=", "method", "\n", "return", "k2", "\n", "}" ]
// ForMethod returns a new Key with a given method
[ "ForMethod", "returns", "a", "new", "Key", "with", "a", "given", "method" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/key.go#L49-L53
123,323
lox/httpcache
key.go
Vary
func (k Key) Vary(varyHeader string, r *http.Request) Key { k2 := k for _, header := range strings.Split(varyHeader, ", ") { k2.vary = append(k2.vary, header+"="+r.Header.Get(header)) } return k2 }
go
func (k Key) Vary(varyHeader string, r *http.Request) Key { k2 := k for _, header := range strings.Split(varyHeader, ", ") { k2.vary = append(k2.vary, header+"="+r.Header.Get(header)) } return k2 }
[ "func", "(", "k", "Key", ")", "Vary", "(", "varyHeader", "string", ",", "r", "*", "http", ".", "Request", ")", "Key", "{", "k2", ":=", "k", "\n\n", "for", "_", ",", "header", ":=", "range", "strings", ".", "Split", "(", "varyHeader", ",", "\"", "...
// Vary returns a Key that is varied on particular headers in a http.Request
[ "Vary", "returns", "a", "Key", "that", "is", "varied", "on", "particular", "headers", "in", "a", "http", ".", "Request" ]
2de7d84cb2513697e071961c5a5a81060c4382b5
https://github.com/lox/httpcache/blob/2de7d84cb2513697e071961c5a5a81060c4382b5/key.go#L56-L64
123,324
tmc/grpc-websocket-proxy
wsproxy/websocket_proxy.go
WithForwardedHeaders
func WithForwardedHeaders(fn func(header string) bool) Option { return func(p *Proxy) { p.headerForwarder = fn } }
go
func WithForwardedHeaders(fn func(header string) bool) Option { return func(p *Proxy) { p.headerForwarder = fn } }
[ "func", "WithForwardedHeaders", "(", "fn", "func", "(", "header", "string", ")", "bool", ")", "Option", "{", "return", "func", "(", "p", "*", "Proxy", ")", "{", "p", ".", "headerForwarder", "=", "fn", "\n", "}", "\n", "}" ]
// WithForwardedHeaders allows controlling which headers are forwarded.
[ "WithForwardedHeaders", "allows", "controlling", "which", "headers", "are", "forwarded", "." ]
0ad062ec5ee553a48f6dbd280b7a1b5638e8a113
https://github.com/tmc/grpc-websocket-proxy/blob/0ad062ec5ee553a48f6dbd280b7a1b5638e8a113/wsproxy/websocket_proxy.go#L77-L81
123,325
tmc/grpc-websocket-proxy
wsproxy/websocket_proxy.go
transformSubProtocolHeader
func transformSubProtocolHeader(header string) string { tokens := strings.SplitN(header, "Bearer,", 2) if len(tokens) < 2 { return "" } return fmt.Sprintf("Bearer %v", strings.Trim(tokens[1], " ")) }
go
func transformSubProtocolHeader(header string) string { tokens := strings.SplitN(header, "Bearer,", 2) if len(tokens) < 2 { return "" } return fmt.Sprintf("Bearer %v", strings.Trim(tokens[1], " ")) }
[ "func", "transformSubProtocolHeader", "(", "header", "string", ")", "string", "{", "tokens", ":=", "strings", ".", "SplitN", "(", "header", ",", "\"", "\"", ",", "2", ")", "\n\n", "if", "len", "(", "tokens", ")", "<", "2", "{", "return", "\"", "\"", ...
// IE and Edge do not delimit Sec-WebSocket-Protocol strings with spaces
[ "IE", "and", "Edge", "do", "not", "delimit", "Sec", "-", "WebSocket", "-", "Protocol", "strings", "with", "spaces" ]
0ad062ec5ee553a48f6dbd280b7a1b5638e8a113
https://github.com/tmc/grpc-websocket-proxy/blob/0ad062ec5ee553a48f6dbd280b7a1b5638e8a113/wsproxy/websocket_proxy.go#L269-L277
123,326
albrow/jobs
worker.go
start
func (w *worker) start() { go func() { for job := range w.jobs { w.doJob(job) } w.wg.Done() }() }
go
func (w *worker) start() { go func() { for job := range w.jobs { w.doJob(job) } w.wg.Done() }() }
[ "func", "(", "w", "*", "worker", ")", "start", "(", ")", "{", "go", "func", "(", ")", "{", "for", "job", ":=", "range", "w", ".", "jobs", "{", "w", ".", "doJob", "(", "job", ")", "\n", "}", "\n", "w", ".", "wg", ".", "Done", "(", ")", "\n...
// start starts a goroutine in which the worker will continuously // execute jobs until the jobs channel is closed.
[ "start", "starts", "a", "goroutine", "in", "which", "the", "worker", "will", "continuously", "execute", "jobs", "until", "the", "jobs", "channel", "is", "closed", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/worker.go#L25-L32
123,327
albrow/jobs
worker.go
doJob
func (w *worker) doJob(job *Job) { if w.afterFunc != nil { defer w.afterFunc(job) } defer func() { if r := recover(); r != nil { // Get a reasonable error message from the panic msg := "" if err, ok := r.(error); ok { msg = err.Error() } else { msg = fmt.Sprint(r) } if err := setJobErr...
go
func (w *worker) doJob(job *Job) { if w.afterFunc != nil { defer w.afterFunc(job) } defer func() { if r := recover(); r != nil { // Get a reasonable error message from the panic msg := "" if err, ok := r.(error); ok { msg = err.Error() } else { msg = fmt.Sprint(r) } if err := setJobErr...
[ "func", "(", "w", "*", "worker", ")", "doJob", "(", "job", "*", "Job", ")", "{", "if", "w", ".", "afterFunc", "!=", "nil", "{", "defer", "w", ".", "afterFunc", "(", "job", ")", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "if", "r", ":=...
// doJob executes the given job. It also sets the status and timestamps for // the job appropriately depending on the outcome of the execution.
[ "doJob", "executes", "the", "given", "job", ".", "It", "also", "sets", "the", "status", "and", "timestamps", "for", "the", "job", "appropriately", "depending", "on", "the", "outcome", "of", "the", "execution", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/worker.go#L36-L115
123,328
albrow/jobs
utils.go
generateRandomId
func generateRandomId() string { timeInt := time.Now().UnixNano() timeString := strconv.FormatInt(timeInt, 36) randomString := uniuri.NewLen(16) return randomString + timeString }
go
func generateRandomId() string { timeInt := time.Now().UnixNano() timeString := strconv.FormatInt(timeInt, 36) randomString := uniuri.NewLen(16) return randomString + timeString }
[ "func", "generateRandomId", "(", ")", "string", "{", "timeInt", ":=", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", "\n", "timeString", ":=", "strconv", ".", "FormatInt", "(", "timeInt", ",", "36", ")", "\n", "randomString", ":=", "uniuri", ...
// generateRandomId generates a random string that is more or less // garunteed to be unique.
[ "generateRandomId", "generates", "a", "random", "string", "that", "is", "more", "or", "less", "garunteed", "to", "be", "unique", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/utils.go#L15-L20
123,329
albrow/jobs
job.go
save
func (j *Job) save() error { t := newTransaction() t.saveJob(j) if err := t.exec(); err != nil { return err } return nil }
go
func (j *Job) save() error { t := newTransaction() t.saveJob(j) if err := t.exec(); err != nil { return err } return nil }
[ "func", "(", "j", "*", "Job", ")", "save", "(", ")", "error", "{", "t", ":=", "newTransaction", "(", ")", "\n", "t", ".", "saveJob", "(", "j", ")", "\n", "if", "err", ":=", "t", ".", "exec", "(", ")", ";", "err", "!=", "nil", "{", "return", ...
// save writes the job to the database and adds it to the appropriate indexes and status // sets, but does not enqueue it. If you want to add it to the queue, use the enqueue method // after save.
[ "save", "writes", "the", "job", "to", "the", "database", "and", "adds", "it", "to", "the", "appropriate", "indexes", "and", "status", "sets", "but", "does", "not", "enqueue", "it", ".", "If", "you", "want", "to", "add", "it", "to", "the", "queue", "use...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L145-L152
123,330
albrow/jobs
job.go
saveJob
func (t *transaction) saveJob(job *Job) { // Generate id if needed if job.id == "" { job.id = generateRandomId() } // Set status to saved if needed if job.status == "" { job.status = StatusSaved } // Add the job attributes to a hash t.command("HMSET", job.mainHashArgs(), nil) // Add the job to the appropri...
go
func (t *transaction) saveJob(job *Job) { // Generate id if needed if job.id == "" { job.id = generateRandomId() } // Set status to saved if needed if job.status == "" { job.status = StatusSaved } // Add the job attributes to a hash t.command("HMSET", job.mainHashArgs(), nil) // Add the job to the appropri...
[ "func", "(", "t", "*", "transaction", ")", "saveJob", "(", "job", "*", "Job", ")", "{", "// Generate id if needed", "if", "job", ".", "id", "==", "\"", "\"", "{", "job", ".", "id", "=", "generateRandomId", "(", ")", "\n", "}", "\n", "// Set status to s...
// saveJob adds commands to the transaction to set all the fields for the main hash for the job, // add the job to the time index, move the job to the appropriate status set. It will // also mutate the job by 1) generating an id if the id is empty and 2) setting the status to // StatusSaved if the status is empty.
[ "saveJob", "adds", "commands", "to", "the", "transaction", "to", "set", "all", "the", "fields", "for", "the", "main", "hash", "for", "the", "job", "add", "the", "job", "to", "the", "time", "index", "move", "the", "job", "to", "the", "appropriate", "statu...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L158-L173
123,331
albrow/jobs
job.go
addJobToTimeIndex
func (t *transaction) addJobToTimeIndex(job *Job) { t.addJobToSet(job, Keys.JobsTimeIndex, float64(job.time)) }
go
func (t *transaction) addJobToTimeIndex(job *Job) { t.addJobToSet(job, Keys.JobsTimeIndex, float64(job.time)) }
[ "func", "(", "t", "*", "transaction", ")", "addJobToTimeIndex", "(", "job", "*", "Job", ")", "{", "t", ".", "addJobToSet", "(", "job", ",", "Keys", ".", "JobsTimeIndex", ",", "float64", "(", "job", ".", "time", ")", ")", "\n", "}" ]
// addJobToTimeIndex adds commands to the transaction which will, when executed, // add the job id to the time index with a score equal to the job's time field. // If the job has been destroyed, addJobToTimeIndex will have no effect.
[ "addJobToTimeIndex", "adds", "commands", "to", "the", "transaction", "which", "will", "when", "executed", "add", "the", "job", "id", "to", "the", "time", "index", "with", "a", "score", "equal", "to", "the", "job", "s", "time", "field", ".", "If", "the", ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L178-L180
123,332
albrow/jobs
job.go
Refresh
func (j *Job) Refresh() error { t := newTransaction() t.scanJobById(j.id, j) if err := t.exec(); err != nil { return err } return nil }
go
func (j *Job) Refresh() error { t := newTransaction() t.scanJobById(j.id, j) if err := t.exec(); err != nil { return err } return nil }
[ "func", "(", "j", "*", "Job", ")", "Refresh", "(", ")", "error", "{", "t", ":=", "newTransaction", "(", ")", "\n", "t", ".", "scanJobById", "(", "j", ".", "id", ",", "j", ")", "\n", "if", "err", ":=", "t", ".", "exec", "(", ")", ";", "err", ...
// Refresh mutates the job by setting its fields to the most recent data // found in the database. It returns an error if there was a problem connecting // to the database or if the job was destroyed.
[ "Refresh", "mutates", "the", "job", "by", "setting", "its", "fields", "to", "the", "most", "recent", "data", "found", "in", "the", "database", ".", "It", "returns", "an", "error", "if", "there", "was", "a", "problem", "connecting", "to", "the", "database",...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L185-L192
123,333
albrow/jobs
job.go
enqueue
func (j *Job) enqueue() error { if err := j.setStatus(StatusQueued); err != nil { return err } return nil }
go
func (j *Job) enqueue() error { if err := j.setStatus(StatusQueued); err != nil { return err } return nil }
[ "func", "(", "j", "*", "Job", ")", "enqueue", "(", ")", "error", "{", "if", "err", ":=", "j", ".", "setStatus", "(", "StatusQueued", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// enqueue adds the job to the queue and sets its status to StatusQueued. Queued jobs will // be completed by workers in order of priority. Attempting to enqueue a destroyed job // will have no effect.
[ "enqueue", "adds", "the", "job", "to", "the", "queue", "and", "sets", "its", "status", "to", "StatusQueued", ".", "Queued", "jobs", "will", "be", "completed", "by", "workers", "in", "order", "of", "priority", ".", "Attempting", "to", "enqueue", "a", "destr...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L197-L202
123,334
albrow/jobs
job.go
Reschedule
func (j *Job) Reschedule(time time.Time) error { t := newTransaction() unixNanoTime := time.UTC().UnixNano() t.setJobField(j, "time", unixNanoTime) t.setStatus(j, StatusQueued) j.time = unixNanoTime t.addJobToTimeIndex(j) if err := t.exec(); err != nil { return err } j.status = StatusQueued return nil }
go
func (j *Job) Reschedule(time time.Time) error { t := newTransaction() unixNanoTime := time.UTC().UnixNano() t.setJobField(j, "time", unixNanoTime) t.setStatus(j, StatusQueued) j.time = unixNanoTime t.addJobToTimeIndex(j) if err := t.exec(); err != nil { return err } j.status = StatusQueued return nil }
[ "func", "(", "j", "*", "Job", ")", "Reschedule", "(", "time", "time", ".", "Time", ")", "error", "{", "t", ":=", "newTransaction", "(", ")", "\n", "unixNanoTime", ":=", "time", ".", "UTC", "(", ")", ".", "UnixNano", "(", ")", "\n", "t", ".", "set...
// Reschedule reschedules the job with the given time. It can be used to reschedule // cancelled jobs. It may also be used to reschedule finished or failed jobs, however, // in most cases if you want to reschedule finished jobs you should use the ScheduleRecurring // method and if you want to reschedule failed jobs, yo...
[ "Reschedule", "reschedules", "the", "job", "with", "the", "given", "time", ".", "It", "can", "be", "used", "to", "reschedule", "cancelled", "jobs", ".", "It", "may", "also", "be", "used", "to", "reschedule", "finished", "or", "failed", "jobs", "however", "...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L210-L222
123,335
albrow/jobs
job.go
Cancel
func (j *Job) Cancel() error { if err := j.setStatus(StatusCancelled); err != nil { return err } return nil }
go
func (j *Job) Cancel() error { if err := j.setStatus(StatusCancelled); err != nil { return err } return nil }
[ "func", "(", "j", "*", "Job", ")", "Cancel", "(", ")", "error", "{", "if", "err", ":=", "j", ".", "setStatus", "(", "StatusCancelled", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Cancel cancels the job, but does not remove it from the database. It will be // added to a list of cancelled jobs. If you wish to remove it from the database, // use the Destroy method. Attempting to cancel a destroyed job will have no effect.
[ "Cancel", "cancels", "the", "job", "but", "does", "not", "remove", "it", "from", "the", "database", ".", "It", "will", "be", "added", "to", "a", "list", "of", "cancelled", "jobs", ".", "If", "you", "wish", "to", "remove", "it", "from", "the", "database...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L227-L232
123,336
albrow/jobs
job.go
setError
func (j *Job) setError(err error) error { j.err = err t := newTransaction() t.setJobField(j, "error", j.err.Error()) if err := t.exec(); err != nil { return err } return nil }
go
func (j *Job) setError(err error) error { j.err = err t := newTransaction() t.setJobField(j, "error", j.err.Error()) if err := t.exec(); err != nil { return err } return nil }
[ "func", "(", "j", "*", "Job", ")", "setError", "(", "err", "error", ")", "error", "{", "j", ".", "err", "=", "err", "\n", "t", ":=", "newTransaction", "(", ")", "\n", "t", ".", "setJobField", "(", "j", ",", "\"", "\"", ",", "j", ".", "err", "...
// setError sets the err property of j and adds it to the set of jobs which had errors. // If the job has been destroyed, setError will have no effect.
[ "setError", "sets", "the", "err", "property", "of", "j", "and", "adds", "it", "to", "the", "set", "of", "jobs", "which", "had", "errors", ".", "If", "the", "job", "has", "been", "destroyed", "setError", "will", "have", "no", "effect", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L236-L244
123,337
albrow/jobs
job.go
Destroy
func (j *Job) Destroy() error { if j.id == "" { return fmt.Errorf("jobs: Cannot destroy job that doesn't have an id.") } // Start a new transaction t := newTransaction() // Call the script to destroy the job t.destroyJob(j) // Execute the transaction if err := t.exec(); err != nil { return err } j.status ...
go
func (j *Job) Destroy() error { if j.id == "" { return fmt.Errorf("jobs: Cannot destroy job that doesn't have an id.") } // Start a new transaction t := newTransaction() // Call the script to destroy the job t.destroyJob(j) // Execute the transaction if err := t.exec(); err != nil { return err } j.status ...
[ "func", "(", "j", "*", "Job", ")", "Destroy", "(", ")", "error", "{", "if", "j", ".", "id", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "// Start a new transaction", "t", ":=", "newTransaction", "("...
// Destroy removes all traces of the job from the database. If the job is currently // being executed by a worker, the worker may still finish the job. Attempting to // destroy a job that has already been destroyed will have no effect, so it is safe // to call Destroy multiple times.
[ "Destroy", "removes", "all", "traces", "of", "the", "job", "from", "the", "database", ".", "If", "the", "job", "is", "currently", "being", "executed", "by", "a", "worker", "the", "worker", "may", "still", "finish", "the", "job", ".", "Attempting", "to", ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L250-L264
123,338
albrow/jobs
job.go
setStatus
func (j *Job) setStatus(status Status) error { if j.id == "" { return fmt.Errorf("jobs: Cannot set status to %s because job doesn't have an id.", status) } if j.status == StatusDestroyed { return fmt.Errorf("jobs: Cannot set job:%s status to %s because it was destroyed.", j.id, status) } // Use a transaction t...
go
func (j *Job) setStatus(status Status) error { if j.id == "" { return fmt.Errorf("jobs: Cannot set status to %s because job doesn't have an id.", status) } if j.status == StatusDestroyed { return fmt.Errorf("jobs: Cannot set job:%s status to %s because it was destroyed.", j.id, status) } // Use a transaction t...
[ "func", "(", "j", "*", "Job", ")", "setStatus", "(", "status", "Status", ")", "error", "{", "if", "j", ".", "id", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "status", ")", "\n", "}", "\n", "if", "j", ".", "st...
// setStatus updates the job's status in the database and moves it to the appropriate // status set. Attempting to set the status of a job which has been destroyed will have // no effect.
[ "setStatus", "updates", "the", "job", "s", "status", "in", "the", "database", "and", "moves", "it", "to", "the", "appropriate", "status", "set", ".", "Attempting", "to", "set", "the", "status", "of", "a", "job", "which", "has", "been", "destroyed", "will",...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L269-L284
123,339
albrow/jobs
job.go
mainHashArgs
func (j *Job) mainHashArgs() []interface{} { hashArgs := []interface{}{j.Key(), "data", string(j.data), "type", j.typ.name, "time", j.time, "freq", j.freq, "priority", j.priority, "retries", j.retries, "status", j.status, "started", j.started, "finished", j.finished, "poolId", j.poolId, } if j.er...
go
func (j *Job) mainHashArgs() []interface{} { hashArgs := []interface{}{j.Key(), "data", string(j.data), "type", j.typ.name, "time", j.time, "freq", j.freq, "priority", j.priority, "retries", j.retries, "status", j.status, "started", j.started, "finished", j.finished, "poolId", j.poolId, } if j.er...
[ "func", "(", "j", "*", "Job", ")", "mainHashArgs", "(", ")", "[", "]", "interface", "{", "}", "{", "hashArgs", ":=", "[", "]", "interface", "{", "}", "{", "j", ".", "Key", "(", ")", ",", "\"", "\"", ",", "string", "(", "j", ".", "data", ")", ...
// mainHashArgs returns the args for the hash which will store the job data
[ "mainHashArgs", "returns", "the", "args", "for", "the", "hash", "which", "will", "store", "the", "job", "data" ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L287-L304
123,340
albrow/jobs
job.go
scanJob
func scanJob(reply interface{}, job *Job) error { fields, err := redis.Values(reply, nil) if err != nil { return err } else if len(fields) == 0 { return ErrorJobNotFound{} } else if len(fields)%2 != 0 { return fmt.Errorf("jobs: In scanJob: Expected length of fields to be even but got: %d", len(fields)) } fo...
go
func scanJob(reply interface{}, job *Job) error { fields, err := redis.Values(reply, nil) if err != nil { return err } else if len(fields) == 0 { return ErrorJobNotFound{} } else if len(fields)%2 != 0 { return fmt.Errorf("jobs: In scanJob: Expected length of fields to be even but got: %d", len(fields)) } fo...
[ "func", "scanJob", "(", "reply", "interface", "{", "}", ",", "job", "*", "Job", ")", "error", "{", "fields", ",", "err", ":=", "redis", ".", "Values", "(", "reply", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}",...
// scanJob scans the values of reply into job. reply should be the // response of an HMGET or HGETALL query.
[ "scanJob", "scans", "the", "values", "of", "reply", "into", "job", ".", "reply", "should", "be", "the", "response", "of", "an", "HMGET", "or", "HGETALL", "query", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L308-L379
123,341
albrow/jobs
job.go
scanInt
func scanInt(reply interface{}, v *int) error { if v == nil { return fmt.Errorf("jobs: In scanInt: argument v was nil") } val, err := redis.Int(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanInt: Could not convert %v of type %T to int.", reply, reply) } (*v) = val return nil }
go
func scanInt(reply interface{}, v *int) error { if v == nil { return fmt.Errorf("jobs: In scanInt: argument v was nil") } val, err := redis.Int(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanInt: Could not convert %v of type %T to int.", reply, reply) } (*v) = val return nil }
[ "func", "scanInt", "(", "reply", "interface", "{", "}", ",", "v", "*", "int", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "val", ",", "err", ":=", "redis", ".", "Int", ...
// scanInt converts a reply from redis into an int and scans the value into v.
[ "scanInt", "converts", "a", "reply", "from", "redis", "into", "an", "int", "and", "scans", "the", "value", "into", "v", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L382-L392
123,342
albrow/jobs
job.go
scanUint
func scanUint(reply interface{}, v *uint) error { if v == nil { return fmt.Errorf("jobs: In scanUint: argument v was nil") } val, err := redis.Uint64(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanUint: Could not convert %v of type %T to uint.", reply, reply) } (*v) = uint(val) return nil }
go
func scanUint(reply interface{}, v *uint) error { if v == nil { return fmt.Errorf("jobs: In scanUint: argument v was nil") } val, err := redis.Uint64(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanUint: Could not convert %v of type %T to uint.", reply, reply) } (*v) = uint(val) return nil }
[ "func", "scanUint", "(", "reply", "interface", "{", "}", ",", "v", "*", "uint", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "val", ",", "err", ":=", "redis", ".", "Uint6...
// scanUint converts a reply from redis into a uint and scans the value into v.
[ "scanUint", "converts", "a", "reply", "from", "redis", "into", "a", "uint", "and", "scans", "the", "value", "into", "v", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L395-L405
123,343
albrow/jobs
job.go
scanInt64
func scanInt64(reply interface{}, v *int64) error { if v == nil { return fmt.Errorf("jobs: In scanInt64: argument v was nil") } val, err := redis.Int64(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanInt64: Could not convert %v of type %T to int64.", reply, reply) } (*v) = val return nil }
go
func scanInt64(reply interface{}, v *int64) error { if v == nil { return fmt.Errorf("jobs: In scanInt64: argument v was nil") } val, err := redis.Int64(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanInt64: Could not convert %v of type %T to int64.", reply, reply) } (*v) = val return nil }
[ "func", "scanInt64", "(", "reply", "interface", "{", "}", ",", "v", "*", "int64", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "val", ",", "err", ":=", "redis", ".", "Int...
// scanInt64 converts a reply from redis into an int64 and scans the value into v.
[ "scanInt64", "converts", "a", "reply", "from", "redis", "into", "an", "int64", "and", "scans", "the", "value", "into", "v", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L408-L418
123,344
albrow/jobs
job.go
scanString
func scanString(reply interface{}, v *string) error { if v == nil { return fmt.Errorf("jobs: In String: argument v was nil") } val, err := redis.String(reply, nil) if err != nil { return fmt.Errorf("jobs: In String: Could not convert %v of type %T to string.", reply, reply) } (*v) = val return nil }
go
func scanString(reply interface{}, v *string) error { if v == nil { return fmt.Errorf("jobs: In String: argument v was nil") } val, err := redis.String(reply, nil) if err != nil { return fmt.Errorf("jobs: In String: Could not convert %v of type %T to string.", reply, reply) } (*v) = val return nil }
[ "func", "scanString", "(", "reply", "interface", "{", "}", ",", "v", "*", "string", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "val", ",", "err", ":=", "redis", ".", "S...
// scanString converts a reply from redis into a string and scans the value into v.
[ "scanString", "converts", "a", "reply", "from", "redis", "into", "a", "string", "and", "scans", "the", "value", "into", "v", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L421-L431
123,345
albrow/jobs
job.go
scanBytes
func scanBytes(reply interface{}, v *[]byte) error { if v == nil { return fmt.Errorf("jobs: In scanBytes: argument v was nil") } val, err := redis.Bytes(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanBytes: Could not convert %v of type %T to []byte.", reply, reply) } (*v) = val return nil }
go
func scanBytes(reply interface{}, v *[]byte) error { if v == nil { return fmt.Errorf("jobs: In scanBytes: argument v was nil") } val, err := redis.Bytes(reply, nil) if err != nil { return fmt.Errorf("jobs: In scanBytes: Could not convert %v of type %T to []byte.", reply, reply) } (*v) = val return nil }
[ "func", "scanBytes", "(", "reply", "interface", "{", "}", ",", "v", "*", "[", "]", "byte", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "val", ",", "err", ":=", "redis", ...
// scanBytes converts a reply from redis into a slice of bytes and scans the value into v.
[ "scanBytes", "converts", "a", "reply", "from", "redis", "into", "a", "slice", "of", "bytes", "and", "scans", "the", "value", "into", "v", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L434-L444
123,346
albrow/jobs
job.go
scanJobById
func (t *transaction) scanJobById(id string, job *Job) { job.id = id t.command("HGETALL", redis.Args{job.Key()}, newScanJobHandler(job)) }
go
func (t *transaction) scanJobById(id string, job *Job) { job.id = id t.command("HGETALL", redis.Args{job.Key()}, newScanJobHandler(job)) }
[ "func", "(", "t", "*", "transaction", ")", "scanJobById", "(", "id", "string", ",", "job", "*", "Job", ")", "{", "job", ".", "id", "=", "id", "\n", "t", ".", "command", "(", "\"", "\"", ",", "redis", ".", "Args", "{", "job", ".", "Key", "(", ...
// scanJobById adds commands and a reply handler to the transaction which, when run, // will scan the values of the job corresponding to id into job. It does not execute // the transaction.
[ "scanJobById", "adds", "commands", "and", "a", "reply", "handler", "to", "the", "transaction", "which", "when", "run", "will", "scan", "the", "values", "of", "the", "job", "corresponding", "to", "id", "into", "job", ".", "It", "does", "not", "execute", "th...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job.go#L449-L452
123,347
albrow/jobs
job_status.go
Count
func (status Status) Count() (int, error) { conn := redisPool.Get() defer conn.Close() return redis.Int(conn.Do("ZCARD", status.Key())) }
go
func (status Status) Count() (int, error) { conn := redisPool.Get() defer conn.Close() return redis.Int(conn.Do("ZCARD", status.Key())) }
[ "func", "(", "status", "Status", ")", "Count", "(", ")", "(", "int", ",", "error", ")", "{", "conn", ":=", "redisPool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "return", "redis", ".", "Int", "(", "conn", ".", ...
// Count returns the number of jobs that currently have the given status // or an error if there was a problem connecting to the database.
[ "Count", "returns", "the", "number", "of", "jobs", "that", "currently", "have", "the", "given", "status", "or", "an", "error", "if", "there", "was", "a", "problem", "connecting", "to", "the", "database", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_status.go#L41-L45
123,348
albrow/jobs
job_status.go
JobIds
func (status Status) JobIds() ([]string, error) { conn := redisPool.Get() defer conn.Close() return redis.Strings(conn.Do("ZREVRANGE", status.Key(), 0, -1)) }
go
func (status Status) JobIds() ([]string, error) { conn := redisPool.Get() defer conn.Close() return redis.Strings(conn.Do("ZREVRANGE", status.Key(), 0, -1)) }
[ "func", "(", "status", "Status", ")", "JobIds", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "conn", ":=", "redisPool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "return", "redis", ".", "Strings", "(...
// JobIds returns the ids of all jobs that have the given status, ordered by // priority or an error if there was a problem connecting to the database.
[ "JobIds", "returns", "the", "ids", "of", "all", "jobs", "that", "have", "the", "given", "status", "ordered", "by", "priority", "or", "an", "error", "if", "there", "was", "a", "problem", "connecting", "to", "the", "database", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_status.go#L49-L53
123,349
albrow/jobs
job_status.go
Jobs
func (status Status) Jobs() ([]*Job, error) { t := newTransaction() jobs := []*Job{} t.getJobsByIds(status.Key(), newScanJobsHandler(&jobs)) if err := t.exec(); err != nil { return nil, err } return jobs, nil }
go
func (status Status) Jobs() ([]*Job, error) { t := newTransaction() jobs := []*Job{} t.getJobsByIds(status.Key(), newScanJobsHandler(&jobs)) if err := t.exec(); err != nil { return nil, err } return jobs, nil }
[ "func", "(", "status", "Status", ")", "Jobs", "(", ")", "(", "[", "]", "*", "Job", ",", "error", ")", "{", "t", ":=", "newTransaction", "(", ")", "\n", "jobs", ":=", "[", "]", "*", "Job", "{", "}", "\n", "t", ".", "getJobsByIds", "(", "status",...
// Jobs returns all jobs that have the given status, ordered by priority or // an error if there was a problem connecting to the database.
[ "Jobs", "returns", "all", "jobs", "that", "have", "the", "given", "status", "ordered", "by", "priority", "or", "an", "error", "if", "there", "was", "a", "problem", "connecting", "to", "the", "database", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_status.go#L57-L65
123,350
albrow/jobs
job_type.go
RegisterType
func RegisterType(name string, retries uint, handler HandlerFunc) (*Type, error) { // Make sure name is unique if _, found := Types[name]; found { return Types[name], newErrorNameAlreadyRegistered(name) } // Make sure handler is a function handlerType := reflect.TypeOf(handler) if handlerType.Kind() != reflect....
go
func RegisterType(name string, retries uint, handler HandlerFunc) (*Type, error) { // Make sure name is unique if _, found := Types[name]; found { return Types[name], newErrorNameAlreadyRegistered(name) } // Make sure handler is a function handlerType := reflect.TypeOf(handler) if handlerType.Kind() != reflect....
[ "func", "RegisterType", "(", "name", "string", ",", "retries", "uint", ",", "handler", "HandlerFunc", ")", "(", "*", "Type", ",", "error", ")", "{", "// Make sure name is unique", "if", "_", ",", "found", ":=", "Types", "[", "name", "]", ";", "found", "{...
// RegisterType registers a new type of job that can be executed by workers. // name should be a unique string identifier for the job. // retries is the number of times this type of job should be retried if it fails. // handler is a function that a worker will call in order to execute the job. // handler should be a fu...
[ "RegisterType", "registers", "a", "new", "type", "of", "job", "that", "can", "be", "executed", "by", "workers", ".", "name", "should", "be", "a", "unique", "string", "identifier", "for", "the", "job", ".", "retries", "is", "the", "number", "of", "times", ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_type.go#L54-L83
123,351
albrow/jobs
job_type.go
Schedule
func (jt *Type) Schedule(priority int, time time.Time, data interface{}) (*Job, error) { // Encode the data encodedData, err := jt.encodeData(data) if err != nil { return nil, err } // Create and save the job job := &Job{ data: encodedData, typ: jt, time: time.UTC().UnixNano(), retries: jt...
go
func (jt *Type) Schedule(priority int, time time.Time, data interface{}) (*Job, error) { // Encode the data encodedData, err := jt.encodeData(data) if err != nil { return nil, err } // Create and save the job job := &Job{ data: encodedData, typ: jt, time: time.UTC().UnixNano(), retries: jt...
[ "func", "(", "jt", "*", "Type", ")", "Schedule", "(", "priority", "int", ",", "time", "time", ".", "Time", ",", "data", "interface", "{", "}", ")", "(", "*", "Job", ",", "error", ")", "{", "// Encode the data", "encodedData", ",", "err", ":=", "jt", ...
// Schedule schedules a on-off job of the given type with the given parameters. // Jobs with a higher priority will be executed first. The job will not be // executed until after time. data is the data associated with this particular // job and should have the same type as the first argument to the handler for this // ...
[ "Schedule", "schedules", "a", "on", "-", "off", "job", "of", "the", "given", "type", "with", "the", "given", "parameters", ".", "Jobs", "with", "a", "higher", "priority", "will", "be", "executed", "first", ".", "The", "job", "will", "not", "be", "execute...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_type.go#L101-L121
123,352
albrow/jobs
job_type.go
encodeData
func (jt *Type) encodeData(data interface{}) ([]byte, error) { // Check the type of data dataType := reflect.TypeOf(data) if dataType != jt.dataType { return nil, fmt.Errorf("jobs: provided data was not of the correct type.\nExpected %s for Type %s, but got %s", jt.dataType, jt, dataType) } // Encode the data e...
go
func (jt *Type) encodeData(data interface{}) ([]byte, error) { // Check the type of data dataType := reflect.TypeOf(data) if dataType != jt.dataType { return nil, fmt.Errorf("jobs: provided data was not of the correct type.\nExpected %s for Type %s, but got %s", jt.dataType, jt, dataType) } // Encode the data e...
[ "func", "(", "jt", "*", "Type", ")", "encodeData", "(", "data", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Check the type of data", "dataType", ":=", "reflect", ".", "TypeOf", "(", "data", ")", "\n", "if", "dataType"...
// encodeData checks that the type of data is what we expect based on the handler for the Type. // If it is, it encodes the data into a slice of bytes.
[ "encodeData", "checks", "that", "the", "type", "of", "data", "is", "what", "we", "expect", "based", "on", "the", "handler", "for", "the", "Type", ".", "If", "it", "is", "it", "encodes", "the", "data", "into", "a", "slice", "of", "bytes", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/job_type.go#L154-L166
123,353
albrow/jobs
pool.go
NewPool
func NewPool(config *PoolConfig) (*Pool, error) { finalConfig := getPoolConfig(config) hardwareId, err := getHardwareId() if err != nil { return nil, err } return &Pool{ config: finalConfig, id: hardwareId, wg: &sync.WaitGroup{}, exit: make(chan bool), workers: make([]*worker, finalConfig...
go
func NewPool(config *PoolConfig) (*Pool, error) { finalConfig := getPoolConfig(config) hardwareId, err := getHardwareId() if err != nil { return nil, err } return &Pool{ config: finalConfig, id: hardwareId, wg: &sync.WaitGroup{}, exit: make(chan bool), workers: make([]*worker, finalConfig...
[ "func", "NewPool", "(", "config", "*", "PoolConfig", ")", "(", "*", "Pool", ",", "error", ")", "{", "finalConfig", ":=", "getPoolConfig", "(", "config", ")", "\n", "hardwareId", ",", "err", ":=", "getHardwareId", "(", ")", "\n", "if", "err", "!=", "nil...
// NewPool creates and returns a new pool with the given configuration. You can // pass in nil to use the default values. Otherwise, any zero values in config will // be interpreted as the default value.
[ "NewPool", "creates", "and", "returns", "a", "new", "pool", "with", "the", "given", "configuration", ".", "You", "can", "pass", "in", "nil", "to", "use", "the", "default", "values", ".", "Otherwise", "any", "zero", "values", "in", "config", "will", "be", ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L92-L106
123,354
albrow/jobs
pool.go
getPoolConfig
func getPoolConfig(passedConfig *PoolConfig) *PoolConfig { if passedConfig == nil { return DefaultPoolConfig } finalConfig := &PoolConfig{} (*finalConfig) = (*passedConfig) if passedConfig.NumWorkers == 0 { finalConfig.NumWorkers = DefaultPoolConfig.NumWorkers } if passedConfig.BatchSize == 0 { finalConfig...
go
func getPoolConfig(passedConfig *PoolConfig) *PoolConfig { if passedConfig == nil { return DefaultPoolConfig } finalConfig := &PoolConfig{} (*finalConfig) = (*passedConfig) if passedConfig.NumWorkers == 0 { finalConfig.NumWorkers = DefaultPoolConfig.NumWorkers } if passedConfig.BatchSize == 0 { finalConfig...
[ "func", "getPoolConfig", "(", "passedConfig", "*", "PoolConfig", ")", "*", "PoolConfig", "{", "if", "passedConfig", "==", "nil", "{", "return", "DefaultPoolConfig", "\n", "}", "\n", "finalConfig", ":=", "&", "PoolConfig", "{", "}", "\n", "(", "*", "finalConf...
// getPoolConfig replaces any zero values in passedConfig with the default values. // If passedConfig is nil, every value will be set to the default.
[ "getPoolConfig", "replaces", "any", "zero", "values", "in", "passedConfig", "with", "the", "default", "values", ".", "If", "passedConfig", "is", "nil", "every", "value", "will", "be", "set", "to", "the", "default", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L110-L129
123,355
albrow/jobs
pool.go
addToPoolSet
func (p *Pool) addToPoolSet() error { conn := redisPool.Get() defer conn.Close() p.RLock() thisId := p.id p.RUnlock() if _, err := conn.Do("SADD", Keys.ActivePools, thisId); err != nil { return err } return nil }
go
func (p *Pool) addToPoolSet() error { conn := redisPool.Get() defer conn.Close() p.RLock() thisId := p.id p.RUnlock() if _, err := conn.Do("SADD", Keys.ActivePools, thisId); err != nil { return err } return nil }
[ "func", "(", "p", "*", "Pool", ")", "addToPoolSet", "(", ")", "error", "{", "conn", ":=", "redisPool", ".", "Get", "(", ")", "\n", "defer", "conn", ".", "Close", "(", ")", "\n", "p", ".", "RLock", "(", ")", "\n", "thisId", ":=", "p", ".", "id",...
// addToPoolSet adds the id of the worker pool to a set of active pools // in the database.
[ "addToPoolSet", "adds", "the", "id", "of", "the", "worker", "pool", "to", "a", "set", "of", "active", "pools", "in", "the", "database", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L133-L143
123,356
albrow/jobs
pool.go
pingAndPurgeIfNeeded
func (p *Pool) pingAndPurgeIfNeeded(other *Pool) error { ping := redisPool.Get() pong := redis.PubSubConn{redisPool.Get()} // Listen for pongs by subscribing to the other pool's pong key pong.Subscribe(other.pongKey()) // Ping the other pool by publishing to its ping key ping.Do("PUBLISH", other.pingKey(), 1) //...
go
func (p *Pool) pingAndPurgeIfNeeded(other *Pool) error { ping := redisPool.Get() pong := redis.PubSubConn{redisPool.Get()} // Listen for pongs by subscribing to the other pool's pong key pong.Subscribe(other.pongKey()) // Ping the other pool by publishing to its ping key ping.Do("PUBLISH", other.pingKey(), 1) //...
[ "func", "(", "p", "*", "Pool", ")", "pingAndPurgeIfNeeded", "(", "other", "*", "Pool", ")", "error", "{", "ping", ":=", "redisPool", ".", "Get", "(", ")", "\n", "pong", ":=", "redis", ".", "PubSubConn", "{", "redisPool", ".", "Get", "(", ")", "}", ...
// pingAndPurgeIfNeeded pings other by publishing to others ping key. If it // does not receive a pong reply within some amount of time, it will // assume the pool is stale and purge it.
[ "pingAndPurgeIfNeeded", "pings", "other", "by", "publishing", "to", "others", "ping", "key", ".", "If", "it", "does", "not", "receive", "a", "pong", "reply", "within", "some", "amount", "of", "time", "it", "will", "assume", "the", "pool", "is", "stale", "a...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L239-L294
123,357
albrow/jobs
pool.go
respondToPings
func (p *Pool) respondToPings() error { pong := redisPool.Get() ping := redis.PubSubConn{redisPool.Get()} defer func() { pong.Close() ping.Close() }() // Subscribe to the ping key for this pool to receive pings. if err := ping.Subscribe(p.pingKey()); err != nil { return err } for { // Whenever we reciev...
go
func (p *Pool) respondToPings() error { pong := redisPool.Get() ping := redis.PubSubConn{redisPool.Get()} defer func() { pong.Close() ping.Close() }() // Subscribe to the ping key for this pool to receive pings. if err := ping.Subscribe(p.pingKey()); err != nil { return err } for { // Whenever we reciev...
[ "func", "(", "p", "*", "Pool", ")", "respondToPings", "(", ")", "error", "{", "pong", ":=", "redisPool", ".", "Get", "(", ")", "\n", "ping", ":=", "redis", ".", "PubSubConn", "{", "redisPool", ".", "Get", "(", ")", "}", "\n", "defer", "func", "(", ...
// respondToPings continuously listens for pings from other worker pools and // immediately responds with a pong. It will only return if there is an error.
[ "respondToPings", "continuously", "listens", "for", "pings", "from", "other", "worker", "pools", "and", "immediately", "responds", "with", "a", "pong", ".", "It", "will", "only", "return", "if", "there", "is", "an", "error", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L298-L323
123,358
albrow/jobs
pool.go
Start
func (p *Pool) Start() error { // Purge stale jobs belonging to this pool if there was a recent // hard failure if err := p.removeStaleSelf(); err != nil { return err } // Check on the status of other worker pools by pinging them and // start the process to repond to pings from other pools if err := p.addToPo...
go
func (p *Pool) Start() error { // Purge stale jobs belonging to this pool if there was a recent // hard failure if err := p.removeStaleSelf(); err != nil { return err } // Check on the status of other worker pools by pinging them and // start the process to repond to pings from other pools if err := p.addToPo...
[ "func", "(", "p", "*", "Pool", ")", "Start", "(", ")", "error", "{", "// Purge stale jobs belonging to this pool if there was a recent", "// hard failure", "if", "err", ":=", "p", ".", "removeStaleSelf", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", ...
// Start starts the worker pool. This means the pool will initialize workers, // continuously query the database for queued jobs, and delegate those jobs // to the workers.
[ "Start", "starts", "the", "worker", "pool", ".", "This", "means", "the", "pool", "will", "initialize", "workers", "continuously", "query", "the", "database", "for", "queued", "jobs", "and", "delegate", "those", "jobs", "to", "the", "workers", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L348-L393
123,359
albrow/jobs
pool.go
queryLoop
func (p *Pool) queryLoop() error { if err := p.sendNextJobs(p.config.BatchSize); err != nil { return err } for { minWait := time.After(p.config.MinWait) select { case <-p.exit: // Close the channel to tell workers to stop executing new jobs close(p.jobs) return nil case <-minWait: if err := p.s...
go
func (p *Pool) queryLoop() error { if err := p.sendNextJobs(p.config.BatchSize); err != nil { return err } for { minWait := time.After(p.config.MinWait) select { case <-p.exit: // Close the channel to tell workers to stop executing new jobs close(p.jobs) return nil case <-minWait: if err := p.s...
[ "func", "(", "p", "*", "Pool", ")", "queryLoop", "(", ")", "error", "{", "if", "err", ":=", "p", ".", "sendNextJobs", "(", "p", ".", "config", ".", "BatchSize", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "{", "m...
// queryLoop continuously queries the database for new jobs and, if // it finds any, sends them through the jobs channel for execution // by some worker.
[ "queryLoop", "continuously", "queries", "the", "database", "for", "new", "jobs", "and", "if", "it", "finds", "any", "sends", "them", "through", "the", "jobs", "channel", "for", "execution", "by", "some", "worker", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L423-L441
123,360
albrow/jobs
pool.go
sendNextJobs
func (p *Pool) sendNextJobs(n int) error { jobs, err := p.getNextJobs(p.config.BatchSize) if err != nil { return err } // Send the jobs across the channel, where they will be picked up // by exactly one worker for _, job := range jobs { p.jobs <- job } return nil }
go
func (p *Pool) sendNextJobs(n int) error { jobs, err := p.getNextJobs(p.config.BatchSize) if err != nil { return err } // Send the jobs across the channel, where they will be picked up // by exactly one worker for _, job := range jobs { p.jobs <- job } return nil }
[ "func", "(", "p", "*", "Pool", ")", "sendNextJobs", "(", "n", "int", ")", "error", "{", "jobs", ",", "err", ":=", "p", ".", "getNextJobs", "(", "p", ".", "config", ".", "BatchSize", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n",...
// sendNextJobs queries the database to find the next n ready jobs, then // sends those jobs to the jobs channel, effectively delegating them to // a worker.
[ "sendNextJobs", "queries", "the", "database", "to", "find", "the", "next", "n", "ready", "jobs", "then", "sends", "those", "jobs", "to", "the", "jobs", "channel", "effectively", "delegating", "them", "to", "a", "worker", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/pool.go#L446-L457
123,361
albrow/jobs
transaction.go
command
func (t *transaction) command(name string, args redis.Args, handler replyHandler) { t.actions = append(t.actions, &action{ kind: actionCommand, name: name, args: args, handler: handler, }) }
go
func (t *transaction) command(name string, args redis.Args, handler replyHandler) { t.actions = append(t.actions, &action{ kind: actionCommand, name: name, args: args, handler: handler, }) }
[ "func", "(", "t", "*", "transaction", ")", "command", "(", "name", "string", ",", "args", "redis", ".", "Args", ",", "handler", "replyHandler", ")", "{", "t", ".", "actions", "=", "append", "(", "t", ".", "actions", ",", "&", "action", "{", "kind", ...
// command adds a command action to the transaction with the given args. // handler will be called with the reply from this specific command when // the transaction is executed.
[ "command", "adds", "a", "command", "action", "to", "the", "transaction", "with", "the", "given", "args", ".", "handler", "will", "be", "called", "with", "the", "reply", "from", "this", "specific", "command", "when", "the", "transaction", "is", "executed", "....
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L54-L61
123,362
albrow/jobs
transaction.go
script
func (t *transaction) script(script *redis.Script, args redis.Args, handler replyHandler) { t.actions = append(t.actions, &action{ kind: actionScript, script: script, args: args, handler: handler, }) }
go
func (t *transaction) script(script *redis.Script, args redis.Args, handler replyHandler) { t.actions = append(t.actions, &action{ kind: actionScript, script: script, args: args, handler: handler, }) }
[ "func", "(", "t", "*", "transaction", ")", "script", "(", "script", "*", "redis", ".", "Script", ",", "args", "redis", ".", "Args", ",", "handler", "replyHandler", ")", "{", "t", ".", "actions", "=", "append", "(", "t", ".", "actions", ",", "&", "a...
// command adds a script action to the transaction with the given args. // handler will be called with the reply from this specific script when // the transaction is executed.
[ "command", "adds", "a", "script", "action", "to", "the", "transaction", "with", "the", "given", "args", ".", "handler", "will", "be", "called", "with", "the", "reply", "from", "this", "specific", "script", "when", "the", "transaction", "is", "executed", "." ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L66-L73
123,363
albrow/jobs
transaction.go
exec
func (t *transaction) exec() error { // Return the connection to the pool when we are done defer t.conn.Close() if len(t.actions) == 1 { // If there is only one command, no need to use MULTI/EXEC a := t.actions[0] reply, err := t.doAction(a) if err != nil { return err } if a.handler != nil { if er...
go
func (t *transaction) exec() error { // Return the connection to the pool when we are done defer t.conn.Close() if len(t.actions) == 1 { // If there is only one command, no need to use MULTI/EXEC a := t.actions[0] reply, err := t.doAction(a) if err != nil { return err } if a.handler != nil { if er...
[ "func", "(", "t", "*", "transaction", ")", "exec", "(", ")", "error", "{", "// Return the connection to the pool when we are done", "defer", "t", ".", "conn", ".", "Close", "(", ")", "\n\n", "if", "len", "(", "t", ".", "actions", ")", "==", "1", "{", "//...
// exec executes the transaction, sequentially sending each action and // calling all the action handlers with the corresponding replies.
[ "exec", "executes", "the", "transaction", "sequentially", "sending", "each", "action", "and", "calling", "all", "the", "action", "handlers", "with", "the", "corresponding", "replies", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L100-L142
123,364
albrow/jobs
transaction.go
newScanJobsHandler
func newScanJobsHandler(jobs *[]*Job) replyHandler { return func(reply interface{}) error { values, err := redis.Values(reply, nil) if err != nil { return nil } for _, fields := range values { job := &Job{} if err := scanJob(fields, job); err != nil { return err } (*jobs) = append((*jobs), j...
go
func newScanJobsHandler(jobs *[]*Job) replyHandler { return func(reply interface{}) error { values, err := redis.Values(reply, nil) if err != nil { return nil } for _, fields := range values { job := &Job{} if err := scanJob(fields, job); err != nil { return err } (*jobs) = append((*jobs), j...
[ "func", "newScanJobsHandler", "(", "jobs", "*", "[", "]", "*", "Job", ")", "replyHandler", "{", "return", "func", "(", "reply", "interface", "{", "}", ")", "error", "{", "values", ",", "err", ":=", "redis", ".", "Values", "(", "reply", ",", "nil", ")...
// newScanJobsHandler returns a replyHandler which, when run, will scan the values // of reply into jobs.
[ "newScanJobsHandler", "returns", "a", "replyHandler", "which", "when", "run", "will", "scan", "the", "values", "of", "reply", "into", "jobs", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L154-L169
123,365
albrow/jobs
transaction.go
debugSet
func (t *transaction) debugSet(setName string) { t.command("ZRANGE", redis.Args{setName, 0, -1, "WITHSCORES"}, func(reply interface{}) error { vals, err := redis.Strings(reply, nil) if err != nil { return err } fmt.Printf("%s: %v\n", setName, vals) return nil }) }
go
func (t *transaction) debugSet(setName string) { t.command("ZRANGE", redis.Args{setName, 0, -1, "WITHSCORES"}, func(reply interface{}) error { vals, err := redis.Strings(reply, nil) if err != nil { return err } fmt.Printf("%s: %v\n", setName, vals) return nil }) }
[ "func", "(", "t", "*", "transaction", ")", "debugSet", "(", "setName", "string", ")", "{", "t", ".", "command", "(", "\"", "\"", ",", "redis", ".", "Args", "{", "setName", ",", "0", ",", "-", "1", ",", "\"", "\"", "}", ",", "func", "(", "reply"...
// debugSet simply prints out the value of the given set
[ "debugSet", "simply", "prints", "out", "the", "value", "of", "the", "given", "set" ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L172-L181
123,366
albrow/jobs
transaction.go
newScanStringsHandler
func newScanStringsHandler(strings *[]string) replyHandler { return func(reply interface{}) error { if strings == nil { return fmt.Errorf("jobs: Error in newScanStringsHandler: expected strings arg to be a pointer to a slice of strings but it was nil") } var err error (*strings), err = redis.Strings(reply, ...
go
func newScanStringsHandler(strings *[]string) replyHandler { return func(reply interface{}) error { if strings == nil { return fmt.Errorf("jobs: Error in newScanStringsHandler: expected strings arg to be a pointer to a slice of strings but it was nil") } var err error (*strings), err = redis.Strings(reply, ...
[ "func", "newScanStringsHandler", "(", "strings", "*", "[", "]", "string", ")", "replyHandler", "{", "return", "func", "(", "reply", "interface", "{", "}", ")", "error", "{", "if", "strings", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", ...
// newScanStringsHandler returns a replyHandler which, when run, will scan the values // of reply into strings.
[ "newScanStringsHandler", "returns", "a", "replyHandler", "which", "when", "run", "will", "scan", "the", "values", "of", "reply", "into", "strings", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L185-L197
123,367
albrow/jobs
transaction.go
newScanStringHandler
func newScanStringHandler(s *string) replyHandler { return func(reply interface{}) error { if s == nil { return fmt.Errorf("jobs: Error in newScanStringHandler: expected arg s to be a pointer to a string but it was nil") } var err error (*s), err = redis.String(reply, nil) if err != nil { return fmt.Er...
go
func newScanStringHandler(s *string) replyHandler { return func(reply interface{}) error { if s == nil { return fmt.Errorf("jobs: Error in newScanStringHandler: expected arg s to be a pointer to a string but it was nil") } var err error (*s), err = redis.String(reply, nil) if err != nil { return fmt.Er...
[ "func", "newScanStringHandler", "(", "s", "*", "string", ")", "replyHandler", "{", "return", "func", "(", "reply", "interface", "{", "}", ")", "error", "{", "if", "s", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}",...
// newScanStringHandler returns a replyHandler which, when run, will convert reply to a // string and scan it into s.
[ "newScanStringHandler", "returns", "a", "replyHandler", "which", "when", "run", "will", "convert", "reply", "to", "a", "string", "and", "scan", "it", "into", "s", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L201-L213
123,368
albrow/jobs
transaction.go
newScanIntHandler
func newScanIntHandler(i *int) replyHandler { return func(reply interface{}) error { if i == nil { return fmt.Errorf("jobs: Error in newScanIntHandler: expected arg s to be a pointer to a string but it was nil") } var err error (*i), err = redis.Int(reply, nil) if err != nil { return fmt.Errorf("jobs: ...
go
func newScanIntHandler(i *int) replyHandler { return func(reply interface{}) error { if i == nil { return fmt.Errorf("jobs: Error in newScanIntHandler: expected arg s to be a pointer to a string but it was nil") } var err error (*i), err = redis.Int(reply, nil) if err != nil { return fmt.Errorf("jobs: ...
[ "func", "newScanIntHandler", "(", "i", "*", "int", ")", "replyHandler", "{", "return", "func", "(", "reply", "interface", "{", "}", ")", "error", "{", "if", "i", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n...
// newScanIntHandler returns a replyHandler which, when run, will convert reply to a // int and scan it into i.
[ "newScanIntHandler", "returns", "a", "replyHandler", "which", "when", "run", "will", "convert", "reply", "to", "a", "int", "and", "scan", "it", "into", "i", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L217-L229
123,369
albrow/jobs
transaction.go
newScanBoolHandler
func newScanBoolHandler(b *bool) replyHandler { return func(reply interface{}) error { if b == nil { return fmt.Errorf("jobs: Error in newScanBoolHandler: expected arg v to be a pointer to a bool but it was nil") } var err error (*b), err = redis.Bool(reply, nil) if err != nil { return fmt.Errorf("jobs...
go
func newScanBoolHandler(b *bool) replyHandler { return func(reply interface{}) error { if b == nil { return fmt.Errorf("jobs: Error in newScanBoolHandler: expected arg v to be a pointer to a bool but it was nil") } var err error (*b), err = redis.Bool(reply, nil) if err != nil { return fmt.Errorf("jobs...
[ "func", "newScanBoolHandler", "(", "b", "*", "bool", ")", "replyHandler", "{", "return", "func", "(", "reply", "interface", "{", "}", ")", "error", "{", "if", "b", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "...
// newScanBoolHandler returns a replyHandler which, when run, will convert reply to a // bool and scan it into b.
[ "newScanBoolHandler", "returns", "a", "replyHandler", "which", "when", "run", "will", "convert", "reply", "to", "a", "bool", "and", "scan", "it", "into", "b", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L233-L245
123,370
albrow/jobs
transaction.go
retryOrFailJob
func (t *transaction) retryOrFailJob(job *Job, handler replyHandler) { t.script(retryOrFailJobScript, redis.Args{job.id}, handler) }
go
func (t *transaction) retryOrFailJob(job *Job, handler replyHandler) { t.script(retryOrFailJobScript, redis.Args{job.id}, handler) }
[ "func", "(", "t", "*", "transaction", ")", "retryOrFailJob", "(", "job", "*", "Job", ",", "handler", "replyHandler", ")", "{", "t", ".", "script", "(", "retryOrFailJobScript", ",", "redis", ".", "Args", "{", "job", ".", "id", "}", ",", "handler", ")", ...
// retryOrFailJob is a small function wrapper around retryOrFailJobScript. // It offers some type safety and helps make sure the arguments you pass through to the are correct. // The script will either mark the job as failed or queue it for retry depending on the number of // retries left.
[ "retryOrFailJob", "is", "a", "small", "function", "wrapper", "around", "retryOrFailJobScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "to", "the", "are", "correct", ".", "The...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L261-L263
123,371
albrow/jobs
transaction.go
setStatus
func (t *transaction) setStatus(job *Job, status Status) { t.script(setJobStatusScript, redis.Args{job.id, string(status)}, nil) }
go
func (t *transaction) setStatus(job *Job, status Status) { t.script(setJobStatusScript, redis.Args{job.id, string(status)}, nil) }
[ "func", "(", "t", "*", "transaction", ")", "setStatus", "(", "job", "*", "Job", ",", "status", "Status", ")", "{", "t", ".", "script", "(", "setJobStatusScript", ",", "redis", ".", "Args", "{", "job", ".", "id", ",", "string", "(", "status", ")", "...
// setStatus is a small function wrapper around setStatusScript. // It offers some type safety and helps make sure the arguments you pass through to the are correct. // The script will atomically update the status of the job, removing it from its old status set and // adding it to the new one.
[ "setStatus", "is", "a", "small", "function", "wrapper", "around", "setStatusScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "to", "the", "are", "correct", ".", "The", "scri...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L269-L271
123,372
albrow/jobs
transaction.go
destroyJob
func (t *transaction) destroyJob(job *Job) { t.script(destroyJobScript, redis.Args{job.id}, nil) }
go
func (t *transaction) destroyJob(job *Job) { t.script(destroyJobScript, redis.Args{job.id}, nil) }
[ "func", "(", "t", "*", "transaction", ")", "destroyJob", "(", "job", "*", "Job", ")", "{", "t", ".", "script", "(", "destroyJobScript", ",", "redis", ".", "Args", "{", "job", ".", "id", "}", ",", "nil", ")", "\n", "}" ]
// destroyJob is a small function wrapper around destroyJobScript. // It offers some type safety and helps make sure the arguments you pass through to the are correct. // The script will remove all records associated with job from the database.
[ "destroyJob", "is", "a", "small", "function", "wrapper", "around", "destroyJobScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "to", "the", "are", "correct", ".", "The", "sc...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L276-L278
123,373
albrow/jobs
transaction.go
purgeStalePool
func (t *transaction) purgeStalePool(poolId string) { t.script(purgeStalePoolScript, redis.Args{poolId}, nil) }
go
func (t *transaction) purgeStalePool(poolId string) { t.script(purgeStalePoolScript, redis.Args{poolId}, nil) }
[ "func", "(", "t", "*", "transaction", ")", "purgeStalePool", "(", "poolId", "string", ")", "{", "t", ".", "script", "(", "purgeStalePoolScript", ",", "redis", ".", "Args", "{", "poolId", "}", ",", "nil", ")", "\n", "}" ]
// purgeStalePool is a small function wrapper around purgeStalePoolScript. // It offers some type safety and helps make sure the arguments you pass through to the are correct. // The script will remove the stale pool from the active pools set, and then requeue any jobs associated // with the stale pool that are stuck i...
[ "purgeStalePool", "is", "a", "small", "function", "wrapper", "around", "purgeStalePoolScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "to", "the", "are", "correct", ".", "The...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L284-L286
123,374
albrow/jobs
transaction.go
getJobsByIds
func (t *transaction) getJobsByIds(setKey string, handler replyHandler) { t.script(getJobsByIdsScript, redis.Args{setKey}, handler) }
go
func (t *transaction) getJobsByIds(setKey string, handler replyHandler) { t.script(getJobsByIdsScript, redis.Args{setKey}, handler) }
[ "func", "(", "t", "*", "transaction", ")", "getJobsByIds", "(", "setKey", "string", ",", "handler", "replyHandler", ")", "{", "t", ".", "script", "(", "getJobsByIdsScript", ",", "redis", ".", "Args", "{", "setKey", "}", ",", "handler", ")", "\n", "}" ]
// getJobsByIds is a small function wrapper around getJobsByIdsScript. // It offers some type safety and helps make sure the arguments you pass through to the are correct. // The script will return all the fields for jobs which are identified by ids in the given sorted set. // You can use the handler to scan the jobs i...
[ "getJobsByIds", "is", "a", "small", "function", "wrapper", "around", "getJobsByIdsScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "to", "the", "are", "correct", ".", "The", ...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L292-L294
123,375
albrow/jobs
transaction.go
setJobField
func (t *transaction) setJobField(job *Job, fieldName string, fieldValue interface{}) { t.script(setJobFieldScript, redis.Args{job.id, fieldName, fieldValue}, nil) }
go
func (t *transaction) setJobField(job *Job, fieldName string, fieldValue interface{}) { t.script(setJobFieldScript, redis.Args{job.id, fieldName, fieldValue}, nil) }
[ "func", "(", "t", "*", "transaction", ")", "setJobField", "(", "job", "*", "Job", ",", "fieldName", "string", ",", "fieldValue", "interface", "{", "}", ")", "{", "t", ".", "script", "(", "setJobFieldScript", ",", "redis", ".", "Args", "{", "job", ".", ...
// setJobField is a small function wrapper around setJobFieldScript. // It offers some type safety and helps make sure the arguments you pass through are correct. // The script will set the given field to the given value iff the job exists and has not been // destroyed.
[ "setJobField", "is", "a", "small", "function", "wrapper", "around", "setJobFieldScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "are", "correct", ".", "The", "script", "will"...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L300-L302
123,376
albrow/jobs
transaction.go
addJobToSet
func (t *transaction) addJobToSet(job *Job, setName string, score float64) { t.script(addJobToSetScript, redis.Args{job.id, setName, score}, nil) }
go
func (t *transaction) addJobToSet(job *Job, setName string, score float64) { t.script(addJobToSetScript, redis.Args{job.id, setName, score}, nil) }
[ "func", "(", "t", "*", "transaction", ")", "addJobToSet", "(", "job", "*", "Job", ",", "setName", "string", ",", "score", "float64", ")", "{", "t", ".", "script", "(", "addJobToSetScript", ",", "redis", ".", "Args", "{", "job", ".", "id", ",", "setNa...
// addJobToSet is a small function wrapper around addJobToSetScript. // It offers some type safety and helps make sure the arguments you pass through are correct. // The script will add the job to the given set with the given score iff the job exists // and has not been destroyed.
[ "addJobToSet", "is", "a", "small", "function", "wrapper", "around", "addJobToSetScript", ".", "It", "offers", "some", "type", "safety", "and", "helps", "make", "sure", "the", "arguments", "you", "pass", "through", "are", "correct", ".", "The", "script", "will"...
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/transaction.go#L308-L310
123,377
albrow/jobs
scripts/generate.go
convertUnderscoresToCamelCase
func convertUnderscoresToCamelCase(s string) string { if len(s) == 0 { return "" } result := "" shouldUpper := false for _, char := range s { if char == '_' { shouldUpper = true continue } if shouldUpper { result += strings.ToUpper(string(char)) } else { result += string(char) } shouldUpp...
go
func convertUnderscoresToCamelCase(s string) string { if len(s) == 0 { return "" } result := "" shouldUpper := false for _, char := range s { if char == '_' { shouldUpper = true continue } if shouldUpper { result += strings.ToUpper(string(char)) } else { result += string(char) } shouldUpp...
[ "func", "convertUnderscoresToCamelCase", "(", "s", "string", ")", "string", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "result", ":=", "\"", "\"", "\n", "shouldUpper", ":=", "false", "\n", "for", "_", ",",...
// convertUnderscoresToCamelCase converts a string of the form // foo_bar_baz to fooBarBaz.
[ "convertUnderscoresToCamelCase", "converts", "a", "string", "of", "the", "form", "foo_bar_baz", "to", "fooBarBaz", "." ]
2580c613deb47dce29730c128a5dee775f552a1d
https://github.com/albrow/jobs/blob/2580c613deb47dce29730c128a5dee775f552a1d/scripts/generate.go#L117-L136
123,378
mdlayher/ethernet
cmd/etherecho/main.go
sendMessages
func sendMessages(c net.PacketConn, source net.HardwareAddr, msg string) { // Message is broadcast to all machines in same network segment. f := &ethernet.Frame{ Destination: ethernet.Broadcast, Source: source, EtherType: etherType, Payload: []byte(msg), } b, err := f.MarshalBinary() if err != ...
go
func sendMessages(c net.PacketConn, source net.HardwareAddr, msg string) { // Message is broadcast to all machines in same network segment. f := &ethernet.Frame{ Destination: ethernet.Broadcast, Source: source, EtherType: etherType, Payload: []byte(msg), } b, err := f.MarshalBinary() if err != ...
[ "func", "sendMessages", "(", "c", "net", ".", "PacketConn", ",", "source", "net", ".", "HardwareAddr", ",", "msg", "string", ")", "{", "// Message is broadcast to all machines in same network segment.", "f", ":=", "&", "ethernet", ".", "Frame", "{", "Destination", ...
// sendMessages continuously sends a message over a connection at regular intervals, // sourced from specified hardware address.
[ "sendMessages", "continuously", "sends", "a", "message", "over", "a", "connection", "at", "regular", "intervals", "sourced", "from", "specified", "hardware", "address", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/cmd/etherecho/main.go#L62-L89
123,379
mdlayher/ethernet
cmd/etherecho/main.go
receiveMessages
func receiveMessages(c net.PacketConn, mtu int) { var f ethernet.Frame b := make([]byte, mtu) // Keep receiving messages forever. for { n, addr, err := c.ReadFrom(b) if err != nil { log.Fatalf("failed to receive message: %v", err) } // Unpack Ethernet II frame into Go representation. if err := (&f).U...
go
func receiveMessages(c net.PacketConn, mtu int) { var f ethernet.Frame b := make([]byte, mtu) // Keep receiving messages forever. for { n, addr, err := c.ReadFrom(b) if err != nil { log.Fatalf("failed to receive message: %v", err) } // Unpack Ethernet II frame into Go representation. if err := (&f).U...
[ "func", "receiveMessages", "(", "c", "net", ".", "PacketConn", ",", "mtu", "int", ")", "{", "var", "f", "ethernet", ".", "Frame", "\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "mtu", ")", "\n\n", "// Keep receiving messages forever.", "for", "{", ...
// receiveMessages continuously receives messages over a connection. The messages // may be up to the interface's MTU in size.
[ "receiveMessages", "continuously", "receives", "messages", "over", "a", "connection", ".", "The", "messages", "may", "be", "up", "to", "the", "interface", "s", "MTU", "in", "size", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/cmd/etherecho/main.go#L93-L112
123,380
mdlayher/ethernet
vlan.go
MarshalBinary
func (v *VLAN) MarshalBinary() ([]byte, error) { b := make([]byte, 2) _, err := v.read(b) return b, err }
go
func (v *VLAN) MarshalBinary() ([]byte, error) { b := make([]byte, 2) _, err := v.read(b) return b, err }
[ "func", "(", "v", "*", "VLAN", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "2", ")", "\n", "_", ",", "err", ":=", "v", ".", "read", "(", "b", ")", "\n", "re...
// MarshalBinary allocates a byte slice and marshals a VLAN into binary form.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "and", "marshals", "a", "VLAN", "into", "binary", "form", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/vlan.go#L72-L76
123,381
mdlayher/ethernet
vlan.go
read
func (v *VLAN) read(b []byte) (int, error) { // Check for VLAN priority in valid range if v.Priority > PriorityNetworkControl { return 0, ErrInvalidVLAN } // Check for VLAN ID in valid range if v.ID >= VLANMax { return 0, ErrInvalidVLAN } // 3 bits: priority ub := uint16(v.Priority) << 13 // 1 bit: drop...
go
func (v *VLAN) read(b []byte) (int, error) { // Check for VLAN priority in valid range if v.Priority > PriorityNetworkControl { return 0, ErrInvalidVLAN } // Check for VLAN ID in valid range if v.ID >= VLANMax { return 0, ErrInvalidVLAN } // 3 bits: priority ub := uint16(v.Priority) << 13 // 1 bit: drop...
[ "func", "(", "v", "*", "VLAN", ")", "read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "// Check for VLAN priority in valid range", "if", "v", ".", "Priority", ">", "PriorityNetworkControl", "{", "return", "0", ",", "ErrInvalidVLA...
// read reads data from a VLAN into b. read is used to marshal a VLAN into // binary form, but does not allocate on its own.
[ "read", "reads", "data", "from", "a", "VLAN", "into", "b", ".", "read", "is", "used", "to", "marshal", "a", "VLAN", "into", "binary", "form", "but", "does", "not", "allocate", "on", "its", "own", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/vlan.go#L80-L106
123,382
mdlayher/ethernet
vlan.go
UnmarshalBinary
func (v *VLAN) UnmarshalBinary(b []byte) error { // VLAN tag is always 2 bytes if len(b) != 2 { return io.ErrUnexpectedEOF } // 3 bits: priority // 1 bit : drop eligible // 12 bits: VLAN ID ub := binary.BigEndian.Uint16(b[0:2]) v.Priority = Priority(uint8(ub >> 13)) v.DropEligible = ub&0x1000 != 0 v.ID =...
go
func (v *VLAN) UnmarshalBinary(b []byte) error { // VLAN tag is always 2 bytes if len(b) != 2 { return io.ErrUnexpectedEOF } // 3 bits: priority // 1 bit : drop eligible // 12 bits: VLAN ID ub := binary.BigEndian.Uint16(b[0:2]) v.Priority = Priority(uint8(ub >> 13)) v.DropEligible = ub&0x1000 != 0 v.ID =...
[ "func", "(", "v", "*", "VLAN", ")", "UnmarshalBinary", "(", "b", "[", "]", "byte", ")", "error", "{", "// VLAN tag is always 2 bytes", "if", "len", "(", "b", ")", "!=", "2", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n", "// 3 bits: pr...
// UnmarshalBinary unmarshals a byte slice into a VLAN.
[ "UnmarshalBinary", "unmarshals", "a", "byte", "slice", "into", "a", "VLAN", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/vlan.go#L109-L129
123,383
mdlayher/ethernet
ethernet.go
MarshalBinary
func (f *Frame) MarshalBinary() ([]byte, error) { b := make([]byte, f.length()) _, err := f.read(b) return b, err }
go
func (f *Frame) MarshalBinary() ([]byte, error) { b := make([]byte, f.length()) _, err := f.read(b) return b, err }
[ "func", "(", "f", "*", "Frame", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "f", ".", "length", "(", ")", ")", "\n", "_", ",", "err", ":=", "f", ".", "read", ...
// MarshalBinary allocates a byte slice and marshals a Frame into binary form.
[ "MarshalBinary", "allocates", "a", "byte", "slice", "and", "marshals", "a", "Frame", "into", "binary", "form", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L90-L94
123,384
mdlayher/ethernet
ethernet.go
MarshalFCS
func (f *Frame) MarshalFCS() ([]byte, error) { // Frame length with 4 extra bytes for frame check sequence b := make([]byte, f.length()+4) if _, err := f.read(b); err != nil { return nil, err } // Compute IEEE CRC32 checksum of frame bytes and place it directly // in the last four bytes of the slice binary.Bi...
go
func (f *Frame) MarshalFCS() ([]byte, error) { // Frame length with 4 extra bytes for frame check sequence b := make([]byte, f.length()+4) if _, err := f.read(b); err != nil { return nil, err } // Compute IEEE CRC32 checksum of frame bytes and place it directly // in the last four bytes of the slice binary.Bi...
[ "func", "(", "f", "*", "Frame", ")", "MarshalFCS", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Frame length with 4 extra bytes for frame check sequence", "b", ":=", "make", "(", "[", "]", "byte", ",", "f", ".", "length", "(", ")", "+", ...
// MarshalFCS allocates a byte slice, marshals a Frame into binary form, and // finally calculates and places a 4-byte IEEE CRC32 frame check sequence at // the end of the slice. // // Most users should use MarshalBinary instead. MarshalFCS is provided as a // convenience for rare occasions when the operating system c...
[ "MarshalFCS", "allocates", "a", "byte", "slice", "marshals", "a", "Frame", "into", "binary", "form", "and", "finally", "calculates", "and", "places", "a", "4", "-", "byte", "IEEE", "CRC32", "frame", "check", "sequence", "at", "the", "end", "of", "the", "sl...
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L103-L114
123,385
mdlayher/ethernet
ethernet.go
read
func (f *Frame) read(b []byte) (int, error) { // S-VLAN must also have accompanying C-VLAN. if f.ServiceVLAN != nil && f.VLAN == nil { return 0, ErrInvalidVLAN } copy(b[0:6], f.Destination) copy(b[6:12], f.Source) // Marshal each non-nil VLAN tag into bytes, inserting the appropriate // EtherType/TPID before...
go
func (f *Frame) read(b []byte) (int, error) { // S-VLAN must also have accompanying C-VLAN. if f.ServiceVLAN != nil && f.VLAN == nil { return 0, ErrInvalidVLAN } copy(b[0:6], f.Destination) copy(b[6:12], f.Source) // Marshal each non-nil VLAN tag into bytes, inserting the appropriate // EtherType/TPID before...
[ "func", "(", "f", "*", "Frame", ")", "read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "// S-VLAN must also have accompanying C-VLAN.", "if", "f", ".", "ServiceVLAN", "!=", "nil", "&&", "f", ".", "VLAN", "==", "nil", "{", "...
// read reads data from a Frame into b. read is used to marshal a Frame // into binary form, but does not allocate on its own.
[ "read", "reads", "data", "from", "a", "Frame", "into", "b", ".", "read", "is", "used", "to", "marshal", "a", "Frame", "into", "binary", "form", "but", "does", "not", "allocate", "on", "its", "own", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L118-L158
123,386
mdlayher/ethernet
ethernet.go
UnmarshalBinary
func (f *Frame) UnmarshalBinary(b []byte) error { // Verify that both hardware addresses and a single EtherType are present if len(b) < 14 { return io.ErrUnexpectedEOF } // Track offset in packet for reading data n := 14 // Continue looping and parsing VLAN tags until no more VLAN EtherType // values are det...
go
func (f *Frame) UnmarshalBinary(b []byte) error { // Verify that both hardware addresses and a single EtherType are present if len(b) < 14 { return io.ErrUnexpectedEOF } // Track offset in packet for reading data n := 14 // Continue looping and parsing VLAN tags until no more VLAN EtherType // values are det...
[ "func", "(", "f", "*", "Frame", ")", "UnmarshalBinary", "(", "b", "[", "]", "byte", ")", "error", "{", "// Verify that both hardware addresses and a single EtherType are present", "if", "len", "(", "b", ")", "<", "14", "{", "return", "io", ".", "ErrUnexpectedEOF...
// UnmarshalBinary unmarshals a byte slice into a Frame.
[ "UnmarshalBinary", "unmarshals", "a", "byte", "slice", "into", "a", "Frame", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L161-L204
123,387
mdlayher/ethernet
ethernet.go
UnmarshalFCS
func (f *Frame) UnmarshalFCS(b []byte) error { // Must contain enough data for FCS, to avoid panics if len(b) < 4 { return io.ErrUnexpectedEOF } // Verify checksum in slice versus newly computed checksum want := binary.BigEndian.Uint32(b[len(b)-4:]) got := crc32.ChecksumIEEE(b[0 : len(b)-4]) if want != got { ...
go
func (f *Frame) UnmarshalFCS(b []byte) error { // Must contain enough data for FCS, to avoid panics if len(b) < 4 { return io.ErrUnexpectedEOF } // Verify checksum in slice versus newly computed checksum want := binary.BigEndian.Uint32(b[len(b)-4:]) got := crc32.ChecksumIEEE(b[0 : len(b)-4]) if want != got { ...
[ "func", "(", "f", "*", "Frame", ")", "UnmarshalFCS", "(", "b", "[", "]", "byte", ")", "error", "{", "// Must contain enough data for FCS, to avoid panics", "if", "len", "(", "b", ")", "<", "4", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n\n...
// UnmarshalFCS computes the IEEE CRC32 frame check sequence of a Frame, // verifies it against the checksum present in the byte slice, and finally, // unmarshals a byte slice into a Frame. // // Most users should use UnmarshalBinary instead. UnmarshalFCS is provided as // a convenience for rare occasions when the ope...
[ "UnmarshalFCS", "computes", "the", "IEEE", "CRC32", "frame", "check", "sequence", "of", "a", "Frame", "verifies", "it", "against", "the", "checksum", "present", "in", "the", "byte", "slice", "and", "finally", "unmarshals", "a", "byte", "slice", "into", "a", ...
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L213-L227
123,388
mdlayher/ethernet
ethernet.go
length
func (f *Frame) length() int { // If payload is less than the required minimum length, we zero-pad up to // the required minimum length pl := len(f.Payload) if pl < minPayload { pl = minPayload } // Add additional length if VLAN tags are needed. var vlanLen int switch { case f.ServiceVLAN != nil && f.VLAN !...
go
func (f *Frame) length() int { // If payload is less than the required minimum length, we zero-pad up to // the required minimum length pl := len(f.Payload) if pl < minPayload { pl = minPayload } // Add additional length if VLAN tags are needed. var vlanLen int switch { case f.ServiceVLAN != nil && f.VLAN !...
[ "func", "(", "f", "*", "Frame", ")", "length", "(", ")", "int", "{", "// If payload is less than the required minimum length, we zero-pad up to", "// the required minimum length", "pl", ":=", "len", "(", "f", ".", "Payload", ")", "\n", "if", "pl", "<", "minPayload",...
// length calculates the number of bytes required to store a Frame.
[ "length", "calculates", "the", "number", "of", "bytes", "required", "to", "store", "a", "Frame", "." ]
5b5fc417d966b71d3781b0d5860413e9fae947c1
https://github.com/mdlayher/ethernet/blob/5b5fc417d966b71d3781b0d5860413e9fae947c1/ethernet.go#L230-L253
123,389
grafana-tools/sdk
rest-user.go
GetActualUser
func (r *Client) GetActualUser() (User, error) { var ( raw []byte user User code int err error ) if raw, code, err = r.get("api/user", nil); err != nil { return user, err } if code != 200 { return user, fmt.Errorf("HTTP error %d: returns %s", code, raw) } dec := json.NewDecoder(bytes.NewReader(raw)...
go
func (r *Client) GetActualUser() (User, error) { var ( raw []byte user User code int err error ) if raw, code, err = r.get("api/user", nil); err != nil { return user, err } if code != 200 { return user, fmt.Errorf("HTTP error %d: returns %s", code, raw) } dec := json.NewDecoder(bytes.NewReader(raw)...
[ "func", "(", "r", "*", "Client", ")", "GetActualUser", "(", ")", "(", "User", ",", "error", ")", "{", "var", "(", "raw", "[", "]", "byte", "\n", "user", "User", "\n", "code", "int", "\n", "err", "error", "\n", ")", "\n", "if", "raw", ",", "code...
// GetActualUser gets an actual user.
[ "GetActualUser", "gets", "an", "actual", "user", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/rest-user.go#L29-L48
123,390
grafana-tools/sdk
panel.go
NewDashlist
func NewDashlist(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: DashlistType, Title: title, Type: "dashlist", Renderer: &render, IsNew: true}, DashlistPanel: &DashlistPanel{}} }
go
func NewDashlist(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: DashlistType, Title: title, Type: "dashlist", Renderer: &render, IsNew: true}, DashlistPanel: &DashlistPanel{}} }
[ "func", "NewDashlist", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel", ...
// NewDashlist initializes panel with a dashlist panel.
[ "NewDashlist", "initializes", "panel", "with", "a", "dashlist", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L400-L413
123,391
grafana-tools/sdk
panel.go
NewGraph
func NewGraph(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: GraphType, Title: title, Type: "graph", Renderer: &render, Span: 12, IsNew: true}, GraphPanel: &GraphPanel{ NullPointMode: "conne...
go
func NewGraph(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: GraphType, Title: title, Type: "graph", Renderer: &render, Span: 12, IsNew: true}, GraphPanel: &GraphPanel{ NullPointMode: "conne...
[ "func", "NewGraph", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel", "...
// NewGraph initializes panel with a graph panel.
[ "NewGraph", "initializes", "panel", "with", "a", "graph", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L416-L435
123,392
grafana-tools/sdk
panel.go
NewTable
func NewTable(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: TableType, Title: title, Type: "table", Renderer: &render, IsNew: true}, TablePanel: &TablePanel{}} }
go
func NewTable(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: TableType, Title: title, Type: "table", Renderer: &render, IsNew: true}, TablePanel: &TablePanel{}} }
[ "func", "NewTable", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel", "...
// NewTable initializes panel with a table panel.
[ "NewTable", "initializes", "panel", "with", "a", "table", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L438-L451
123,393
grafana-tools/sdk
panel.go
NewText
func NewText(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: TextType, Title: title, Type: "text", Renderer: &render, IsNew: true}, TextPanel: &TextPanel{}} }
go
func NewText(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: TextType, Title: title, Type: "text", Renderer: &render, IsNew: true}, TextPanel: &TextPanel{}} }
[ "func", "NewText", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel", "{...
// NewText initializes panel with a text panel.
[ "NewText", "initializes", "panel", "with", "a", "text", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L454-L467
123,394
grafana-tools/sdk
panel.go
NewSinglestat
func NewSinglestat(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: SinglestatType, Title: title, Type: "singlestat", Renderer: &render, IsNew: true}, SinglestatPanel: &SinglestatPanel{}} }
go
func NewSinglestat(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: SinglestatType, Title: title, Type: "singlestat", Renderer: &render, IsNew: true}, SinglestatPanel: &SinglestatPanel{}} }
[ "func", "NewSinglestat", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel"...
// NewSinglestat initializes panel with a singlestat panel.
[ "NewSinglestat", "initializes", "panel", "with", "a", "singlestat", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L470-L483
123,395
grafana-tools/sdk
panel.go
NewPluginlist
func NewPluginlist(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: PluginlistType, Title: title, Type: "pluginlist", Renderer: &render, IsNew: true}, PluginlistPanel: &PluginlistPanel{}} }
go
func NewPluginlist(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: PluginlistType, Title: title, Type: "pluginlist", Renderer: &render, IsNew: true}, PluginlistPanel: &PluginlistPanel{}} }
[ "func", "NewPluginlist", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel"...
// NewPluginlist initializes panel with a singlestat panel.
[ "NewPluginlist", "initializes", "panel", "with", "a", "singlestat", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L486-L499
123,396
grafana-tools/sdk
panel.go
NewCustom
func NewCustom(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: CustomType, Title: title, Type: "singlestat", Renderer: &render, IsNew: true}, CustomPanel: &CustomPanel{}} }
go
func NewCustom(title string) *Panel { if title == "" { title = "Panel Title" } render := "flot" return &Panel{ commonPanel: commonPanel{ OfType: CustomType, Title: title, Type: "singlestat", Renderer: &render, IsNew: true}, CustomPanel: &CustomPanel{}} }
[ "func", "NewCustom", "(", "title", "string", ")", "*", "Panel", "{", "if", "title", "==", "\"", "\"", "{", "title", "=", "\"", "\"", "\n", "}", "\n", "render", ":=", "\"", "\"", "\n", "return", "&", "Panel", "{", "commonPanel", ":", "commonPanel", ...
// NewCustom initializes panel with a singlestat panel.
[ "NewCustom", "initializes", "panel", "with", "a", "singlestat", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L517-L530
123,397
grafana-tools/sdk
panel.go
ResetTargets
func (p *Panel) ResetTargets() { switch p.OfType { case GraphType: p.GraphPanel.Targets = nil case SinglestatType: p.SinglestatPanel.Targets = nil case TableType: p.TablePanel.Targets = nil } }
go
func (p *Panel) ResetTargets() { switch p.OfType { case GraphType: p.GraphPanel.Targets = nil case SinglestatType: p.SinglestatPanel.Targets = nil case TableType: p.TablePanel.Targets = nil } }
[ "func", "(", "p", "*", "Panel", ")", "ResetTargets", "(", ")", "{", "switch", "p", ".", "OfType", "{", "case", "GraphType", ":", "p", ".", "GraphPanel", ".", "Targets", "=", "nil", "\n", "case", "SinglestatType", ":", "p", ".", "SinglestatPanel", ".", ...
// ResetTargets delete all targets defined for a panel.
[ "ResetTargets", "delete", "all", "targets", "defined", "for", "a", "panel", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L533-L542
123,398
grafana-tools/sdk
panel.go
AddTarget
func (p *Panel) AddTarget(t *Target) { switch p.OfType { case GraphType: p.GraphPanel.Targets = append(p.GraphPanel.Targets, *t) case SinglestatType: p.SinglestatPanel.Targets = append(p.SinglestatPanel.Targets, *t) case TableType: p.TablePanel.Targets = append(p.TablePanel.Targets, *t) } // TODO check for ...
go
func (p *Panel) AddTarget(t *Target) { switch p.OfType { case GraphType: p.GraphPanel.Targets = append(p.GraphPanel.Targets, *t) case SinglestatType: p.SinglestatPanel.Targets = append(p.SinglestatPanel.Targets, *t) case TableType: p.TablePanel.Targets = append(p.TablePanel.Targets, *t) } // TODO check for ...
[ "func", "(", "p", "*", "Panel", ")", "AddTarget", "(", "t", "*", "Target", ")", "{", "switch", "p", ".", "OfType", "{", "case", "GraphType", ":", "p", ".", "GraphPanel", ".", "Targets", "=", "append", "(", "p", ".", "GraphPanel", ".", "Targets", ",...
// AddTarget adds a new target as defined in the argument // but with refId letter incremented. Value of refID from // the argument will be used only if no target with such // value already exists.
[ "AddTarget", "adds", "a", "new", "target", "as", "defined", "in", "the", "argument", "but", "with", "refId", "letter", "incremented", ".", "Value", "of", "refID", "from", "the", "argument", "will", "be", "used", "only", "if", "no", "target", "with", "such"...
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L548-L558
123,399
grafana-tools/sdk
panel.go
SetTarget
func (p *Panel) SetTarget(t *Target) { setTarget := func(t *Target, targets *[]Target) { for i, target := range *targets { if t.RefID == target.RefID { (*targets)[i] = *t return } } (*targets) = append((*targets), *t) } switch p.OfType { case GraphType: setTarget(t, &p.GraphPanel.Targets) cas...
go
func (p *Panel) SetTarget(t *Target) { setTarget := func(t *Target, targets *[]Target) { for i, target := range *targets { if t.RefID == target.RefID { (*targets)[i] = *t return } } (*targets) = append((*targets), *t) } switch p.OfType { case GraphType: setTarget(t, &p.GraphPanel.Targets) cas...
[ "func", "(", "p", "*", "Panel", ")", "SetTarget", "(", "t", "*", "Target", ")", "{", "setTarget", ":=", "func", "(", "t", "*", "Target", ",", "targets", "*", "[", "]", "Target", ")", "{", "for", "i", ",", "target", ":=", "range", "*", "targets", ...
// SetTarget updates a target if target with such refId exists // or creates a new one.
[ "SetTarget", "updates", "a", "target", "if", "target", "with", "such", "refId", "exists", "or", "creates", "a", "new", "one", "." ]
5158161510f07142e96b0c3d4be124b47fe2c070
https://github.com/grafana-tools/sdk/blob/5158161510f07142e96b0c3d4be124b47fe2c070/panel.go#L562-L580