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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
12,900
influxdata/platform
tsdb/tsm1/ring.go
getPartition
func (r *ring) getPartition(key []byte) *partition { return r.partitions[int(xxhash.Sum64(key)%partitions)] }
go
func (r *ring) getPartition(key []byte) *partition { return r.partitions[int(xxhash.Sum64(key)%partitions)] }
[ "func", "(", "r", "*", "ring", ")", "getPartition", "(", "key", "[", "]", "byte", ")", "*", "partition", "{", "return", "r", ".", "partitions", "[", "int", "(", "xxhash", ".", "Sum64", "(", "key", ")", "%", "partitions", ")", "]", "\n", "}" ]
// getPartition retrieves the hash ring partition associated with the provided // key.
[ "getPartition", "retrieves", "the", "hash", "ring", "partition", "associated", "with", "the", "provided", "key", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/ring.go#L86-L88
12,901
influxdata/platform
inmem/organization_service.go
FindOrganization
func (s *Service) FindOrganization(ctx context.Context, filter platform.OrganizationFilter) (*platform.Organization, error) { op := OpPrefix + platform.OpFindOrganization if filter.ID == nil && filter.Name == nil { return nil, &platform.Error{ Code: platform.EInvalid, Op: op, Msg: "no filter parameters provided", } } if filter.ID != nil { o, err := s.FindOrganizationByID(ctx, *filter.ID) if err != nil { return nil, &platform.Error{ Op: op, Err: err, } } return o, nil } orgs, n, err := s.FindOrganizations(ctx, filter) if err != nil { return nil, &platform.Error{ Op: op, Err: err, } } if n < 1 { return nil, &platform.Error{ Code: platform.ENotFound, Op: op, Msg: errOrganizationNotFound, } } return orgs[0], nil }
go
func (s *Service) FindOrganization(ctx context.Context, filter platform.OrganizationFilter) (*platform.Organization, error) { op := OpPrefix + platform.OpFindOrganization if filter.ID == nil && filter.Name == nil { return nil, &platform.Error{ Code: platform.EInvalid, Op: op, Msg: "no filter parameters provided", } } if filter.ID != nil { o, err := s.FindOrganizationByID(ctx, *filter.ID) if err != nil { return nil, &platform.Error{ Op: op, Err: err, } } return o, nil } orgs, n, err := s.FindOrganizations(ctx, filter) if err != nil { return nil, &platform.Error{ Op: op, Err: err, } } if n < 1 { return nil, &platform.Error{ Code: platform.ENotFound, Op: op, Msg: errOrganizationNotFound, } } return orgs[0], nil }
[ "func", "(", "s", "*", "Service", ")", "FindOrganization", "(", "ctx", "context", ".", "Context", ",", "filter", "platform", ".", "OrganizationFilter", ")", "(", "*", "platform", ".", "Organization", ",", "error", ")", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpFindOrganization", "\n", "if", "filter", ".", "ID", "==", "nil", "&&", "filter", ".", "Name", "==", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "EInvalid", ",", "Op", ":", "op", ",", "Msg", ":", "\"", "\"", ",", "}", "\n", "}", "\n\n", "if", "filter", ".", "ID", "!=", "nil", "{", "o", ",", "err", ":=", "s", ".", "FindOrganizationByID", "(", "ctx", ",", "*", "filter", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n", "return", "o", ",", "nil", "\n", "}", "\n\n", "orgs", ",", "n", ",", "err", ":=", "s", ".", "FindOrganizations", "(", "ctx", ",", "filter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n", "if", "n", "<", "1", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "ENotFound", ",", "Op", ":", "op", ",", "Msg", ":", "errOrganizationNotFound", ",", "}", "\n", "}", "\n\n", "return", "orgs", "[", "0", "]", ",", "nil", "\n", "}" ]
// FindOrganization returns the first organization that matches a filter.
[ "FindOrganization", "returns", "the", "first", "organization", "that", "matches", "a", "filter", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/organization_service.go#L79-L116
12,902
influxdata/platform
inmem/organization_service.go
FindOrganizations
func (s *Service) FindOrganizations(ctx context.Context, filter platform.OrganizationFilter, opt ...platform.FindOptions) ([]*platform.Organization, int, error) { op := OpPrefix + platform.OpFindOrganizations if filter.ID != nil { o, err := s.FindOrganizationByID(ctx, *filter.ID) if err != nil { return nil, 0, &platform.Error{ Op: op, Err: err, } } return []*platform.Organization{o}, 1, nil } filterFunc := func(o *platform.Organization) bool { return true } if filter.Name != nil { filterFunc = func(o *platform.Organization) bool { return o.Name == *filter.Name } } orgs, pe := s.filterOrganizations(ctx, filterFunc) if pe != nil { return nil, 0, &platform.Error{ Err: pe, Op: op, } } if len(orgs) == 0 { return orgs, 0, &platform.Error{ Code: platform.ENotFound, Op: op, Msg: errOrganizationNotFound, } } return orgs, len(orgs), nil }
go
func (s *Service) FindOrganizations(ctx context.Context, filter platform.OrganizationFilter, opt ...platform.FindOptions) ([]*platform.Organization, int, error) { op := OpPrefix + platform.OpFindOrganizations if filter.ID != nil { o, err := s.FindOrganizationByID(ctx, *filter.ID) if err != nil { return nil, 0, &platform.Error{ Op: op, Err: err, } } return []*platform.Organization{o}, 1, nil } filterFunc := func(o *platform.Organization) bool { return true } if filter.Name != nil { filterFunc = func(o *platform.Organization) bool { return o.Name == *filter.Name } } orgs, pe := s.filterOrganizations(ctx, filterFunc) if pe != nil { return nil, 0, &platform.Error{ Err: pe, Op: op, } } if len(orgs) == 0 { return orgs, 0, &platform.Error{ Code: platform.ENotFound, Op: op, Msg: errOrganizationNotFound, } } return orgs, len(orgs), nil }
[ "func", "(", "s", "*", "Service", ")", "FindOrganizations", "(", "ctx", "context", ".", "Context", ",", "filter", "platform", ".", "OrganizationFilter", ",", "opt", "...", "platform", ".", "FindOptions", ")", "(", "[", "]", "*", "platform", ".", "Organization", ",", "int", ",", "error", ")", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpFindOrganizations", "\n", "if", "filter", ".", "ID", "!=", "nil", "{", "o", ",", "err", ":=", "s", ".", "FindOrganizationByID", "(", "ctx", ",", "*", "filter", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "return", "[", "]", "*", "platform", ".", "Organization", "{", "o", "}", ",", "1", ",", "nil", "\n", "}", "\n\n", "filterFunc", ":=", "func", "(", "o", "*", "platform", ".", "Organization", ")", "bool", "{", "return", "true", "}", "\n", "if", "filter", ".", "Name", "!=", "nil", "{", "filterFunc", "=", "func", "(", "o", "*", "platform", ".", "Organization", ")", "bool", "{", "return", "o", ".", "Name", "==", "*", "filter", ".", "Name", "\n", "}", "\n", "}", "\n\n", "orgs", ",", "pe", ":=", "s", ".", "filterOrganizations", "(", "ctx", ",", "filterFunc", ")", "\n", "if", "pe", "!=", "nil", "{", "return", "nil", ",", "0", ",", "&", "platform", ".", "Error", "{", "Err", ":", "pe", ",", "Op", ":", "op", ",", "}", "\n", "}", "\n\n", "if", "len", "(", "orgs", ")", "==", "0", "{", "return", "orgs", ",", "0", ",", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "ENotFound", ",", "Op", ":", "op", ",", "Msg", ":", "errOrganizationNotFound", ",", "}", "\n", "}", "\n\n", "return", "orgs", ",", "len", "(", "orgs", ")", ",", "nil", "\n", "}" ]
// FindOrganizations returns a list of organizations that match filter and the total count of matching organizations.
[ "FindOrganizations", "returns", "a", "list", "of", "organizations", "that", "match", "filter", "and", "the", "total", "count", "of", "matching", "organizations", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/organization_service.go#L119-L157
12,903
influxdata/platform
zap/auth_service.go
SetAuthorizationStatus
func (s *AuthorizationService) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) (err error) { defer func() { if err != nil { s.Logger.Info("error updating authorization", zap.Error(err)) } }() return s.AuthorizationService.SetAuthorizationStatus(ctx, id, status) }
go
func (s *AuthorizationService) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) (err error) { defer func() { if err != nil { s.Logger.Info("error updating authorization", zap.Error(err)) } }() return s.AuthorizationService.SetAuthorizationStatus(ctx, id, status) }
[ "func", "(", "s", "*", "AuthorizationService", ")", "SetAuthorizationStatus", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "status", "platform", ".", "Status", ")", "(", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "s", ".", "Logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "s", ".", "AuthorizationService", ".", "SetAuthorizationStatus", "(", "ctx", ",", "id", ",", "status", ")", "\n", "}" ]
// SetAuthorizationStatus updates an authorization's status and logs any errors.
[ "SetAuthorizationStatus", "updates", "an", "authorization", "s", "status", "and", "logs", "any", "errors", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/zap/auth_service.go#L75-L83
12,904
influxdata/platform
tsdb/tsm1/bool.go
Write
func (e *BooleanEncoder) Write(b bool) { // If we have filled the current byte, flush it if e.i >= 8 { e.flush() } // Use 1 bit for each boolean value, shift the current byte // by 1 and set the least signficant bit acordingly e.b = e.b << 1 if b { e.b |= 1 } // Increment the current boolean count e.i++ // Increment the total boolean count e.n++ }
go
func (e *BooleanEncoder) Write(b bool) { // If we have filled the current byte, flush it if e.i >= 8 { e.flush() } // Use 1 bit for each boolean value, shift the current byte // by 1 and set the least signficant bit acordingly e.b = e.b << 1 if b { e.b |= 1 } // Increment the current boolean count e.i++ // Increment the total boolean count e.n++ }
[ "func", "(", "e", "*", "BooleanEncoder", ")", "Write", "(", "b", "bool", ")", "{", "// If we have filled the current byte, flush it", "if", "e", ".", "i", ">=", "8", "{", "e", ".", "flush", "(", ")", "\n", "}", "\n\n", "// Use 1 bit for each boolean value, shift the current byte", "// by 1 and set the least signficant bit acordingly", "e", ".", "b", "=", "e", ".", "b", "<<", "1", "\n", "if", "b", "{", "e", ".", "b", "|=", "1", "\n", "}", "\n\n", "// Increment the current boolean count", "e", ".", "i", "++", "\n", "// Increment the total boolean count", "e", ".", "n", "++", "\n", "}" ]
// Write encodes b to the underlying buffer.
[ "Write", "encodes", "b", "to", "the", "underlying", "buffer", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/bool.go#L48-L65
12,905
influxdata/platform
cmd/influxd/launcher/launcher.go
Shutdown
func (m *Launcher) Shutdown(ctx context.Context) { m.httpServer.Shutdown(ctx) m.logger.Info("Stopping", zap.String("service", "task")) m.scheduler.Stop() m.logger.Info("Stopping", zap.String("service", "nats")) m.natsServer.Close() m.logger.Info("Stopping", zap.String("service", "bolt")) if err := m.boltClient.Close(); err != nil { m.logger.Info("failed closing bolt", zap.Error(err)) } m.logger.Info("Stopping", zap.String("service", "query")) if err := m.queryController.Shutdown(ctx); err != nil { m.logger.Info("Failed closing query service", zap.Error(err)) } m.logger.Info("Stopping", zap.String("service", "storage-engine")) if err := m.engine.Close(); err != nil { m.logger.Error("failed to close engine", zap.Error(err)) } m.wg.Wait() m.logger.Sync() }
go
func (m *Launcher) Shutdown(ctx context.Context) { m.httpServer.Shutdown(ctx) m.logger.Info("Stopping", zap.String("service", "task")) m.scheduler.Stop() m.logger.Info("Stopping", zap.String("service", "nats")) m.natsServer.Close() m.logger.Info("Stopping", zap.String("service", "bolt")) if err := m.boltClient.Close(); err != nil { m.logger.Info("failed closing bolt", zap.Error(err)) } m.logger.Info("Stopping", zap.String("service", "query")) if err := m.queryController.Shutdown(ctx); err != nil { m.logger.Info("Failed closing query service", zap.Error(err)) } m.logger.Info("Stopping", zap.String("service", "storage-engine")) if err := m.engine.Close(); err != nil { m.logger.Error("failed to close engine", zap.Error(err)) } m.wg.Wait() m.logger.Sync() }
[ "func", "(", "m", "*", "Launcher", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ")", "{", "m", ".", "httpServer", ".", "Shutdown", "(", "ctx", ")", "\n\n", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "m", ".", "scheduler", ".", "Stop", "(", ")", "\n\n", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "m", ".", "natsServer", ".", "Close", "(", ")", "\n\n", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "if", "err", ":=", "m", ".", "boltClient", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "if", "err", ":=", "m", ".", "queryController", ".", "Shutdown", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "m", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "if", "err", ":=", "m", ".", "engine", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "m", ".", "logger", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "\n\n", "m", ".", "wg", ".", "Wait", "(", ")", "\n\n", "m", ".", "logger", ".", "Sync", "(", ")", "\n", "}" ]
// Shutdown shuts down the HTTP server and waits for all services to clean up.
[ "Shutdown", "shuts", "down", "the", "HTTP", "server", "and", "waits", "for", "all", "services", "to", "clean", "up", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/cmd/influxd/launcher/launcher.go#L109-L136
12,906
influxdata/platform
query/influxql/service.go
Query
func (s *Service) Query(ctx context.Context, req *query.Request) (flux.ResultIterator, error) { resp, err := s.query(ctx, req) if err != nil { return nil, err } // Decode the response into the JSON structure. var results Response if err := json.NewDecoder(resp.Body).Decode(&results); err != nil { return nil, err } // Return a result iterator using the response. return NewResponseIterator(&results), nil }
go
func (s *Service) Query(ctx context.Context, req *query.Request) (flux.ResultIterator, error) { resp, err := s.query(ctx, req) if err != nil { return nil, err } // Decode the response into the JSON structure. var results Response if err := json.NewDecoder(resp.Body).Decode(&results); err != nil { return nil, err } // Return a result iterator using the response. return NewResponseIterator(&results), nil }
[ "func", "(", "s", "*", "Service", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "req", "*", "query", ".", "Request", ")", "(", "flux", ".", "ResultIterator", ",", "error", ")", "{", "resp", ",", "err", ":=", "s", ".", "query", "(", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Decode the response into the JSON structure.", "var", "results", "Response", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "results", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Return a result iterator using the response.", "return", "NewResponseIterator", "(", "&", "results", ")", ",", "nil", "\n", "}" ]
// Query will execute a query for the influxql.Compiler type against an influxdb 1.x endpoint, // and return results using the default decoder.
[ "Query", "will", "execute", "a", "query", "for", "the", "influxql", ".", "Compiler", "type", "against", "an", "influxdb", "1", ".", "x", "endpoint", "and", "return", "results", "using", "the", "default", "decoder", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/query/influxql/service.go#L31-L45
12,907
influxdata/platform
task/backend/executor/executor.go
NewAsyncQueryServiceExecutor
func NewAsyncQueryServiceExecutor(logger *zap.Logger, svc query.AsyncQueryService, st backend.Store) backend.Executor { return &asyncQueryServiceExecutor{logger: logger, svc: svc, st: st} }
go
func NewAsyncQueryServiceExecutor(logger *zap.Logger, svc query.AsyncQueryService, st backend.Store) backend.Executor { return &asyncQueryServiceExecutor{logger: logger, svc: svc, st: st} }
[ "func", "NewAsyncQueryServiceExecutor", "(", "logger", "*", "zap", ".", "Logger", ",", "svc", "query", ".", "AsyncQueryService", ",", "st", "backend", ".", "Store", ")", "backend", ".", "Executor", "{", "return", "&", "asyncQueryServiceExecutor", "{", "logger", ":", "logger", ",", "svc", ":", "svc", ",", "st", ":", "st", "}", "\n", "}" ]
// NewQueryServiceExecutor returns a new executor based on the given AsyncQueryService.
[ "NewQueryServiceExecutor", "returns", "a", "new", "executor", "based", "on", "the", "given", "AsyncQueryService", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/task/backend/executor/executor.go#L189-L191
12,908
influxdata/platform
mock/auth_service.go
NewAuthorizationService
func NewAuthorizationService() *AuthorizationService { return &AuthorizationService{ FindAuthorizationByIDFn: func(context.Context, platform.ID) (*platform.Authorization, error) { return nil, nil }, FindAuthorizationByTokenFn: func(context.Context, string) (*platform.Authorization, error) { return nil, nil }, FindAuthorizationsFn: func(context.Context, platform.AuthorizationFilter, ...platform.FindOptions) ([]*platform.Authorization, int, error) { return nil, 0, nil }, CreateAuthorizationFn: func(context.Context, *platform.Authorization) error { return nil }, DeleteAuthorizationFn: func(context.Context, platform.ID) error { return nil }, SetAuthorizationStatusFn: func(context.Context, platform.ID, platform.Status) error { return nil }, } }
go
func NewAuthorizationService() *AuthorizationService { return &AuthorizationService{ FindAuthorizationByIDFn: func(context.Context, platform.ID) (*platform.Authorization, error) { return nil, nil }, FindAuthorizationByTokenFn: func(context.Context, string) (*platform.Authorization, error) { return nil, nil }, FindAuthorizationsFn: func(context.Context, platform.AuthorizationFilter, ...platform.FindOptions) ([]*platform.Authorization, int, error) { return nil, 0, nil }, CreateAuthorizationFn: func(context.Context, *platform.Authorization) error { return nil }, DeleteAuthorizationFn: func(context.Context, platform.ID) error { return nil }, SetAuthorizationStatusFn: func(context.Context, platform.ID, platform.Status) error { return nil }, } }
[ "func", "NewAuthorizationService", "(", ")", "*", "AuthorizationService", "{", "return", "&", "AuthorizationService", "{", "FindAuthorizationByIDFn", ":", "func", "(", "context", ".", "Context", ",", "platform", ".", "ID", ")", "(", "*", "platform", ".", "Authorization", ",", "error", ")", "{", "return", "nil", ",", "nil", "}", ",", "FindAuthorizationByTokenFn", ":", "func", "(", "context", ".", "Context", ",", "string", ")", "(", "*", "platform", ".", "Authorization", ",", "error", ")", "{", "return", "nil", ",", "nil", "}", ",", "FindAuthorizationsFn", ":", "func", "(", "context", ".", "Context", ",", "platform", ".", "AuthorizationFilter", ",", "...", "platform", ".", "FindOptions", ")", "(", "[", "]", "*", "platform", ".", "Authorization", ",", "int", ",", "error", ")", "{", "return", "nil", ",", "0", ",", "nil", "\n", "}", ",", "CreateAuthorizationFn", ":", "func", "(", "context", ".", "Context", ",", "*", "platform", ".", "Authorization", ")", "error", "{", "return", "nil", "}", ",", "DeleteAuthorizationFn", ":", "func", "(", "context", ".", "Context", ",", "platform", ".", "ID", ")", "error", "{", "return", "nil", "}", ",", "SetAuthorizationStatusFn", ":", "func", "(", "context", ".", "Context", ",", "platform", ".", "ID", ",", "platform", ".", "Status", ")", "error", "{", "return", "nil", "}", ",", "}", "\n", "}" ]
// NewAuthorizationService returns a mock AuthorizationService where its methods will return // zero values.
[ "NewAuthorizationService", "returns", "a", "mock", "AuthorizationService", "where", "its", "methods", "will", "return", "zero", "values", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/mock/auth_service.go#L29-L40
12,909
influxdata/platform
http/user_service.go
FindMe
func (s *UserService) FindMe(ctx context.Context, id platform.ID) (*platform.User, error) { url, err := newURL(s.Addr, mePath) if err != nil { return nil, err } req, err := http.NewRequest("GET", url.String(), nil) if err != nil { return nil, err } SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if err := CheckError(resp, true); err != nil { return nil, err } var res userResponse if err := json.NewDecoder(resp.Body).Decode(&res); err != nil { return nil, err } return &res.User, nil }
go
func (s *UserService) FindMe(ctx context.Context, id platform.ID) (*platform.User, error) { url, err := newURL(s.Addr, mePath) if err != nil { return nil, err } req, err := http.NewRequest("GET", url.String(), nil) if err != nil { return nil, err } SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if err := CheckError(resp, true); err != nil { return nil, err } var res userResponse if err := json.NewDecoder(resp.Body).Decode(&res); err != nil { return nil, err } return &res.User, nil }
[ "func", "(", "s", "*", "UserService", ")", "FindMe", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "(", "*", "platform", ".", "User", ",", "error", ")", "{", "url", ",", "err", ":=", "newURL", "(", "s", ".", "Addr", ",", "mePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "url", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "SetToken", "(", "s", ".", "Token", ",", "req", ")", "\n\n", "hc", ":=", "newClient", "(", "url", ".", "Scheme", ",", "s", ".", "InsecureSkipVerify", ")", "\n", "resp", ",", "err", ":=", "hc", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "if", "err", ":=", "CheckError", "(", "resp", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "res", "userResponse", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "res", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "User", ",", "nil", "\n", "}" ]
// FindMe returns user information about the owner of the token
[ "FindMe", "returns", "user", "information", "about", "the", "owner", "of", "the", "token" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/user_service.go#L421-L450
12,910
influxdata/platform
http/user_service.go
FindUsers
func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error) { url, err := newURL(s.Addr, usersPath) if err != nil { return nil, 0, err } query := url.Query() req, err := http.NewRequest("GET", url.String(), nil) if err != nil { return nil, 0, err } if filter.ID != nil { query.Add("id", filter.ID.String()) } if filter.Name != nil { query.Add("name", *filter.Name) } req.URL.RawQuery = query.Encode() SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, 0, err } if err := CheckError(resp, true); err != nil { return nil, 0, err } var r usersResponse if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { return nil, 0, err } us := r.ToPlatform() return us, len(us), nil }
go
func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error) { url, err := newURL(s.Addr, usersPath) if err != nil { return nil, 0, err } query := url.Query() req, err := http.NewRequest("GET", url.String(), nil) if err != nil { return nil, 0, err } if filter.ID != nil { query.Add("id", filter.ID.String()) } if filter.Name != nil { query.Add("name", *filter.Name) } req.URL.RawQuery = query.Encode() SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, 0, err } if err := CheckError(resp, true); err != nil { return nil, 0, err } var r usersResponse if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { return nil, 0, err } us := r.ToPlatform() return us, len(us), nil }
[ "func", "(", "s", "*", "UserService", ")", "FindUsers", "(", "ctx", "context", ".", "Context", ",", "filter", "platform", ".", "UserFilter", ",", "opt", "...", "platform", ".", "FindOptions", ")", "(", "[", "]", "*", "platform", ".", "User", ",", "int", ",", "error", ")", "{", "url", ",", "err", ":=", "newURL", "(", "s", ".", "Addr", ",", "usersPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "query", ":=", "url", ".", "Query", "(", ")", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "url", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n", "if", "filter", ".", "ID", "!=", "nil", "{", "query", ".", "Add", "(", "\"", "\"", ",", "filter", ".", "ID", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "filter", ".", "Name", "!=", "nil", "{", "query", ".", "Add", "(", "\"", "\"", ",", "*", "filter", ".", "Name", ")", "\n", "}", "\n\n", "req", ".", "URL", ".", "RawQuery", "=", "query", ".", "Encode", "(", ")", "\n", "SetToken", "(", "s", ".", "Token", ",", "req", ")", "\n\n", "hc", ":=", "newClient", "(", "url", ".", "Scheme", ",", "s", ".", "InsecureSkipVerify", ")", "\n", "resp", ",", "err", ":=", "hc", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "CheckError", "(", "resp", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "var", "r", "usersResponse", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "r", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "us", ":=", "r", ".", "ToPlatform", "(", ")", "\n", "return", "us", ",", "len", "(", "us", ")", ",", "nil", "\n", "}" ]
// FindUsers returns a list of users that match filter and the total count of matching users. // Additional options provide pagination & sorting.
[ "FindUsers", "returns", "a", "list", "of", "users", "that", "match", "filter", "and", "the", "total", "count", "of", "matching", "users", ".", "Additional", "options", "provide", "pagination", "&", "sorting", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/user_service.go#L507-L546
12,911
influxdata/platform
http/user_service.go
CreateUser
func (s *UserService) CreateUser(ctx context.Context, u *platform.User) error { url, err := newURL(s.Addr, usersPath) if err != nil { return err } octets, err := json.Marshal(u) if err != nil { return err } req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return err } // TODO(jsternberg): Should this check for a 201 explicitly? if err := CheckError(resp, true); err != nil { return err } if err := json.NewDecoder(resp.Body).Decode(u); err != nil { return err } return nil }
go
func (s *UserService) CreateUser(ctx context.Context, u *platform.User) error { url, err := newURL(s.Addr, usersPath) if err != nil { return err } octets, err := json.Marshal(u) if err != nil { return err } req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(url.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return err } // TODO(jsternberg): Should this check for a 201 explicitly? if err := CheckError(resp, true); err != nil { return err } if err := json.NewDecoder(resp.Body).Decode(u); err != nil { return err } return nil }
[ "func", "(", "s", "*", "UserService", ")", "CreateUser", "(", "ctx", "context", ".", "Context", ",", "u", "*", "platform", ".", "User", ")", "error", "{", "url", ",", "err", ":=", "newURL", "(", "s", ".", "Addr", ",", "usersPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "octets", ",", "err", ":=", "json", ".", "Marshal", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "url", ".", "String", "(", ")", ",", "bytes", ".", "NewReader", "(", "octets", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "SetToken", "(", "s", ".", "Token", ",", "req", ")", "\n\n", "hc", ":=", "newClient", "(", "url", ".", "Scheme", ",", "s", ".", "InsecureSkipVerify", ")", "\n\n", "resp", ",", "err", ":=", "hc", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// TODO(jsternberg): Should this check for a 201 explicitly?", "if", "err", ":=", "CheckError", "(", "resp", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "u", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CreateUser creates a new user and sets u.ID with the new identifier.
[ "CreateUser", "creates", "a", "new", "user", "and", "sets", "u", ".", "ID", "with", "the", "new", "identifier", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/user_service.go#L549-L585
12,912
influxdata/platform
pkg/deep/equal.go
Equal
func Equal(a1, a2 interface{}) bool { if a1 == nil || a2 == nil { return a1 == a2 } v1 := reflect.ValueOf(a1) v2 := reflect.ValueOf(a2) if v1.Type() != v2.Type() { return false } return deepValueEqual(v1, v2, make(map[visit]bool), 0) }
go
func Equal(a1, a2 interface{}) bool { if a1 == nil || a2 == nil { return a1 == a2 } v1 := reflect.ValueOf(a1) v2 := reflect.ValueOf(a2) if v1.Type() != v2.Type() { return false } return deepValueEqual(v1, v2, make(map[visit]bool), 0) }
[ "func", "Equal", "(", "a1", ",", "a2", "interface", "{", "}", ")", "bool", "{", "if", "a1", "==", "nil", "||", "a2", "==", "nil", "{", "return", "a1", "==", "a2", "\n", "}", "\n", "v1", ":=", "reflect", ".", "ValueOf", "(", "a1", ")", "\n", "v2", ":=", "reflect", ".", "ValueOf", "(", "a2", ")", "\n", "if", "v1", ".", "Type", "(", ")", "!=", "v2", ".", "Type", "(", ")", "{", "return", "false", "\n", "}", "\n", "return", "deepValueEqual", "(", "v1", ",", "v2", ",", "make", "(", "map", "[", "visit", "]", "bool", ")", ",", "0", ")", "\n", "}" ]
// Equal is a copy of reflect.DeepEqual except that it treats NaN == NaN as true.
[ "Equal", "is", "a", "copy", "of", "reflect", ".", "DeepEqual", "except", "that", "it", "treats", "NaN", "==", "NaN", "as", "true", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/pkg/deep/equal.go#L41-L51
12,913
influxdata/platform
storage/compat/compat.go
NewConfig
func NewConfig() Config { return Config{ WALFsyncDelay: toml.Duration(tsm1.DefaultWALFsyncDelay), ValidateKeys: storage.DefaultValidateKeys, CacheMaxMemorySize: toml.Size(tsm1.DefaultCacheMaxMemorySize), CacheSnapshotMemorySize: toml.Size(tsm1.DefaultCacheSnapshotMemorySize), CacheSnapshotWriteColdDuration: toml.Duration(tsm1.DefaultCacheSnapshotWriteColdDuration), CompactFullWriteColdDuration: toml.Duration(tsm1.DefaultCompactFullWriteColdDuration), CompactThroughput: toml.Size(tsm1.DefaultCompactThroughput), CompactThroughputBurst: toml.Size(tsm1.DefaultCompactThroughputBurst), MaxConcurrentCompactions: tsm1.DefaultCompactMaxConcurrent, TraceLoggingEnabled: storage.DefaultTraceLoggingEnabled, TSMWillNeed: tsm1.DefaultMADVWillNeed, } }
go
func NewConfig() Config { return Config{ WALFsyncDelay: toml.Duration(tsm1.DefaultWALFsyncDelay), ValidateKeys: storage.DefaultValidateKeys, CacheMaxMemorySize: toml.Size(tsm1.DefaultCacheMaxMemorySize), CacheSnapshotMemorySize: toml.Size(tsm1.DefaultCacheSnapshotMemorySize), CacheSnapshotWriteColdDuration: toml.Duration(tsm1.DefaultCacheSnapshotWriteColdDuration), CompactFullWriteColdDuration: toml.Duration(tsm1.DefaultCompactFullWriteColdDuration), CompactThroughput: toml.Size(tsm1.DefaultCompactThroughput), CompactThroughputBurst: toml.Size(tsm1.DefaultCompactThroughputBurst), MaxConcurrentCompactions: tsm1.DefaultCompactMaxConcurrent, TraceLoggingEnabled: storage.DefaultTraceLoggingEnabled, TSMWillNeed: tsm1.DefaultMADVWillNeed, } }
[ "func", "NewConfig", "(", ")", "Config", "{", "return", "Config", "{", "WALFsyncDelay", ":", "toml", ".", "Duration", "(", "tsm1", ".", "DefaultWALFsyncDelay", ")", ",", "ValidateKeys", ":", "storage", ".", "DefaultValidateKeys", ",", "CacheMaxMemorySize", ":", "toml", ".", "Size", "(", "tsm1", ".", "DefaultCacheMaxMemorySize", ")", ",", "CacheSnapshotMemorySize", ":", "toml", ".", "Size", "(", "tsm1", ".", "DefaultCacheSnapshotMemorySize", ")", ",", "CacheSnapshotWriteColdDuration", ":", "toml", ".", "Duration", "(", "tsm1", ".", "DefaultCacheSnapshotWriteColdDuration", ")", ",", "CompactFullWriteColdDuration", ":", "toml", ".", "Duration", "(", "tsm1", ".", "DefaultCompactFullWriteColdDuration", ")", ",", "CompactThroughput", ":", "toml", ".", "Size", "(", "tsm1", ".", "DefaultCompactThroughput", ")", ",", "CompactThroughputBurst", ":", "toml", ".", "Size", "(", "tsm1", ".", "DefaultCompactThroughputBurst", ")", ",", "MaxConcurrentCompactions", ":", "tsm1", ".", "DefaultCompactMaxConcurrent", ",", "TraceLoggingEnabled", ":", "storage", ".", "DefaultTraceLoggingEnabled", ",", "TSMWillNeed", ":", "tsm1", ".", "DefaultMADVWillNeed", ",", "}", "\n", "}" ]
// NewConfig constructs an old Config struct with appropriate defaults for a new Config.
[ "NewConfig", "constructs", "an", "old", "Config", "struct", "with", "appropriate", "defaults", "for", "a", "new", "Config", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/storage/compat/compat.go#L35-L49
12,914
influxdata/platform
storage/compat/compat.go
Convert
func Convert(oldConfig Config) (string, storage.Config) { newConfig := storage.NewConfig() newConfig.TraceLoggingEnabled = oldConfig.TraceLoggingEnabled newConfig.ValidateKeys = oldConfig.ValidateKeys newConfig.Engine.MADVWillNeed = oldConfig.TSMWillNeed newConfig.Engine.Cache.MaxMemorySize = oldConfig.CacheMaxMemorySize newConfig.Engine.Cache.SnapshotMemorySize = oldConfig.CacheSnapshotMemorySize newConfig.Engine.Cache.SnapshotWriteColdDuration = oldConfig.CacheSnapshotWriteColdDuration newConfig.Engine.Compaction.FullWriteColdDuration = oldConfig.CompactFullWriteColdDuration newConfig.Engine.Compaction.Throughput = oldConfig.CompactThroughput newConfig.Engine.Compaction.ThroughputBurst = oldConfig.CompactThroughputBurst newConfig.Engine.Compaction.MaxConcurrent = oldConfig.MaxConcurrentCompactions newConfig.WALPath = oldConfig.WALDir newConfig.WAL.FsyncDelay = oldConfig.WALFsyncDelay return oldConfig.Dir, newConfig }
go
func Convert(oldConfig Config) (string, storage.Config) { newConfig := storage.NewConfig() newConfig.TraceLoggingEnabled = oldConfig.TraceLoggingEnabled newConfig.ValidateKeys = oldConfig.ValidateKeys newConfig.Engine.MADVWillNeed = oldConfig.TSMWillNeed newConfig.Engine.Cache.MaxMemorySize = oldConfig.CacheMaxMemorySize newConfig.Engine.Cache.SnapshotMemorySize = oldConfig.CacheSnapshotMemorySize newConfig.Engine.Cache.SnapshotWriteColdDuration = oldConfig.CacheSnapshotWriteColdDuration newConfig.Engine.Compaction.FullWriteColdDuration = oldConfig.CompactFullWriteColdDuration newConfig.Engine.Compaction.Throughput = oldConfig.CompactThroughput newConfig.Engine.Compaction.ThroughputBurst = oldConfig.CompactThroughputBurst newConfig.Engine.Compaction.MaxConcurrent = oldConfig.MaxConcurrentCompactions newConfig.WALPath = oldConfig.WALDir newConfig.WAL.FsyncDelay = oldConfig.WALFsyncDelay return oldConfig.Dir, newConfig }
[ "func", "Convert", "(", "oldConfig", "Config", ")", "(", "string", ",", "storage", ".", "Config", ")", "{", "newConfig", ":=", "storage", ".", "NewConfig", "(", ")", "\n", "newConfig", ".", "TraceLoggingEnabled", "=", "oldConfig", ".", "TraceLoggingEnabled", "\n", "newConfig", ".", "ValidateKeys", "=", "oldConfig", ".", "ValidateKeys", "\n", "newConfig", ".", "Engine", ".", "MADVWillNeed", "=", "oldConfig", ".", "TSMWillNeed", "\n", "newConfig", ".", "Engine", ".", "Cache", ".", "MaxMemorySize", "=", "oldConfig", ".", "CacheMaxMemorySize", "\n", "newConfig", ".", "Engine", ".", "Cache", ".", "SnapshotMemorySize", "=", "oldConfig", ".", "CacheSnapshotMemorySize", "\n", "newConfig", ".", "Engine", ".", "Cache", ".", "SnapshotWriteColdDuration", "=", "oldConfig", ".", "CacheSnapshotWriteColdDuration", "\n", "newConfig", ".", "Engine", ".", "Compaction", ".", "FullWriteColdDuration", "=", "oldConfig", ".", "CompactFullWriteColdDuration", "\n", "newConfig", ".", "Engine", ".", "Compaction", ".", "Throughput", "=", "oldConfig", ".", "CompactThroughput", "\n", "newConfig", ".", "Engine", ".", "Compaction", ".", "ThroughputBurst", "=", "oldConfig", ".", "CompactThroughputBurst", "\n", "newConfig", ".", "Engine", ".", "Compaction", ".", "MaxConcurrent", "=", "oldConfig", ".", "MaxConcurrentCompactions", "\n", "newConfig", ".", "WALPath", "=", "oldConfig", ".", "WALDir", "\n", "newConfig", ".", "WAL", ".", "FsyncDelay", "=", "oldConfig", ".", "WALFsyncDelay", "\n", "return", "oldConfig", ".", "Dir", ",", "newConfig", "\n", "}" ]
// Convert takes an old Config and converts it into a new Config. It also returns the value // of the Dir key so that it can be passed through appropriately to the storage engine constructor.
[ "Convert", "takes", "an", "old", "Config", "and", "converts", "it", "into", "a", "new", "Config", ".", "It", "also", "returns", "the", "value", "of", "the", "Dir", "key", "so", "that", "it", "can", "be", "passed", "through", "appropriately", "to", "the", "storage", "engine", "constructor", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/storage/compat/compat.go#L53-L68
12,915
influxdata/platform
query/control/controller.go
Query
func (c *Controller) Query(ctx context.Context, req *query.Request) (flux.Query, error) { // Set the request on the context so platform specific Flux operations can retrieve it later. ctx = query.ContextWithRequest(ctx, req) // Set the org label value for controller metrics ctx = context.WithValue(ctx, orgLabel, req.OrganizationID.String()) q, err := c.c.Query(ctx, req.Compiler) if err != nil { // If the controller reports an error, it's usually because of a syntax error // or other problem that the client must fix. return q, &platform.Error{ Code: platform.EInvalid, Msg: err.Error(), } } return q, nil }
go
func (c *Controller) Query(ctx context.Context, req *query.Request) (flux.Query, error) { // Set the request on the context so platform specific Flux operations can retrieve it later. ctx = query.ContextWithRequest(ctx, req) // Set the org label value for controller metrics ctx = context.WithValue(ctx, orgLabel, req.OrganizationID.String()) q, err := c.c.Query(ctx, req.Compiler) if err != nil { // If the controller reports an error, it's usually because of a syntax error // or other problem that the client must fix. return q, &platform.Error{ Code: platform.EInvalid, Msg: err.Error(), } } return q, nil }
[ "func", "(", "c", "*", "Controller", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "req", "*", "query", ".", "Request", ")", "(", "flux", ".", "Query", ",", "error", ")", "{", "// Set the request on the context so platform specific Flux operations can retrieve it later.", "ctx", "=", "query", ".", "ContextWithRequest", "(", "ctx", ",", "req", ")", "\n", "// Set the org label value for controller metrics", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "orgLabel", ",", "req", ".", "OrganizationID", ".", "String", "(", ")", ")", "\n", "q", ",", "err", ":=", "c", ".", "c", ".", "Query", "(", "ctx", ",", "req", ".", "Compiler", ")", "\n", "if", "err", "!=", "nil", "{", "// If the controller reports an error, it's usually because of a syntax error", "// or other problem that the client must fix.", "return", "q", ",", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "EInvalid", ",", "Msg", ":", "err", ".", "Error", "(", ")", ",", "}", "\n", "}", "\n\n", "return", "q", ",", "nil", "\n", "}" ]
// Query satisfies the AsyncQueryService while ensuring the request is propagated on the context.
[ "Query", "satisfies", "the", "AsyncQueryService", "while", "ensuring", "the", "request", "is", "propagated", "on", "the", "context", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/query/control/controller.go#L30-L46
12,916
influxdata/platform
pkg/rhh/rhh.go
grow
func (m *HashMap) grow() { // Copy old elements and hashes. elems, hashes := m.elems, m.hashes capacity := m.capacity // Double capacity & reallocate. m.capacity *= 2 m.alloc() // Copy old elements to new hash/elem list. for i := int64(0); i < capacity; i++ { elem, hash := &elems[i], hashes[i] if hash == 0 { continue } m.insert(hash, elem.key, elem.value) } }
go
func (m *HashMap) grow() { // Copy old elements and hashes. elems, hashes := m.elems, m.hashes capacity := m.capacity // Double capacity & reallocate. m.capacity *= 2 m.alloc() // Copy old elements to new hash/elem list. for i := int64(0); i < capacity; i++ { elem, hash := &elems[i], hashes[i] if hash == 0 { continue } m.insert(hash, elem.key, elem.value) } }
[ "func", "(", "m", "*", "HashMap", ")", "grow", "(", ")", "{", "// Copy old elements and hashes.", "elems", ",", "hashes", ":=", "m", ".", "elems", ",", "m", ".", "hashes", "\n", "capacity", ":=", "m", ".", "capacity", "\n\n", "// Double capacity & reallocate.", "m", ".", "capacity", "*=", "2", "\n", "m", ".", "alloc", "(", ")", "\n\n", "// Copy old elements to new hash/elem list.", "for", "i", ":=", "int64", "(", "0", ")", ";", "i", "<", "capacity", ";", "i", "++", "{", "elem", ",", "hash", ":=", "&", "elems", "[", "i", "]", ",", "hashes", "[", "i", "]", "\n", "if", "hash", "==", "0", "{", "continue", "\n", "}", "\n", "m", ".", "insert", "(", "hash", ",", "elem", ".", "key", ",", "elem", ".", "value", ")", "\n", "}", "\n", "}" ]
// grow doubles the capacity and reinserts all existing hashes & elements.
[ "grow", "doubles", "the", "capacity", "and", "reinserts", "all", "existing", "hashes", "&", "elements", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/pkg/rhh/rhh.go#L185-L202
12,917
influxdata/platform
bolt/dashboard.go
CreateDashboard
func (c *Client) CreateDashboard(ctx context.Context, d *platform.Dashboard) error { err := c.db.Update(func(tx *bolt.Tx) error { d.ID = c.IDGenerator.ID() for _, cell := range d.Cells { cell.ID = c.IDGenerator.ID() if err := c.createCellView(ctx, tx, d.ID, cell.ID, nil); err != nil { return err } } if err := c.appendDashboardEventToLog(ctx, tx, d.ID, dashboardCreatedEvent); err != nil { return err } // TODO(desa): don't populate this here. use the first/last methods of the oplog to get meta fields. d.Meta.CreatedAt = c.time() return c.putDashboardWithMeta(ctx, tx, d) }) if err != nil { return &platform.Error{ Err: err, Op: getOp(platform.OpCreateDashboard), } } return nil }
go
func (c *Client) CreateDashboard(ctx context.Context, d *platform.Dashboard) error { err := c.db.Update(func(tx *bolt.Tx) error { d.ID = c.IDGenerator.ID() for _, cell := range d.Cells { cell.ID = c.IDGenerator.ID() if err := c.createCellView(ctx, tx, d.ID, cell.ID, nil); err != nil { return err } } if err := c.appendDashboardEventToLog(ctx, tx, d.ID, dashboardCreatedEvent); err != nil { return err } // TODO(desa): don't populate this here. use the first/last methods of the oplog to get meta fields. d.Meta.CreatedAt = c.time() return c.putDashboardWithMeta(ctx, tx, d) }) if err != nil { return &platform.Error{ Err: err, Op: getOp(platform.OpCreateDashboard), } } return nil }
[ "func", "(", "c", "*", "Client", ")", "CreateDashboard", "(", "ctx", "context", ".", "Context", ",", "d", "*", "platform", ".", "Dashboard", ")", "error", "{", "err", ":=", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "d", ".", "ID", "=", "c", ".", "IDGenerator", ".", "ID", "(", ")", "\n\n", "for", "_", ",", "cell", ":=", "range", "d", ".", "Cells", "{", "cell", ".", "ID", "=", "c", ".", "IDGenerator", ".", "ID", "(", ")", "\n\n", "if", "err", ":=", "c", ".", "createCellView", "(", "ctx", ",", "tx", ",", "d", ".", "ID", ",", "cell", ".", "ID", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "appendDashboardEventToLog", "(", "ctx", ",", "tx", ",", "d", ".", "ID", ",", "dashboardCreatedEvent", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// TODO(desa): don't populate this here. use the first/last methods of the oplog to get meta fields.", "d", ".", "Meta", ".", "CreatedAt", "=", "c", ".", "time", "(", ")", "\n\n", "return", "c", ".", "putDashboardWithMeta", "(", "ctx", ",", "tx", ",", "d", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Err", ":", "err", ",", "Op", ":", "getOp", "(", "platform", ".", "OpCreateDashboard", ")", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CreateDashboard creates a platform dashboard and sets d.ID.
[ "CreateDashboard", "creates", "a", "platform", "dashboard", "and", "sets", "d", ".", "ID", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/dashboard.go#L197-L225
12,918
influxdata/platform
tsdb/tsm1/wal.go
EnableTraceLogging
func (l *WAL) EnableTraceLogging(enabled bool) { l.traceLogging = enabled if enabled { l.traceLogger = l.logger } }
go
func (l *WAL) EnableTraceLogging(enabled bool) { l.traceLogging = enabled if enabled { l.traceLogger = l.logger } }
[ "func", "(", "l", "*", "WAL", ")", "EnableTraceLogging", "(", "enabled", "bool", ")", "{", "l", ".", "traceLogging", "=", "enabled", "\n", "if", "enabled", "{", "l", ".", "traceLogger", "=", "l", ".", "logger", "\n", "}", "\n", "}" ]
// EnableTraceLogging must be called before the WAL is opened.
[ "EnableTraceLogging", "must", "be", "called", "before", "the", "WAL", "is", "opened", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L145-L150
12,919
influxdata/platform
tsdb/tsm1/wal.go
WriteMulti
func (l *WAL) WriteMulti(values map[string][]Value) (int, error) { entry := &WriteWALEntry{ Values: values, } id, err := l.writeToLog(entry) if err != nil { l.tracker.IncWritesErr() return -1, err } l.tracker.IncWritesOK() return id, nil }
go
func (l *WAL) WriteMulti(values map[string][]Value) (int, error) { entry := &WriteWALEntry{ Values: values, } id, err := l.writeToLog(entry) if err != nil { l.tracker.IncWritesErr() return -1, err } l.tracker.IncWritesOK() return id, nil }
[ "func", "(", "l", "*", "WAL", ")", "WriteMulti", "(", "values", "map", "[", "string", "]", "[", "]", "Value", ")", "(", "int", ",", "error", ")", "{", "entry", ":=", "&", "WriteWALEntry", "{", "Values", ":", "values", ",", "}", "\n\n", "id", ",", "err", ":=", "l", ".", "writeToLog", "(", "entry", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "tracker", ".", "IncWritesErr", "(", ")", "\n", "return", "-", "1", ",", "err", "\n", "}", "\n", "l", ".", "tracker", ".", "IncWritesOK", "(", ")", "\n\n", "return", "id", ",", "nil", "\n", "}" ]
// WriteMulti writes the given values to the WAL. It returns the WAL segment ID to // which the points were written. If an error is returned the segment ID should // be ignored.
[ "WriteMulti", "writes", "the", "given", "values", "to", "the", "WAL", ".", "It", "returns", "the", "WAL", "segment", "ID", "to", "which", "the", "points", "were", "written", ".", "If", "an", "error", "is", "returned", "the", "segment", "ID", "should", "be", "ignored", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L303-L316
12,920
influxdata/platform
tsdb/tsm1/wal.go
ClosedSegments
func (l *WAL) ClosedSegments() ([]string, error) { l.mu.RLock() defer l.mu.RUnlock() // Not loading files from disk so nothing to do if l.path == "" { return nil, nil } var currentFile string if l.currentSegmentWriter != nil { currentFile = l.currentSegmentWriter.path() } files, err := segmentFileNames(l.path) if err != nil { return nil, err } var closedFiles []string for _, fn := range files { // Skip the current path if fn == currentFile { continue } closedFiles = append(closedFiles, fn) } return closedFiles, nil }
go
func (l *WAL) ClosedSegments() ([]string, error) { l.mu.RLock() defer l.mu.RUnlock() // Not loading files from disk so nothing to do if l.path == "" { return nil, nil } var currentFile string if l.currentSegmentWriter != nil { currentFile = l.currentSegmentWriter.path() } files, err := segmentFileNames(l.path) if err != nil { return nil, err } var closedFiles []string for _, fn := range files { // Skip the current path if fn == currentFile { continue } closedFiles = append(closedFiles, fn) } return closedFiles, nil }
[ "func", "(", "l", "*", "WAL", ")", "ClosedSegments", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "l", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "RUnlock", "(", ")", "\n", "// Not loading files from disk so nothing to do", "if", "l", ".", "path", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "var", "currentFile", "string", "\n", "if", "l", ".", "currentSegmentWriter", "!=", "nil", "{", "currentFile", "=", "l", ".", "currentSegmentWriter", ".", "path", "(", ")", "\n", "}", "\n\n", "files", ",", "err", ":=", "segmentFileNames", "(", "l", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "closedFiles", "[", "]", "string", "\n", "for", "_", ",", "fn", ":=", "range", "files", "{", "// Skip the current path", "if", "fn", "==", "currentFile", "{", "continue", "\n", "}", "\n\n", "closedFiles", "=", "append", "(", "closedFiles", ",", "fn", ")", "\n", "}", "\n\n", "return", "closedFiles", ",", "nil", "\n", "}" ]
// ClosedSegments returns a slice of the names of the closed segment files.
[ "ClosedSegments", "returns", "a", "slice", "of", "the", "names", "of", "the", "closed", "segment", "files", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L319-L348
12,921
influxdata/platform
tsdb/tsm1/wal.go
Delete
func (l *WAL) Delete(keys [][]byte) (int, error) { if len(keys) == 0 { return 0, nil } entry := &DeleteWALEntry{ Keys: keys, } id, err := l.writeToLog(entry) if err != nil { return -1, err } return id, nil }
go
func (l *WAL) Delete(keys [][]byte) (int, error) { if len(keys) == 0 { return 0, nil } entry := &DeleteWALEntry{ Keys: keys, } id, err := l.writeToLog(entry) if err != nil { return -1, err } return id, nil }
[ "func", "(", "l", "*", "WAL", ")", "Delete", "(", "keys", "[", "]", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "0", ",", "nil", "\n", "}", "\n", "entry", ":=", "&", "DeleteWALEntry", "{", "Keys", ":", "keys", ",", "}", "\n\n", "id", ",", "err", ":=", "l", ".", "writeToLog", "(", "entry", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "return", "id", ",", "nil", "\n", "}" ]
// Delete deletes the given keys, returning the segment ID for the operation.
[ "Delete", "deletes", "the", "given", "keys", "returning", "the", "segment", "ID", "for", "the", "operation", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L487-L500
12,922
influxdata/platform
tsdb/tsm1/wal.go
DeleteRange
func (l *WAL) DeleteRange(keys [][]byte, min, max int64) (int, error) { if len(keys) == 0 { return 0, nil } entry := &DeleteRangeWALEntry{ Keys: keys, Min: min, Max: max, } id, err := l.writeToLog(entry) if err != nil { return -1, err } return id, nil }
go
func (l *WAL) DeleteRange(keys [][]byte, min, max int64) (int, error) { if len(keys) == 0 { return 0, nil } entry := &DeleteRangeWALEntry{ Keys: keys, Min: min, Max: max, } id, err := l.writeToLog(entry) if err != nil { return -1, err } return id, nil }
[ "func", "(", "l", "*", "WAL", ")", "DeleteRange", "(", "keys", "[", "]", "[", "]", "byte", ",", "min", ",", "max", "int64", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "0", ",", "nil", "\n", "}", "\n", "entry", ":=", "&", "DeleteRangeWALEntry", "{", "Keys", ":", "keys", ",", "Min", ":", "min", ",", "Max", ":", "max", ",", "}", "\n\n", "id", ",", "err", ":=", "l", ".", "writeToLog", "(", "entry", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "return", "id", ",", "nil", "\n", "}" ]
// DeleteRange deletes the given keys within the given time range, // returning the segment ID for the operation.
[ "DeleteRange", "deletes", "the", "given", "keys", "within", "the", "given", "time", "range", "returning", "the", "segment", "ID", "for", "the", "operation", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L504-L519
12,923
influxdata/platform
tsdb/tsm1/wal.go
segmentFileNames
func segmentFileNames(dir string) ([]string, error) { names, err := filepath.Glob(filepath.Join(dir, fmt.Sprintf("%s*.%s", WALFilePrefix, WALFileExtension))) if err != nil { return nil, err } sort.Strings(names) return names, nil }
go
func segmentFileNames(dir string) ([]string, error) { names, err := filepath.Glob(filepath.Join(dir, fmt.Sprintf("%s*.%s", WALFilePrefix, WALFileExtension))) if err != nil { return nil, err } sort.Strings(names) return names, nil }
[ "func", "segmentFileNames", "(", "dir", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "names", ",", "err", ":=", "filepath", ".", "Glob", "(", "filepath", ".", "Join", "(", "dir", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "WALFilePrefix", ",", "WALFileExtension", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "return", "names", ",", "nil", "\n", "}" ]
// segmentFileNames will return all files that are WAL segment files in sorted order by ascending ID.
[ "segmentFileNames", "will", "return", "all", "files", "that", "are", "WAL", "segment", "files", "in", "sorted", "order", "by", "ascending", "ID", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L542-L549
12,924
influxdata/platform
tsdb/tsm1/wal.go
Encode
func (w *DeleteWALEntry) Encode(dst []byte) ([]byte, error) { sz := w.MarshalSize() if len(dst) < sz { dst = make([]byte, sz) } var n int for _, k := range w.Keys { n += copy(dst[n:], k) n += copy(dst[n:], "\n") } // We return n-1 to strip off the last newline so that unmarshalling the value // does not produce an empty string return []byte(dst[:n-1]), nil }
go
func (w *DeleteWALEntry) Encode(dst []byte) ([]byte, error) { sz := w.MarshalSize() if len(dst) < sz { dst = make([]byte, sz) } var n int for _, k := range w.Keys { n += copy(dst[n:], k) n += copy(dst[n:], "\n") } // We return n-1 to strip off the last newline so that unmarshalling the value // does not produce an empty string return []byte(dst[:n-1]), nil }
[ "func", "(", "w", "*", "DeleteWALEntry", ")", "Encode", "(", "dst", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "sz", ":=", "w", ".", "MarshalSize", "(", ")", "\n\n", "if", "len", "(", "dst", ")", "<", "sz", "{", "dst", "=", "make", "(", "[", "]", "byte", ",", "sz", ")", "\n", "}", "\n\n", "var", "n", "int", "\n", "for", "_", ",", "k", ":=", "range", "w", ".", "Keys", "{", "n", "+=", "copy", "(", "dst", "[", "n", ":", "]", ",", "k", ")", "\n", "n", "+=", "copy", "(", "dst", "[", "n", ":", "]", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n\n", "// We return n-1 to strip off the last newline so that unmarshalling the value", "// does not produce an empty string", "return", "[", "]", "byte", "(", "dst", "[", ":", "n", "-", "1", "]", ")", ",", "nil", "\n", "}" ]
// Encode converts the DeleteWALEntry into a byte slice, appending to dst.
[ "Encode", "converts", "the", "DeleteWALEntry", "into", "a", "byte", "slice", "appending", "to", "dst", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L1005-L1021
12,925
influxdata/platform
tsdb/tsm1/wal.go
Encode
func (w *DeleteRangeWALEntry) Encode(b []byte) ([]byte, error) { sz := w.MarshalSize() if len(b) < sz { b = make([]byte, sz) } binary.BigEndian.PutUint64(b[:8], uint64(w.Min)) binary.BigEndian.PutUint64(b[8:16], uint64(w.Max)) i := 16 for _, k := range w.Keys { binary.BigEndian.PutUint32(b[i:i+4], uint32(len(k))) i += 4 i += copy(b[i:], k) } return b[:i], nil }
go
func (w *DeleteRangeWALEntry) Encode(b []byte) ([]byte, error) { sz := w.MarshalSize() if len(b) < sz { b = make([]byte, sz) } binary.BigEndian.PutUint64(b[:8], uint64(w.Min)) binary.BigEndian.PutUint64(b[8:16], uint64(w.Max)) i := 16 for _, k := range w.Keys { binary.BigEndian.PutUint32(b[i:i+4], uint32(len(k))) i += 4 i += copy(b[i:], k) } return b[:i], nil }
[ "func", "(", "w", "*", "DeleteRangeWALEntry", ")", "Encode", "(", "b", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "sz", ":=", "w", ".", "MarshalSize", "(", ")", "\n\n", "if", "len", "(", "b", ")", "<", "sz", "{", "b", "=", "make", "(", "[", "]", "byte", ",", "sz", ")", "\n", "}", "\n\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", "[", ":", "8", "]", ",", "uint64", "(", "w", ".", "Min", ")", ")", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", "[", "8", ":", "16", "]", ",", "uint64", "(", "w", ".", "Max", ")", ")", "\n\n", "i", ":=", "16", "\n", "for", "_", ",", "k", ":=", "range", "w", ".", "Keys", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "b", "[", "i", ":", "i", "+", "4", "]", ",", "uint32", "(", "len", "(", "k", ")", ")", ")", "\n", "i", "+=", "4", "\n", "i", "+=", "copy", "(", "b", "[", "i", ":", "]", ",", "k", ")", "\n", "}", "\n\n", "return", "b", "[", ":", "i", "]", ",", "nil", "\n", "}" ]
// Encode converts the DeleteRangeWALEntry into a byte slice, appending to b.
[ "Encode", "converts", "the", "DeleteRangeWALEntry", "into", "a", "byte", "slice", "appending", "to", "b", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L1087-L1105
12,926
influxdata/platform
tsdb/tsm1/wal.go
Next
func (r *WALSegmentReader) Next() bool { var nReadOK int // read the type and the length of the entry var lv [5]byte n, err := io.ReadFull(r.r, lv[:]) if err == io.EOF { return false } if err != nil { r.err = err // We return true here because we want the client code to call read which // will return the this error to be handled. return true } nReadOK += n entryType := lv[0] length := binary.BigEndian.Uint32(lv[1:5]) b := *(getBuf(int(length))) defer putBuf(&b) // read the compressed block and decompress it n, err = io.ReadFull(r.r, b[:length]) if err != nil { r.err = err return true } nReadOK += n decLen, err := snappy.DecodedLen(b[:length]) if err != nil { r.err = err return true } decBuf := *(getBuf(decLen)) defer putBuf(&decBuf) data, err := snappy.Decode(decBuf, b[:length]) if err != nil { r.err = err return true } // and marshal it and send it to the cache switch WalEntryType(entryType) { case WriteWALEntryType: r.entry = &WriteWALEntry{ Values: make(map[string][]Value), } case DeleteWALEntryType: r.entry = &DeleteWALEntry{} case DeleteRangeWALEntryType: r.entry = &DeleteRangeWALEntry{} default: r.err = fmt.Errorf("unknown wal entry type: %v", entryType) return true } r.err = r.entry.UnmarshalBinary(data) if r.err == nil { // Read and decode of this entry was successful. r.n += int64(nReadOK) } return true }
go
func (r *WALSegmentReader) Next() bool { var nReadOK int // read the type and the length of the entry var lv [5]byte n, err := io.ReadFull(r.r, lv[:]) if err == io.EOF { return false } if err != nil { r.err = err // We return true here because we want the client code to call read which // will return the this error to be handled. return true } nReadOK += n entryType := lv[0] length := binary.BigEndian.Uint32(lv[1:5]) b := *(getBuf(int(length))) defer putBuf(&b) // read the compressed block and decompress it n, err = io.ReadFull(r.r, b[:length]) if err != nil { r.err = err return true } nReadOK += n decLen, err := snappy.DecodedLen(b[:length]) if err != nil { r.err = err return true } decBuf := *(getBuf(decLen)) defer putBuf(&decBuf) data, err := snappy.Decode(decBuf, b[:length]) if err != nil { r.err = err return true } // and marshal it and send it to the cache switch WalEntryType(entryType) { case WriteWALEntryType: r.entry = &WriteWALEntry{ Values: make(map[string][]Value), } case DeleteWALEntryType: r.entry = &DeleteWALEntry{} case DeleteRangeWALEntryType: r.entry = &DeleteRangeWALEntry{} default: r.err = fmt.Errorf("unknown wal entry type: %v", entryType) return true } r.err = r.entry.UnmarshalBinary(data) if r.err == nil { // Read and decode of this entry was successful. r.n += int64(nReadOK) } return true }
[ "func", "(", "r", "*", "WALSegmentReader", ")", "Next", "(", ")", "bool", "{", "var", "nReadOK", "int", "\n\n", "// read the type and the length of the entry", "var", "lv", "[", "5", "]", "byte", "\n", "n", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ".", "r", ",", "lv", "[", ":", "]", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "false", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "r", ".", "err", "=", "err", "\n", "// We return true here because we want the client code to call read which", "// will return the this error to be handled.", "return", "true", "\n", "}", "\n", "nReadOK", "+=", "n", "\n\n", "entryType", ":=", "lv", "[", "0", "]", "\n", "length", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "lv", "[", "1", ":", "5", "]", ")", "\n\n", "b", ":=", "*", "(", "getBuf", "(", "int", "(", "length", ")", ")", ")", "\n", "defer", "putBuf", "(", "&", "b", ")", "\n\n", "// read the compressed block and decompress it", "n", ",", "err", "=", "io", ".", "ReadFull", "(", "r", ".", "r", ",", "b", "[", ":", "length", "]", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "err", "=", "err", "\n", "return", "true", "\n", "}", "\n", "nReadOK", "+=", "n", "\n\n", "decLen", ",", "err", ":=", "snappy", ".", "DecodedLen", "(", "b", "[", ":", "length", "]", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "err", "=", "err", "\n", "return", "true", "\n", "}", "\n", "decBuf", ":=", "*", "(", "getBuf", "(", "decLen", ")", ")", "\n", "defer", "putBuf", "(", "&", "decBuf", ")", "\n\n", "data", ",", "err", ":=", "snappy", ".", "Decode", "(", "decBuf", ",", "b", "[", ":", "length", "]", ")", "\n", "if", "err", "!=", "nil", "{", "r", ".", "err", "=", "err", "\n", "return", "true", "\n", "}", "\n\n", "// and marshal it and send it to the cache", "switch", "WalEntryType", "(", "entryType", ")", "{", "case", "WriteWALEntryType", ":", "r", ".", "entry", "=", "&", "WriteWALEntry", "{", "Values", ":", "make", "(", "map", "[", "string", "]", "[", "]", "Value", ")", ",", "}", "\n", "case", "DeleteWALEntryType", ":", "r", ".", "entry", "=", "&", "DeleteWALEntry", "{", "}", "\n", "case", "DeleteRangeWALEntryType", ":", "r", ".", "entry", "=", "&", "DeleteRangeWALEntry", "{", "}", "\n", "default", ":", "r", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "entryType", ")", "\n", "return", "true", "\n", "}", "\n", "r", ".", "err", "=", "r", ".", "entry", ".", "UnmarshalBinary", "(", "data", ")", "\n", "if", "r", ".", "err", "==", "nil", "{", "// Read and decode of this entry was successful.", "r", ".", "n", "+=", "int64", "(", "nReadOK", ")", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Next indicates if there is a value to read.
[ "Next", "indicates", "if", "there", "is", "a", "value", "to", "read", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/wal.go#L1203-L1270
12,927
influxdata/platform
bolt/authorization.go
SetAuthorizationStatus
func (c *Client) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) error { return c.db.Update(func(tx *bolt.Tx) error { if pe := c.updateAuthorization(ctx, tx, id, status); pe != nil { return &platform.Error{ Err: pe, Op: platform.OpSetAuthorizationStatus, } } return nil }) }
go
func (c *Client) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) error { return c.db.Update(func(tx *bolt.Tx) error { if pe := c.updateAuthorization(ctx, tx, id, status); pe != nil { return &platform.Error{ Err: pe, Op: platform.OpSetAuthorizationStatus, } } return nil }) }
[ "func", "(", "c", "*", "Client", ")", "SetAuthorizationStatus", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "status", "platform", ".", "Status", ")", "error", "{", "return", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "if", "pe", ":=", "c", ".", "updateAuthorization", "(", "ctx", ",", "tx", ",", "id", ",", "status", ")", ";", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Err", ":", "pe", ",", "Op", ":", "platform", ".", "OpSetAuthorizationStatus", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// SetAuthorizationStatus updates the status of the authorization. Useful // for setting an authorization to inactive or active.
[ "SetAuthorizationStatus", "updates", "the", "status", "of", "the", "authorization", ".", "Useful", "for", "setting", "an", "authorization", "to", "inactive", "or", "active", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/authorization.go#L377-L387
12,928
influxdata/platform
cmd/influx/main.go
Execute
func Execute() { if err := influxCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } }
go
func Execute() { if err := influxCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } }
[ "func", "Execute", "(", ")", "{", "if", "err", ":=", "influxCmd", ".", "Execute", "(", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "err", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}" ]
// Execute executes the influx command
[ "Execute", "executes", "the", "influx", "command" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/cmd/influx/main.go#L90-L95
12,929
influxdata/platform
tsdb/tsm1/cache.go
init
func (c *Cache) init() { if !atomic.CompareAndSwapUint32(&c.initializedCount, 0, 1) { return } c.mu.Lock() c.store, _ = newring(ringShards) c.mu.Unlock() }
go
func (c *Cache) init() { if !atomic.CompareAndSwapUint32(&c.initializedCount, 0, 1) { return } c.mu.Lock() c.store, _ = newring(ringShards) c.mu.Unlock() }
[ "func", "(", "c", "*", "Cache", ")", "init", "(", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapUint32", "(", "&", "c", ".", "initializedCount", ",", "0", ",", "1", ")", "{", "return", "\n", "}", "\n\n", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "c", ".", "store", ",", "_", "=", "newring", "(", "ringShards", ")", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// init initializes the cache and allocates the underlying store. Once initialized, // the store re-used until Freed.
[ "init", "initializes", "the", "cache", "and", "allocates", "the", "underlying", "store", ".", "Once", "initialized", "the", "store", "re", "-", "used", "until", "Freed", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L199-L207
12,930
influxdata/platform
tsdb/tsm1/cache.go
Free
func (c *Cache) Free() { if !atomic.CompareAndSwapUint32(&c.initializedCount, 1, 0) { return } c.mu.Lock() c.store = emptyStore{} c.mu.Unlock() }
go
func (c *Cache) Free() { if !atomic.CompareAndSwapUint32(&c.initializedCount, 1, 0) { return } c.mu.Lock() c.store = emptyStore{} c.mu.Unlock() }
[ "func", "(", "c", "*", "Cache", ")", "Free", "(", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapUint32", "(", "&", "c", ".", "initializedCount", ",", "1", ",", "0", ")", "{", "return", "\n", "}", "\n\n", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "c", ".", "store", "=", "emptyStore", "{", "}", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Free releases the underlying store and memory held by the Cache.
[ "Free", "releases", "the", "underlying", "store", "and", "memory", "held", "by", "the", "Cache", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L210-L218
12,931
influxdata/platform
tsdb/tsm1/cache.go
Write
func (c *Cache) Write(key []byte, values []Value) error { c.init() addedSize := uint64(Values(values).Size()) // Enough room in the cache? limit := c.maxSize n := c.Size() + addedSize if limit > 0 && n > limit { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesDrop(uint64(addedSize)) return ErrCacheMemorySizeLimitExceeded(n, limit) } newKey, err := c.store.write(key, values) if err != nil { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesErr(uint64(addedSize)) return err } if newKey { addedSize += uint64(len(key)) } // Update the cache size and the memory size stat. c.tracker.IncCacheSize(addedSize) c.tracker.AddMemBytes(addedSize) c.tracker.AddWrittenBytesOK(uint64(addedSize)) c.tracker.IncWritesOK() return nil }
go
func (c *Cache) Write(key []byte, values []Value) error { c.init() addedSize := uint64(Values(values).Size()) // Enough room in the cache? limit := c.maxSize n := c.Size() + addedSize if limit > 0 && n > limit { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesDrop(uint64(addedSize)) return ErrCacheMemorySizeLimitExceeded(n, limit) } newKey, err := c.store.write(key, values) if err != nil { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesErr(uint64(addedSize)) return err } if newKey { addedSize += uint64(len(key)) } // Update the cache size and the memory size stat. c.tracker.IncCacheSize(addedSize) c.tracker.AddMemBytes(addedSize) c.tracker.AddWrittenBytesOK(uint64(addedSize)) c.tracker.IncWritesOK() return nil }
[ "func", "(", "c", "*", "Cache", ")", "Write", "(", "key", "[", "]", "byte", ",", "values", "[", "]", "Value", ")", "error", "{", "c", ".", "init", "(", ")", "\n", "addedSize", ":=", "uint64", "(", "Values", "(", "values", ")", ".", "Size", "(", ")", ")", "\n\n", "// Enough room in the cache?", "limit", ":=", "c", ".", "maxSize", "\n", "n", ":=", "c", ".", "Size", "(", ")", "+", "addedSize", "\n\n", "if", "limit", ">", "0", "&&", "n", ">", "limit", "{", "c", ".", "tracker", ".", "IncWritesErr", "(", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesDrop", "(", "uint64", "(", "addedSize", ")", ")", "\n", "return", "ErrCacheMemorySizeLimitExceeded", "(", "n", ",", "limit", ")", "\n", "}", "\n\n", "newKey", ",", "err", ":=", "c", ".", "store", ".", "write", "(", "key", ",", "values", ")", "\n", "if", "err", "!=", "nil", "{", "c", ".", "tracker", ".", "IncWritesErr", "(", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesErr", "(", "uint64", "(", "addedSize", ")", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "newKey", "{", "addedSize", "+=", "uint64", "(", "len", "(", "key", ")", ")", "\n", "}", "\n", "// Update the cache size and the memory size stat.", "c", ".", "tracker", ".", "IncCacheSize", "(", "addedSize", ")", "\n", "c", ".", "tracker", ".", "AddMemBytes", "(", "addedSize", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesOK", "(", "uint64", "(", "addedSize", ")", ")", "\n", "c", ".", "tracker", ".", "IncWritesOK", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Write writes the set of values for the key to the cache. This function is goroutine-safe. // It returns an error if the cache will exceed its max size by adding the new values.
[ "Write", "writes", "the", "set", "of", "values", "for", "the", "key", "to", "the", "cache", ".", "This", "function", "is", "goroutine", "-", "safe", ".", "It", "returns", "an", "error", "if", "the", "cache", "will", "exceed", "its", "max", "size", "by", "adding", "the", "new", "values", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L222-L253
12,932
influxdata/platform
tsdb/tsm1/cache.go
WriteMulti
func (c *Cache) WriteMulti(values map[string][]Value) error { c.init() var addedSize uint64 for _, v := range values { addedSize += uint64(Values(v).Size()) } // Enough room in the cache? limit := c.maxSize // maxSize is safe for reading without a lock. n := c.Size() + addedSize if limit > 0 && n > limit { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesDrop(uint64(addedSize)) return ErrCacheMemorySizeLimitExceeded(n, limit) } var werr error c.mu.RLock() store := c.store c.mu.RUnlock() var bytesWrittenErr uint64 // We'll optimistically set size here, and then decrement it for write errors. for k, v := range values { newKey, err := store.write([]byte(k), v) if err != nil { // The write failed, hold onto the error and adjust the size delta. werr = err addedSize -= uint64(Values(v).Size()) bytesWrittenErr += uint64(Values(v).Size()) } if newKey { addedSize += uint64(len(k)) } } // Some points in the batch were dropped. An error is returned so // error stat is incremented as well. if werr != nil { c.tracker.IncWritesErr() c.tracker.IncWritesDrop() c.tracker.AddWrittenBytesErr(bytesWrittenErr) } // Update the memory size stat c.tracker.IncCacheSize(addedSize) c.tracker.AddMemBytes(addedSize) c.tracker.IncWritesOK() c.tracker.AddWrittenBytesOK(addedSize) c.mu.Lock() c.lastWriteTime = time.Now() c.mu.Unlock() return werr }
go
func (c *Cache) WriteMulti(values map[string][]Value) error { c.init() var addedSize uint64 for _, v := range values { addedSize += uint64(Values(v).Size()) } // Enough room in the cache? limit := c.maxSize // maxSize is safe for reading without a lock. n := c.Size() + addedSize if limit > 0 && n > limit { c.tracker.IncWritesErr() c.tracker.AddWrittenBytesDrop(uint64(addedSize)) return ErrCacheMemorySizeLimitExceeded(n, limit) } var werr error c.mu.RLock() store := c.store c.mu.RUnlock() var bytesWrittenErr uint64 // We'll optimistically set size here, and then decrement it for write errors. for k, v := range values { newKey, err := store.write([]byte(k), v) if err != nil { // The write failed, hold onto the error and adjust the size delta. werr = err addedSize -= uint64(Values(v).Size()) bytesWrittenErr += uint64(Values(v).Size()) } if newKey { addedSize += uint64(len(k)) } } // Some points in the batch were dropped. An error is returned so // error stat is incremented as well. if werr != nil { c.tracker.IncWritesErr() c.tracker.IncWritesDrop() c.tracker.AddWrittenBytesErr(bytesWrittenErr) } // Update the memory size stat c.tracker.IncCacheSize(addedSize) c.tracker.AddMemBytes(addedSize) c.tracker.IncWritesOK() c.tracker.AddWrittenBytesOK(addedSize) c.mu.Lock() c.lastWriteTime = time.Now() c.mu.Unlock() return werr }
[ "func", "(", "c", "*", "Cache", ")", "WriteMulti", "(", "values", "map", "[", "string", "]", "[", "]", "Value", ")", "error", "{", "c", ".", "init", "(", ")", "\n", "var", "addedSize", "uint64", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "addedSize", "+=", "uint64", "(", "Values", "(", "v", ")", ".", "Size", "(", ")", ")", "\n", "}", "\n\n", "// Enough room in the cache?", "limit", ":=", "c", ".", "maxSize", "// maxSize is safe for reading without a lock.", "\n", "n", ":=", "c", ".", "Size", "(", ")", "+", "addedSize", "\n", "if", "limit", ">", "0", "&&", "n", ">", "limit", "{", "c", ".", "tracker", ".", "IncWritesErr", "(", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesDrop", "(", "uint64", "(", "addedSize", ")", ")", "\n", "return", "ErrCacheMemorySizeLimitExceeded", "(", "n", ",", "limit", ")", "\n", "}", "\n\n", "var", "werr", "error", "\n", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "store", ":=", "c", ".", "store", "\n", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n\n", "var", "bytesWrittenErr", "uint64", "\n\n", "// We'll optimistically set size here, and then decrement it for write errors.", "for", "k", ",", "v", ":=", "range", "values", "{", "newKey", ",", "err", ":=", "store", ".", "write", "(", "[", "]", "byte", "(", "k", ")", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "// The write failed, hold onto the error and adjust the size delta.", "werr", "=", "err", "\n", "addedSize", "-=", "uint64", "(", "Values", "(", "v", ")", ".", "Size", "(", ")", ")", "\n", "bytesWrittenErr", "+=", "uint64", "(", "Values", "(", "v", ")", ".", "Size", "(", ")", ")", "\n", "}", "\n\n", "if", "newKey", "{", "addedSize", "+=", "uint64", "(", "len", "(", "k", ")", ")", "\n", "}", "\n", "}", "\n\n", "// Some points in the batch were dropped. An error is returned so", "// error stat is incremented as well.", "if", "werr", "!=", "nil", "{", "c", ".", "tracker", ".", "IncWritesErr", "(", ")", "\n", "c", ".", "tracker", ".", "IncWritesDrop", "(", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesErr", "(", "bytesWrittenErr", ")", "\n", "}", "\n\n", "// Update the memory size stat", "c", ".", "tracker", ".", "IncCacheSize", "(", "addedSize", ")", "\n", "c", ".", "tracker", ".", "AddMemBytes", "(", "addedSize", ")", "\n", "c", ".", "tracker", ".", "IncWritesOK", "(", ")", "\n", "c", ".", "tracker", ".", "AddWrittenBytesOK", "(", "addedSize", ")", "\n\n", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "c", ".", "lastWriteTime", "=", "time", ".", "Now", "(", ")", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "werr", "\n", "}" ]
// WriteMulti writes the map of keys and associated values to the cache. This // function is goroutine-safe. It returns an error if the cache will exceeded // its max size by adding the new values. The write attempts to write as many // values as possible. If one key fails, the others can still succeed and an // error will be returned.
[ "WriteMulti", "writes", "the", "map", "of", "keys", "and", "associated", "values", "to", "the", "cache", ".", "This", "function", "is", "goroutine", "-", "safe", ".", "It", "returns", "an", "error", "if", "the", "cache", "will", "exceeded", "its", "max", "size", "by", "adding", "the", "new", "values", ".", "The", "write", "attempts", "to", "write", "as", "many", "values", "as", "possible", ".", "If", "one", "key", "fails", "the", "others", "can", "still", "succeed", "and", "an", "error", "will", "be", "returned", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L260-L317
12,933
influxdata/platform
tsdb/tsm1/cache.go
Delete
func (c *Cache) Delete(keys [][]byte) { c.DeleteRange(keys, math.MinInt64, math.MaxInt64) }
go
func (c *Cache) Delete(keys [][]byte) { c.DeleteRange(keys, math.MinInt64, math.MaxInt64) }
[ "func", "(", "c", "*", "Cache", ")", "Delete", "(", "keys", "[", "]", "[", "]", "byte", ")", "{", "c", ".", "DeleteRange", "(", "keys", ",", "math", ".", "MinInt64", ",", "math", ".", "MaxInt64", ")", "\n", "}" ]
// Delete removes all values for the given keys from the cache.
[ "Delete", "removes", "all", "values", "for", "the", "given", "keys", "from", "the", "cache", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L549-L551
12,934
influxdata/platform
tsdb/tsm1/cache.go
NewCacheLoader
func NewCacheLoader(files []string) *CacheLoader { return &CacheLoader{ files: files, Logger: zap.NewNop(), } }
go
func NewCacheLoader(files []string) *CacheLoader { return &CacheLoader{ files: files, Logger: zap.NewNop(), } }
[ "func", "NewCacheLoader", "(", "files", "[", "]", "string", ")", "*", "CacheLoader", "{", "return", "&", "CacheLoader", "{", "files", ":", "files", ",", "Logger", ":", "zap", ".", "NewNop", "(", ")", ",", "}", "\n", "}" ]
// NewCacheLoader returns a new instance of a CacheLoader.
[ "NewCacheLoader", "returns", "a", "new", "instance", "of", "a", "CacheLoader", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L636-L641
12,935
influxdata/platform
tsdb/tsm1/cache.go
Load
func (cl *CacheLoader) Load(cache *Cache) error { var r *WALSegmentReader for _, fn := range cl.files { if err := func() error { f, err := os.OpenFile(fn, os.O_CREATE|os.O_RDWR, 0666) if err != nil { return err } defer f.Close() // Log some information about the segments. stat, err := os.Stat(f.Name()) if err != nil { return err } cl.Logger.Info("Reading file", zap.String("path", f.Name()), zap.Int64("size", stat.Size())) // Nothing to read, skip it if stat.Size() == 0 { return nil } if r == nil { r = NewWALSegmentReader(f) defer r.Close() } else { r.Reset(f) } for r.Next() { entry, err := r.Read() if err != nil { n := r.Count() cl.Logger.Info("File corrupt", zap.Error(err), zap.String("path", f.Name()), zap.Int64("pos", n)) if err := f.Truncate(n); err != nil { return err } break } switch t := entry.(type) { case *WriteWALEntry: if err := cache.WriteMulti(t.Values); err != nil { return err } case *DeleteRangeWALEntry: cache.DeleteRange(t.Keys, t.Min, t.Max) case *DeleteWALEntry: cache.Delete(t.Keys) } } return r.Close() }(); err != nil { return err } } return nil }
go
func (cl *CacheLoader) Load(cache *Cache) error { var r *WALSegmentReader for _, fn := range cl.files { if err := func() error { f, err := os.OpenFile(fn, os.O_CREATE|os.O_RDWR, 0666) if err != nil { return err } defer f.Close() // Log some information about the segments. stat, err := os.Stat(f.Name()) if err != nil { return err } cl.Logger.Info("Reading file", zap.String("path", f.Name()), zap.Int64("size", stat.Size())) // Nothing to read, skip it if stat.Size() == 0 { return nil } if r == nil { r = NewWALSegmentReader(f) defer r.Close() } else { r.Reset(f) } for r.Next() { entry, err := r.Read() if err != nil { n := r.Count() cl.Logger.Info("File corrupt", zap.Error(err), zap.String("path", f.Name()), zap.Int64("pos", n)) if err := f.Truncate(n); err != nil { return err } break } switch t := entry.(type) { case *WriteWALEntry: if err := cache.WriteMulti(t.Values); err != nil { return err } case *DeleteRangeWALEntry: cache.DeleteRange(t.Keys, t.Min, t.Max) case *DeleteWALEntry: cache.Delete(t.Keys) } } return r.Close() }(); err != nil { return err } } return nil }
[ "func", "(", "cl", "*", "CacheLoader", ")", "Load", "(", "cache", "*", "Cache", ")", "error", "{", "var", "r", "*", "WALSegmentReader", "\n", "for", "_", ",", "fn", ":=", "range", "cl", ".", "files", "{", "if", "err", ":=", "func", "(", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "OpenFile", "(", "fn", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_RDWR", ",", "0666", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "// Log some information about the segments.", "stat", ",", "err", ":=", "os", ".", "Stat", "(", "f", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "cl", ".", "Logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "f", ".", "Name", "(", ")", ")", ",", "zap", ".", "Int64", "(", "\"", "\"", ",", "stat", ".", "Size", "(", ")", ")", ")", "\n\n", "// Nothing to read, skip it", "if", "stat", ".", "Size", "(", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "if", "r", "==", "nil", "{", "r", "=", "NewWALSegmentReader", "(", "f", ")", "\n", "defer", "r", ".", "Close", "(", ")", "\n", "}", "else", "{", "r", ".", "Reset", "(", "f", ")", "\n", "}", "\n\n", "for", "r", ".", "Next", "(", ")", "{", "entry", ",", "err", ":=", "r", ".", "Read", "(", ")", "\n", "if", "err", "!=", "nil", "{", "n", ":=", "r", ".", "Count", "(", ")", "\n", "cl", ".", "Logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ",", "zap", ".", "String", "(", "\"", "\"", ",", "f", ".", "Name", "(", ")", ")", ",", "zap", ".", "Int64", "(", "\"", "\"", ",", "n", ")", ")", "\n", "if", "err", ":=", "f", ".", "Truncate", "(", "n", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "break", "\n", "}", "\n\n", "switch", "t", ":=", "entry", ".", "(", "type", ")", "{", "case", "*", "WriteWALEntry", ":", "if", "err", ":=", "cache", ".", "WriteMulti", "(", "t", ".", "Values", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "*", "DeleteRangeWALEntry", ":", "cache", ".", "DeleteRange", "(", "t", ".", "Keys", ",", "t", ".", "Min", ",", "t", ".", "Max", ")", "\n", "case", "*", "DeleteWALEntry", ":", "cache", ".", "Delete", "(", "t", ".", "Keys", ")", "\n", "}", "\n", "}", "\n\n", "return", "r", ".", "Close", "(", ")", "\n", "}", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Load returns a cache loaded with the data contained within the segment files. // If, during reading of a segment file, corruption is encountered, that segment // file is truncated up to and including the last valid byte, and processing // continues with the next segment file.
[ "Load", "returns", "a", "cache", "loaded", "with", "the", "data", "contained", "within", "the", "segment", "files", ".", "If", "during", "reading", "of", "a", "segment", "file", "corruption", "is", "encountered", "that", "segment", "file", "is", "truncated", "up", "to", "and", "including", "the", "last", "valid", "byte", "and", "processing", "continues", "with", "the", "next", "segment", "file", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/tsm1/cache.go#L647-L706
12,936
influxdata/platform
view.go
UnmarshalViewPropertiesJSON
func UnmarshalViewPropertiesJSON(b []byte) (ViewProperties, error) { var v struct { B json.RawMessage `json:"properties"` } if err := json.Unmarshal(b, &v); err != nil { return nil, err } if len(v.B) == 0 { // Then there wasn't any visualization field, so there's no need unmarshal it return EmptyViewProperties{}, nil } var t struct { Shape string `json:"shape"` Type string `json:"type"` } if err := json.Unmarshal(v.B, &t); err != nil { return nil, err } var vis ViewProperties switch t.Shape { case "chronograf-v2": switch t.Type { case "xy": var xyv XYViewProperties if err := json.Unmarshal(v.B, &xyv); err != nil { return nil, err } vis = xyv case "single-stat": var ssv SingleStatViewProperties if err := json.Unmarshal(v.B, &ssv); err != nil { return nil, err } vis = ssv case "gauge": var gv GaugeViewProperties if err := json.Unmarshal(v.B, &gv); err != nil { return nil, err } vis = gv case "table": var tv TableViewProperties if err := json.Unmarshal(v.B, &tv); err != nil { return nil, err } vis = tv case "markdown": var mv MarkdownViewProperties if err := json.Unmarshal(v.B, &mv); err != nil { return nil, err } vis = mv case "log-viewer": // happens in log viewer stays in log viewer. var lv LogViewProperties if err := json.Unmarshal(v.B, &lv); err != nil { return nil, err } vis = lv case "line-plus-single-stat": var lv LinePlusSingleStatProperties if err := json.Unmarshal(v.B, &lv); err != nil { return nil, err } vis = lv } case "empty": var ev EmptyViewProperties if err := json.Unmarshal(v.B, &ev); err != nil { return nil, err } vis = ev default: return nil, fmt.Errorf("unknown type %v", t.Shape) } return vis, nil }
go
func UnmarshalViewPropertiesJSON(b []byte) (ViewProperties, error) { var v struct { B json.RawMessage `json:"properties"` } if err := json.Unmarshal(b, &v); err != nil { return nil, err } if len(v.B) == 0 { // Then there wasn't any visualization field, so there's no need unmarshal it return EmptyViewProperties{}, nil } var t struct { Shape string `json:"shape"` Type string `json:"type"` } if err := json.Unmarshal(v.B, &t); err != nil { return nil, err } var vis ViewProperties switch t.Shape { case "chronograf-v2": switch t.Type { case "xy": var xyv XYViewProperties if err := json.Unmarshal(v.B, &xyv); err != nil { return nil, err } vis = xyv case "single-stat": var ssv SingleStatViewProperties if err := json.Unmarshal(v.B, &ssv); err != nil { return nil, err } vis = ssv case "gauge": var gv GaugeViewProperties if err := json.Unmarshal(v.B, &gv); err != nil { return nil, err } vis = gv case "table": var tv TableViewProperties if err := json.Unmarshal(v.B, &tv); err != nil { return nil, err } vis = tv case "markdown": var mv MarkdownViewProperties if err := json.Unmarshal(v.B, &mv); err != nil { return nil, err } vis = mv case "log-viewer": // happens in log viewer stays in log viewer. var lv LogViewProperties if err := json.Unmarshal(v.B, &lv); err != nil { return nil, err } vis = lv case "line-plus-single-stat": var lv LinePlusSingleStatProperties if err := json.Unmarshal(v.B, &lv); err != nil { return nil, err } vis = lv } case "empty": var ev EmptyViewProperties if err := json.Unmarshal(v.B, &ev); err != nil { return nil, err } vis = ev default: return nil, fmt.Errorf("unknown type %v", t.Shape) } return vis, nil }
[ "func", "UnmarshalViewPropertiesJSON", "(", "b", "[", "]", "byte", ")", "(", "ViewProperties", ",", "error", ")", "{", "var", "v", "struct", "{", "B", "json", ".", "RawMessage", "`json:\"properties\"`", "\n", "}", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "v", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "v", ".", "B", ")", "==", "0", "{", "// Then there wasn't any visualization field, so there's no need unmarshal it", "return", "EmptyViewProperties", "{", "}", ",", "nil", "\n", "}", "\n\n", "var", "t", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "Type", "string", "`json:\"type\"`", "\n", "}", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "t", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "vis", "ViewProperties", "\n", "switch", "t", ".", "Shape", "{", "case", "\"", "\"", ":", "switch", "t", ".", "Type", "{", "case", "\"", "\"", ":", "var", "xyv", "XYViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "xyv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "xyv", "\n", "case", "\"", "\"", ":", "var", "ssv", "SingleStatViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "ssv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "ssv", "\n", "case", "\"", "\"", ":", "var", "gv", "GaugeViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "gv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "gv", "\n", "case", "\"", "\"", ":", "var", "tv", "TableViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "tv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "tv", "\n", "case", "\"", "\"", ":", "var", "mv", "MarkdownViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "mv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "mv", "\n", "case", "\"", "\"", ":", "// happens in log viewer stays in log viewer.", "var", "lv", "LogViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "lv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "lv", "\n", "case", "\"", "\"", ":", "var", "lv", "LinePlusSingleStatProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "lv", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "lv", "\n", "}", "\n", "case", "\"", "\"", ":", "var", "ev", "EmptyViewProperties", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "B", ",", "&", "ev", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vis", "=", "ev", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "t", ".", "Shape", ")", "\n", "}", "\n\n", "return", "vis", ",", "nil", "\n", "}" ]
// UnmarshalViewPropertiesJSON unmarshals JSON bytes into a ViewProperties.
[ "UnmarshalViewPropertiesJSON", "unmarshals", "JSON", "bytes", "into", "a", "ViewProperties", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/view.go#L117-L198
12,937
influxdata/platform
view.go
MarshalViewPropertiesJSON
func MarshalViewPropertiesJSON(v ViewProperties) ([]byte, error) { var s interface{} switch vis := v.(type) { case SingleStatViewProperties: s = struct { Shape string `json:"shape"` SingleStatViewProperties }{ Shape: "chronograf-v2", SingleStatViewProperties: vis, } case TableViewProperties: s = struct { Shape string `json:"shape"` TableViewProperties }{ Shape: "chronograf-v2", TableViewProperties: vis, } case GaugeViewProperties: s = struct { Shape string `json:"shape"` GaugeViewProperties }{ Shape: "chronograf-v2", GaugeViewProperties: vis, } case XYViewProperties: s = struct { Shape string `json:"shape"` XYViewProperties }{ Shape: "chronograf-v2", XYViewProperties: vis, } case LinePlusSingleStatProperties: s = struct { Shape string `json:"shape"` LinePlusSingleStatProperties }{ Shape: "chronograf-v2", LinePlusSingleStatProperties: vis, } case MarkdownViewProperties: s = struct { Shape string `json:"shape"` MarkdownViewProperties }{ Shape: "chronograf-v2", MarkdownViewProperties: vis, } case LogViewProperties: s = struct { Shape string `json:"shape"` LogViewProperties }{ Shape: "chronograf-v2", LogViewProperties: vis, } default: s = struct { Shape string `json:"shape"` EmptyViewProperties }{ Shape: "empty", EmptyViewProperties: EmptyViewProperties{}, } } return json.Marshal(s) }
go
func MarshalViewPropertiesJSON(v ViewProperties) ([]byte, error) { var s interface{} switch vis := v.(type) { case SingleStatViewProperties: s = struct { Shape string `json:"shape"` SingleStatViewProperties }{ Shape: "chronograf-v2", SingleStatViewProperties: vis, } case TableViewProperties: s = struct { Shape string `json:"shape"` TableViewProperties }{ Shape: "chronograf-v2", TableViewProperties: vis, } case GaugeViewProperties: s = struct { Shape string `json:"shape"` GaugeViewProperties }{ Shape: "chronograf-v2", GaugeViewProperties: vis, } case XYViewProperties: s = struct { Shape string `json:"shape"` XYViewProperties }{ Shape: "chronograf-v2", XYViewProperties: vis, } case LinePlusSingleStatProperties: s = struct { Shape string `json:"shape"` LinePlusSingleStatProperties }{ Shape: "chronograf-v2", LinePlusSingleStatProperties: vis, } case MarkdownViewProperties: s = struct { Shape string `json:"shape"` MarkdownViewProperties }{ Shape: "chronograf-v2", MarkdownViewProperties: vis, } case LogViewProperties: s = struct { Shape string `json:"shape"` LogViewProperties }{ Shape: "chronograf-v2", LogViewProperties: vis, } default: s = struct { Shape string `json:"shape"` EmptyViewProperties }{ Shape: "empty", EmptyViewProperties: EmptyViewProperties{}, } } return json.Marshal(s) }
[ "func", "MarshalViewPropertiesJSON", "(", "v", "ViewProperties", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "s", "interface", "{", "}", "\n", "switch", "vis", ":=", "v", ".", "(", "type", ")", "{", "case", "SingleStatViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "SingleStatViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "SingleStatViewProperties", ":", "vis", ",", "}", "\n", "case", "TableViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "TableViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "TableViewProperties", ":", "vis", ",", "}", "\n", "case", "GaugeViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "GaugeViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "GaugeViewProperties", ":", "vis", ",", "}", "\n", "case", "XYViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "XYViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "XYViewProperties", ":", "vis", ",", "}", "\n", "case", "LinePlusSingleStatProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "LinePlusSingleStatProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "LinePlusSingleStatProperties", ":", "vis", ",", "}", "\n", "case", "MarkdownViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "MarkdownViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "MarkdownViewProperties", ":", "vis", ",", "}", "\n", "case", "LogViewProperties", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "LogViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "LogViewProperties", ":", "vis", ",", "}", "\n", "default", ":", "s", "=", "struct", "{", "Shape", "string", "`json:\"shape\"`", "\n", "EmptyViewProperties", "\n", "}", "{", "Shape", ":", "\"", "\"", ",", "EmptyViewProperties", ":", "EmptyViewProperties", "{", "}", ",", "}", "\n", "}", "\n", "return", "json", ".", "Marshal", "(", "s", ")", "\n", "}" ]
// MarshalViewPropertiesJSON encodes a view into JSON bytes.
[ "MarshalViewPropertiesJSON", "encodes", "a", "view", "into", "JSON", "bytes", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/view.go#L201-L270
12,938
influxdata/platform
http/proto.go
NewProtoBackend
func NewProtoBackend(b *APIBackend) *ProtoBackend { return &ProtoBackend{ Logger: b.Logger.With(zap.String("handler", "proto")), ProtoService: b.ProtoService, LabelService: b.LabelService, } }
go
func NewProtoBackend(b *APIBackend) *ProtoBackend { return &ProtoBackend{ Logger: b.Logger.With(zap.String("handler", "proto")), ProtoService: b.ProtoService, LabelService: b.LabelService, } }
[ "func", "NewProtoBackend", "(", "b", "*", "APIBackend", ")", "*", "ProtoBackend", "{", "return", "&", "ProtoBackend", "{", "Logger", ":", "b", ".", "Logger", ".", "With", "(", "zap", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ")", ",", "ProtoService", ":", "b", ".", "ProtoService", ",", "LabelService", ":", "b", ".", "LabelService", ",", "}", "\n", "}" ]
// NewProtoBackend creates an instance of the Protobackend from the APIBackend.
[ "NewProtoBackend", "creates", "an", "instance", "of", "the", "Protobackend", "from", "the", "APIBackend", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/proto.go#L55-L61
12,939
influxdata/platform
http/proto.go
NewProtoHandler
func NewProtoHandler(b *ProtoBackend) *ProtoHandler { h := &ProtoHandler{ Router: NewRouter(), Logger: b.Logger, ProtoService: b.ProtoService, LabelService: b.LabelService, } h.HandlerFunc("GET", protosPath, h.handleGetProtos) h.HandlerFunc("POST", protosDashboardsPath, h.handlePostProtosDashboards) return h }
go
func NewProtoHandler(b *ProtoBackend) *ProtoHandler { h := &ProtoHandler{ Router: NewRouter(), Logger: b.Logger, ProtoService: b.ProtoService, LabelService: b.LabelService, } h.HandlerFunc("GET", protosPath, h.handleGetProtos) h.HandlerFunc("POST", protosDashboardsPath, h.handlePostProtosDashboards) return h }
[ "func", "NewProtoHandler", "(", "b", "*", "ProtoBackend", ")", "*", "ProtoHandler", "{", "h", ":=", "&", "ProtoHandler", "{", "Router", ":", "NewRouter", "(", ")", ",", "Logger", ":", "b", ".", "Logger", ",", "ProtoService", ":", "b", ".", "ProtoService", ",", "LabelService", ":", "b", ".", "LabelService", ",", "}", "\n\n", "h", ".", "HandlerFunc", "(", "\"", "\"", ",", "protosPath", ",", "h", ".", "handleGetProtos", ")", "\n", "h", ".", "HandlerFunc", "(", "\"", "\"", ",", "protosDashboardsPath", ",", "h", ".", "handlePostProtosDashboards", ")", "\n\n", "return", "h", "\n", "}" ]
// NewProtoHandler creates an instance of a proto handler.
[ "NewProtoHandler", "creates", "an", "instance", "of", "a", "proto", "handler", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/proto.go#L64-L76
12,940
influxdata/platform
http/proto.go
Decode
func (r *createProtoResourcesRequest) Decode(req *http.Request) error { ctx := req.Context() id, err := extractProtoID(ctx) if err != nil { return err } r.ProtoID = id if err := json.NewDecoder(req.Body).Decode(r); err != nil { return err } return nil }
go
func (r *createProtoResourcesRequest) Decode(req *http.Request) error { ctx := req.Context() id, err := extractProtoID(ctx) if err != nil { return err } r.ProtoID = id if err := json.NewDecoder(req.Body).Decode(r); err != nil { return err } return nil }
[ "func", "(", "r", "*", "createProtoResourcesRequest", ")", "Decode", "(", "req", "*", "http", ".", "Request", ")", "error", "{", "ctx", ":=", "req", ".", "Context", "(", ")", "\n", "id", ",", "err", ":=", "extractProtoID", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "r", ".", "ProtoID", "=", "id", "\n\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "req", ".", "Body", ")", ".", "Decode", "(", "r", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Decode turns an http request into a createProtoResourceRequest.
[ "Decode", "turns", "an", "http", "request", "into", "a", "createProtoResourceRequest", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/proto.go#L128-L142
12,941
influxdata/platform
tsdb/errors.go
NewShardError
func NewShardError(id uint64, err error) error { if err == nil { return nil } return ShardError{id: id, Err: err} }
go
func NewShardError(id uint64, err error) error { if err == nil { return nil } return ShardError{id: id, Err: err} }
[ "func", "NewShardError", "(", "id", "uint64", ",", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "ShardError", "{", "id", ":", "id", ",", "Err", ":", "err", "}", "\n", "}" ]
// NewShardError returns a new ShardError.
[ "NewShardError", "returns", "a", "new", "ShardError", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/errors.go#L28-L33
12,942
influxdata/platform
http/org_service.go
UpdateOrganization
func (s *OrganizationService) UpdateOrganization(ctx context.Context, id platform.ID, upd platform.OrganizationUpdate) (*platform.Organization, error) { u, err := newURL(s.Addr, organizationIDPath(id)) if err != nil { return nil, err } octets, err := json.Marshal(upd) if err != nil { return nil, err } req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(octets)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(u.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, err } if err := CheckError(resp, true); err != nil { return nil, err } var o platform.Organization if err := json.NewDecoder(resp.Body).Decode(&o); err != nil { return nil, err } defer resp.Body.Close() return &o, nil }
go
func (s *OrganizationService) UpdateOrganization(ctx context.Context, id platform.ID, upd platform.OrganizationUpdate) (*platform.Organization, error) { u, err := newURL(s.Addr, organizationIDPath(id)) if err != nil { return nil, err } octets, err := json.Marshal(upd) if err != nil { return nil, err } req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(octets)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(u.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return nil, err } if err := CheckError(resp, true); err != nil { return nil, err } var o platform.Organization if err := json.NewDecoder(resp.Body).Decode(&o); err != nil { return nil, err } defer resp.Body.Close() return &o, nil }
[ "func", "(", "s", "*", "OrganizationService", ")", "UpdateOrganization", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "upd", "platform", ".", "OrganizationUpdate", ")", "(", "*", "platform", ".", "Organization", ",", "error", ")", "{", "u", ",", "err", ":=", "newURL", "(", "s", ".", "Addr", ",", "organizationIDPath", "(", "id", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "octets", ",", "err", ":=", "json", ".", "Marshal", "(", "upd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "bytes", ".", "NewReader", "(", "octets", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "SetToken", "(", "s", ".", "Token", ",", "req", ")", "\n\n", "hc", ":=", "newClient", "(", "u", ".", "Scheme", ",", "s", ".", "InsecureSkipVerify", ")", "\n\n", "resp", ",", "err", ":=", "hc", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "CheckError", "(", "resp", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "o", "platform", ".", "Organization", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "o", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "return", "&", "o", ",", "nil", "\n", "}" ]
// UpdateOrganization updates the organization over HTTP.
[ "UpdateOrganization", "updates", "the", "organization", "over", "HTTP", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/org_service.go#L632-L669
12,943
influxdata/platform
bolt/macro.go
FindMacroByID
func (c *Client) FindMacroByID(ctx context.Context, id platform.ID) (*platform.Macro, error) { op := getOp(platform.OpFindMacroByID) var macro *platform.Macro err := c.db.View(func(tx *bolt.Tx) error { m, pe := c.findMacroByID(ctx, tx, id) if pe != nil { return &platform.Error{ Op: op, Err: pe, } } macro = m return nil }) if err != nil { return nil, err } return macro, nil }
go
func (c *Client) FindMacroByID(ctx context.Context, id platform.ID) (*platform.Macro, error) { op := getOp(platform.OpFindMacroByID) var macro *platform.Macro err := c.db.View(func(tx *bolt.Tx) error { m, pe := c.findMacroByID(ctx, tx, id) if pe != nil { return &platform.Error{ Op: op, Err: pe, } } macro = m return nil }) if err != nil { return nil, err } return macro, nil }
[ "func", "(", "c", "*", "Client", ")", "FindMacroByID", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "(", "*", "platform", ".", "Macro", ",", "error", ")", "{", "op", ":=", "getOp", "(", "platform", ".", "OpFindMacroByID", ")", "\n", "var", "macro", "*", "platform", ".", "Macro", "\n", "err", ":=", "c", ".", "db", ".", "View", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "m", ",", "pe", ":=", "c", ".", "findMacroByID", "(", "ctx", ",", "tx", ",", "id", ")", "\n", "if", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "pe", ",", "}", "\n", "}", "\n", "macro", "=", "m", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "macro", ",", "nil", "\n", "}" ]
// FindMacroByID finds a single macro in the store by its ID
[ "FindMacroByID", "finds", "a", "single", "macro", "in", "the", "store", "by", "its", "ID" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/macro.go#L54-L73
12,944
influxdata/platform
bolt/macro.go
CreateMacro
func (c *Client) CreateMacro(ctx context.Context, macro *platform.Macro) error { op := getOp(platform.OpCreateMacro) return c.db.Update(func(tx *bolt.Tx) error { macro.ID = c.IDGenerator.ID() if pe := c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) }
go
func (c *Client) CreateMacro(ctx context.Context, macro *platform.Macro) error { op := getOp(platform.OpCreateMacro) return c.db.Update(func(tx *bolt.Tx) error { macro.ID = c.IDGenerator.ID() if pe := c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) }
[ "func", "(", "c", "*", "Client", ")", "CreateMacro", "(", "ctx", "context", ".", "Context", ",", "macro", "*", "platform", ".", "Macro", ")", "error", "{", "op", ":=", "getOp", "(", "platform", ".", "OpCreateMacro", ")", "\n", "return", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "macro", ".", "ID", "=", "c", ".", "IDGenerator", ".", "ID", "(", ")", "\n", "if", "pe", ":=", "c", ".", "putMacro", "(", "ctx", ",", "tx", ",", "macro", ")", ";", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "pe", ",", "}", "\n\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// CreateMacro creates a new macro and assigns it an ID
[ "CreateMacro", "creates", "a", "new", "macro", "and", "assigns", "it", "an", "ID" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/macro.go#L104-L117
12,945
influxdata/platform
bolt/macro.go
ReplaceMacro
func (c *Client) ReplaceMacro(ctx context.Context, macro *platform.Macro) error { op := getOp(platform.OpReplaceMacro) return c.db.Update(func(tx *bolt.Tx) error { if pe := c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) }
go
func (c *Client) ReplaceMacro(ctx context.Context, macro *platform.Macro) error { op := getOp(platform.OpReplaceMacro) return c.db.Update(func(tx *bolt.Tx) error { if pe := c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) }
[ "func", "(", "c", "*", "Client", ")", "ReplaceMacro", "(", "ctx", "context", ".", "Context", ",", "macro", "*", "platform", ".", "Macro", ")", "error", "{", "op", ":=", "getOp", "(", "platform", ".", "OpReplaceMacro", ")", "\n", "return", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "if", "pe", ":=", "c", ".", "putMacro", "(", "ctx", ",", "tx", ",", "macro", ")", ";", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "pe", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// ReplaceMacro puts a macro in the store
[ "ReplaceMacro", "puts", "a", "macro", "in", "the", "store" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/macro.go#L120-L131
12,946
influxdata/platform
bolt/macro.go
UpdateMacro
func (c *Client) UpdateMacro(ctx context.Context, id platform.ID, update *platform.MacroUpdate) (*platform.Macro, error) { op := getOp(platform.OpUpdateMacro) var macro *platform.Macro err := c.db.Update(func(tx *bolt.Tx) error { m, pe := c.findMacroByID(ctx, tx, id) if pe != nil { return &platform.Error{ Op: op, Err: pe, } } if err := update.Apply(m); err != nil { return &platform.Error{ Op: op, Err: err, } } macro = m if pe = c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) return macro, err }
go
func (c *Client) UpdateMacro(ctx context.Context, id platform.ID, update *platform.MacroUpdate) (*platform.Macro, error) { op := getOp(platform.OpUpdateMacro) var macro *platform.Macro err := c.db.Update(func(tx *bolt.Tx) error { m, pe := c.findMacroByID(ctx, tx, id) if pe != nil { return &platform.Error{ Op: op, Err: pe, } } if err := update.Apply(m); err != nil { return &platform.Error{ Op: op, Err: err, } } macro = m if pe = c.putMacro(ctx, tx, macro); pe != nil { return &platform.Error{ Op: op, Err: pe, } } return nil }) return macro, err }
[ "func", "(", "c", "*", "Client", ")", "UpdateMacro", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "update", "*", "platform", ".", "MacroUpdate", ")", "(", "*", "platform", ".", "Macro", ",", "error", ")", "{", "op", ":=", "getOp", "(", "platform", ".", "OpUpdateMacro", ")", "\n", "var", "macro", "*", "platform", ".", "Macro", "\n", "err", ":=", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "m", ",", "pe", ":=", "c", ".", "findMacroByID", "(", "ctx", ",", "tx", ",", "id", ")", "\n", "if", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "pe", ",", "}", "\n", "}", "\n\n", "if", "err", ":=", "update", ".", "Apply", "(", "m", ")", ";", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "macro", "=", "m", "\n", "if", "pe", "=", "c", ".", "putMacro", "(", "ctx", ",", "tx", ",", "macro", ")", ";", "pe", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "pe", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n\n", "return", "macro", ",", "err", "\n", "}" ]
// UpdateMacro updates a single macro in the store with a changeset
[ "UpdateMacro", "updates", "a", "single", "macro", "in", "the", "store", "with", "a", "changeset" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/macro.go#L159-L189
12,947
influxdata/platform
bolt/macro.go
DeleteMacro
func (c *Client) DeleteMacro(ctx context.Context, id platform.ID) error { op := getOp(platform.OpDeleteMacro) return c.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(macroBucket) encID, err := id.Encode() if err != nil { return &platform.Error{ Code: platform.EInvalid, Op: op, Err: err, } } d := b.Get(encID) if d == nil { return &platform.Error{ Code: platform.ENotFound, Op: op, Msg: "macro not found", } } if err := b.Delete(encID); err != nil { return &platform.Error{ Op: op, Err: err, } } return nil }) }
go
func (c *Client) DeleteMacro(ctx context.Context, id platform.ID) error { op := getOp(platform.OpDeleteMacro) return c.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(macroBucket) encID, err := id.Encode() if err != nil { return &platform.Error{ Code: platform.EInvalid, Op: op, Err: err, } } d := b.Get(encID) if d == nil { return &platform.Error{ Code: platform.ENotFound, Op: op, Msg: "macro not found", } } if err := b.Delete(encID); err != nil { return &platform.Error{ Op: op, Err: err, } } return nil }) }
[ "func", "(", "c", "*", "Client", ")", "DeleteMacro", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "error", "{", "op", ":=", "getOp", "(", "platform", ".", "OpDeleteMacro", ")", "\n", "return", "c", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "b", ":=", "tx", ".", "Bucket", "(", "macroBucket", ")", "\n\n", "encID", ",", "err", ":=", "id", ".", "Encode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "EInvalid", ",", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "d", ":=", "b", ".", "Get", "(", "encID", ")", "\n", "if", "d", "==", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Code", ":", "platform", ".", "ENotFound", ",", "Op", ":", "op", ",", "Msg", ":", "\"", "\"", ",", "}", "\n", "}", "\n\n", "if", "err", ":=", "b", ".", "Delete", "(", "encID", ")", ";", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// DeleteMacro removes a single macro from the store by its ID
[ "DeleteMacro", "removes", "a", "single", "macro", "from", "the", "store", "by", "its", "ID" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/macro.go#L192-L224
12,948
influxdata/platform
models/points.go
ParsePoints
func ParsePoints(buf []byte) ([]Point, error) { return ParsePointsWithPrecision(buf, time.Now().UTC(), "n") }
go
func ParsePoints(buf []byte) ([]Point, error) { return ParsePointsWithPrecision(buf, time.Now().UTC(), "n") }
[ "func", "ParsePoints", "(", "buf", "[", "]", "byte", ")", "(", "[", "]", "Point", ",", "error", ")", "{", "return", "ParsePointsWithPrecision", "(", "buf", ",", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ",", "\"", "\"", ")", "\n", "}" ]
// ParsePoints returns a slice of Points from a text representation of a point // with each point separated by newlines. If any points fail to parse, a non-nil error // will be returned in addition to the points that parsed successfully.
[ "ParsePoints", "returns", "a", "slice", "of", "Points", "from", "a", "text", "representation", "of", "a", "point", "with", "each", "point", "separated", "by", "newlines", ".", "If", "any", "points", "fail", "to", "parse", "a", "non", "-", "nil", "error", "will", "be", "returned", "in", "addition", "to", "the", "points", "that", "parsed", "successfully", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/models/points.go#L279-L281
12,949
influxdata/platform
models/points.go
ValidKeyToken
func ValidKeyToken(s string) bool { if !utf8.ValidString(s) { return false } for _, r := range s { if !unicode.IsPrint(r) || r == unicode.ReplacementChar { return false } } return true }
go
func ValidKeyToken(s string) bool { if !utf8.ValidString(s) { return false } for _, r := range s { if !unicode.IsPrint(r) || r == unicode.ReplacementChar { return false } } return true }
[ "func", "ValidKeyToken", "(", "s", "string", ")", "bool", "{", "if", "!", "utf8", ".", "ValidString", "(", "s", ")", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "s", "{", "if", "!", "unicode", ".", "IsPrint", "(", "r", ")", "||", "r", "==", "unicode", ".", "ReplacementChar", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ValidKeyToken returns true if the token used for measurement, tag key, or tag // value is a valid unicode string and only contains printable, non-replacement characters.
[ "ValidKeyToken", "returns", "true", "if", "the", "token", "used", "for", "measurement", "tag", "key", "or", "tag", "value", "is", "a", "valid", "unicode", "string", "and", "only", "contains", "printable", "non", "-", "replacement", "characters", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/models/points.go#L2458-L2468
12,950
influxdata/platform
models/points.go
ValidKeyTokens
func ValidKeyTokens(name string, tags Tags) bool { if !ValidKeyToken(name) { return false } for _, tag := range tags { if !ValidKeyToken(string(tag.Key)) || !ValidKeyToken(string(tag.Value)) { return false } } return true }
go
func ValidKeyTokens(name string, tags Tags) bool { if !ValidKeyToken(name) { return false } for _, tag := range tags { if !ValidKeyToken(string(tag.Key)) || !ValidKeyToken(string(tag.Value)) { return false } } return true }
[ "func", "ValidKeyTokens", "(", "name", "string", ",", "tags", "Tags", ")", "bool", "{", "if", "!", "ValidKeyToken", "(", "name", ")", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "tag", ":=", "range", "tags", "{", "if", "!", "ValidKeyToken", "(", "string", "(", "tag", ".", "Key", ")", ")", "||", "!", "ValidKeyToken", "(", "string", "(", "tag", ".", "Value", ")", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ValidKeyTokens returns true if the measurement name and all tags are valid.
[ "ValidKeyTokens", "returns", "true", "if", "the", "measurement", "name", "and", "all", "tags", "are", "valid", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/models/points.go#L2471-L2481
12,951
influxdata/platform
label.go
Validate
func (l *Label) Validate() error { if !l.ResourceID.Valid() { return &Error{ Code: EInvalid, Msg: "resourceID is required", } } if l.Name == "" { return &Error{ Code: EInvalid, Msg: "label name is required", } } return nil }
go
func (l *Label) Validate() error { if !l.ResourceID.Valid() { return &Error{ Code: EInvalid, Msg: "resourceID is required", } } if l.Name == "" { return &Error{ Code: EInvalid, Msg: "label name is required", } } return nil }
[ "func", "(", "l", "*", "Label", ")", "Validate", "(", ")", "error", "{", "if", "!", "l", ".", "ResourceID", ".", "Valid", "(", ")", "{", "return", "&", "Error", "{", "Code", ":", "EInvalid", ",", "Msg", ":", "\"", "\"", ",", "}", "\n", "}", "\n\n", "if", "l", ".", "Name", "==", "\"", "\"", "{", "return", "&", "Error", "{", "Code", ":", "EInvalid", ",", "Msg", ":", "\"", "\"", ",", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate returns an error if the label is invalid.
[ "Validate", "returns", "an", "error", "if", "the", "label", "is", "invalid", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/label.go#L38-L54
12,952
influxdata/platform
http/auth_service.go
SetAuthorizationStatus
func (s *AuthorizationService) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) error { u, err := newURL(s.Addr, authorizationIDPath(id)) if err != nil { return err } b, err := json.Marshal(setAuthorizationStatusRequest{ Status: status, }) if err != nil { return err } req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(b)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(u.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return err } if err := CheckError(resp, true); err != nil { return err } return nil }
go
func (s *AuthorizationService) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) error { u, err := newURL(s.Addr, authorizationIDPath(id)) if err != nil { return err } b, err := json.Marshal(setAuthorizationStatusRequest{ Status: status, }) if err != nil { return err } req, err := http.NewRequest("PATCH", u.String(), bytes.NewReader(b)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") SetToken(s.Token, req) hc := newClient(u.Scheme, s.InsecureSkipVerify) resp, err := hc.Do(req) if err != nil { return err } if err := CheckError(resp, true); err != nil { return err } return nil }
[ "func", "(", "s", "*", "AuthorizationService", ")", "SetAuthorizationStatus", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "status", "platform", ".", "Status", ")", "error", "{", "u", ",", "err", ":=", "newURL", "(", "s", ".", "Addr", ",", "authorizationIDPath", "(", "id", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "setAuthorizationStatusRequest", "{", "Status", ":", "status", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "bytes", ".", "NewReader", "(", "b", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "SetToken", "(", "s", ".", "Token", ",", "req", ")", "\n\n", "hc", ":=", "newClient", "(", "u", ".", "Scheme", ",", "s", ".", "InsecureSkipVerify", ")", "\n\n", "resp", ",", "err", ":=", "hc", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "CheckError", "(", "resp", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetAuthorizationStatus updates an authorization's status.
[ "SetAuthorizationStatus", "updates", "an", "authorization", "s", "status", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/http/auth_service.go#L695-L728
12,953
influxdata/platform
inmem/macro.go
FindMacroByID
func (s *Service) FindMacroByID(ctx context.Context, id platform.ID) (*platform.Macro, error) { op := OpPrefix + platform.OpFindMacroByID i, ok := s.macroKV.Load(id.String()) if !ok { return nil, &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", } } macro, ok := i.(*platform.Macro) if !ok { return nil, &platform.Error{ Op: op, Msg: fmt.Sprintf("type %T is not a macro", i), } } return macro, nil }
go
func (s *Service) FindMacroByID(ctx context.Context, id platform.ID) (*platform.Macro, error) { op := OpPrefix + platform.OpFindMacroByID i, ok := s.macroKV.Load(id.String()) if !ok { return nil, &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", } } macro, ok := i.(*platform.Macro) if !ok { return nil, &platform.Error{ Op: op, Msg: fmt.Sprintf("type %T is not a macro", i), } } return macro, nil }
[ "func", "(", "s", "*", "Service", ")", "FindMacroByID", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "(", "*", "platform", ".", "Macro", ",", "error", ")", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpFindMacroByID", "\n", "i", ",", "ok", ":=", "s", ".", "macroKV", ".", "Load", "(", "id", ".", "String", "(", ")", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Code", ":", "platform", ".", "ENotFound", ",", "Msg", ":", "\"", "\"", ",", "}", "\n", "}", "\n\n", "macro", ",", "ok", ":=", "i", ".", "(", "*", "platform", ".", "Macro", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Msg", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ")", ",", "}", "\n", "}", "\n\n", "return", "macro", ",", "nil", "\n", "}" ]
// FindMacroByID implements the platform.MacroService interface
[ "FindMacroByID", "implements", "the", "platform", ".", "MacroService", "interface" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L11-L31
12,954
influxdata/platform
inmem/macro.go
FindMacros
func (s *Service) FindMacros(ctx context.Context) ([]*platform.Macro, error) { op := OpPrefix + platform.OpFindMacros var err error var macros []*platform.Macro s.macroKV.Range(func(k, v interface{}) bool { macro, ok := v.(*platform.Macro) if !ok { err = &platform.Error{ Op: op, Msg: fmt.Sprintf("type %T is not a macro", v), } return false } macros = append(macros, macro) return true }) if err != nil { return nil, err } return macros, nil }
go
func (s *Service) FindMacros(ctx context.Context) ([]*platform.Macro, error) { op := OpPrefix + platform.OpFindMacros var err error var macros []*platform.Macro s.macroKV.Range(func(k, v interface{}) bool { macro, ok := v.(*platform.Macro) if !ok { err = &platform.Error{ Op: op, Msg: fmt.Sprintf("type %T is not a macro", v), } return false } macros = append(macros, macro) return true }) if err != nil { return nil, err } return macros, nil }
[ "func", "(", "s", "*", "Service", ")", "FindMacros", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "platform", ".", "Macro", ",", "error", ")", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpFindMacros", "\n", "var", "err", "error", "\n", "var", "macros", "[", "]", "*", "platform", ".", "Macro", "\n", "s", ".", "macroKV", ".", "Range", "(", "func", "(", "k", ",", "v", "interface", "{", "}", ")", "bool", "{", "macro", ",", "ok", ":=", "v", ".", "(", "*", "platform", ".", "Macro", ")", "\n", "if", "!", "ok", "{", "err", "=", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Msg", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", ",", "}", "\n", "return", "false", "\n", "}", "\n\n", "macros", "=", "append", "(", "macros", ",", "macro", ")", "\n", "return", "true", "\n", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "macros", ",", "nil", "\n", "}" ]
// FindMacros implements the platform.MacroService interface
[ "FindMacros", "implements", "the", "platform", ".", "MacroService", "interface" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L34-L57
12,955
influxdata/platform
inmem/macro.go
CreateMacro
func (s *Service) CreateMacro(ctx context.Context, m *platform.Macro) error { op := OpPrefix + platform.OpCreateMacro m.ID = s.IDGenerator.ID() err := s.ReplaceMacro(ctx, m) if err != nil { return &platform.Error{ Op: op, Err: err, } } return nil }
go
func (s *Service) CreateMacro(ctx context.Context, m *platform.Macro) error { op := OpPrefix + platform.OpCreateMacro m.ID = s.IDGenerator.ID() err := s.ReplaceMacro(ctx, m) if err != nil { return &platform.Error{ Op: op, Err: err, } } return nil }
[ "func", "(", "s", "*", "Service", ")", "CreateMacro", "(", "ctx", "context", ".", "Context", ",", "m", "*", "platform", ".", "Macro", ")", "error", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpCreateMacro", "\n", "m", ".", "ID", "=", "s", ".", "IDGenerator", ".", "ID", "(", ")", "\n", "err", ":=", "s", ".", "ReplaceMacro", "(", "ctx", ",", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CreateMacro implements the platform.MacroService interface
[ "CreateMacro", "implements", "the", "platform", ".", "MacroService", "interface" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L60-L71
12,956
influxdata/platform
inmem/macro.go
UpdateMacro
func (s *Service) UpdateMacro(ctx context.Context, id platform.ID, update *platform.MacroUpdate) (*platform.Macro, error) { op := OpPrefix + platform.OpUpdateMacro macro, err := s.FindMacroByID(ctx, id) if err != nil { return nil, &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", Err: err, } } if err := update.Apply(macro); err != nil { return nil, &platform.Error{ Op: op, Err: err, } } if err := s.ReplaceMacro(ctx, macro); err != nil { return nil, &platform.Error{ Op: op, Err: err, } } return macro, nil }
go
func (s *Service) UpdateMacro(ctx context.Context, id platform.ID, update *platform.MacroUpdate) (*platform.Macro, error) { op := OpPrefix + platform.OpUpdateMacro macro, err := s.FindMacroByID(ctx, id) if err != nil { return nil, &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", Err: err, } } if err := update.Apply(macro); err != nil { return nil, &platform.Error{ Op: op, Err: err, } } if err := s.ReplaceMacro(ctx, macro); err != nil { return nil, &platform.Error{ Op: op, Err: err, } } return macro, nil }
[ "func", "(", "s", "*", "Service", ")", "UpdateMacro", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "update", "*", "platform", ".", "MacroUpdate", ")", "(", "*", "platform", ".", "Macro", ",", "error", ")", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpUpdateMacro", "\n", "macro", ",", "err", ":=", "s", ".", "FindMacroByID", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Code", ":", "platform", ".", "ENotFound", ",", "Msg", ":", "\"", "\"", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "if", "err", ":=", "update", ".", "Apply", "(", "macro", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "ReplaceMacro", "(", "ctx", ",", "macro", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "return", "macro", ",", "nil", "\n", "}" ]
// UpdateMacro implements the platform.MacroService interface
[ "UpdateMacro", "implements", "the", "platform", ".", "MacroService", "interface" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L74-L101
12,957
influxdata/platform
inmem/macro.go
DeleteMacro
func (s *Service) DeleteMacro(ctx context.Context, id platform.ID) error { op := OpPrefix + platform.OpDeleteMacro _, err := s.FindMacroByID(ctx, id) if err != nil { return &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", Err: err, } } s.macroKV.Delete(id.String()) return nil }
go
func (s *Service) DeleteMacro(ctx context.Context, id platform.ID) error { op := OpPrefix + platform.OpDeleteMacro _, err := s.FindMacroByID(ctx, id) if err != nil { return &platform.Error{ Op: op, Code: platform.ENotFound, Msg: "macro not found", Err: err, } } s.macroKV.Delete(id.String()) return nil }
[ "func", "(", "s", "*", "Service", ")", "DeleteMacro", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "error", "{", "op", ":=", "OpPrefix", "+", "platform", ".", "OpDeleteMacro", "\n", "_", ",", "err", ":=", "s", ".", "FindMacroByID", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Op", ":", "op", ",", "Code", ":", "platform", ".", "ENotFound", ",", "Msg", ":", "\"", "\"", ",", "Err", ":", "err", ",", "}", "\n", "}", "\n\n", "s", ".", "macroKV", ".", "Delete", "(", "id", ".", "String", "(", ")", ")", "\n\n", "return", "nil", "\n", "}" ]
// DeleteMacro implements the platform.MacroService interface
[ "DeleteMacro", "implements", "the", "platform", ".", "MacroService", "interface" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L104-L119
12,958
influxdata/platform
inmem/macro.go
ReplaceMacro
func (s *Service) ReplaceMacro(ctx context.Context, m *platform.Macro) error { s.macroKV.Store(m.ID.String(), m) return nil }
go
func (s *Service) ReplaceMacro(ctx context.Context, m *platform.Macro) error { s.macroKV.Store(m.ID.String(), m) return nil }
[ "func", "(", "s", "*", "Service", ")", "ReplaceMacro", "(", "ctx", "context", ".", "Context", ",", "m", "*", "platform", ".", "Macro", ")", "error", "{", "s", ".", "macroKV", ".", "Store", "(", "m", ".", "ID", ".", "String", "(", ")", ",", "m", ")", "\n", "return", "nil", "\n", "}" ]
// ReplaceMacro stores a Macro in the key value store
[ "ReplaceMacro", "stores", "a", "Macro", "in", "the", "key", "value", "store" ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/macro.go#L122-L125
12,959
influxdata/platform
task/backend/meta.go
NewStoreTaskMeta
func NewStoreTaskMeta(req CreateTaskRequest, o options.Options) StoreTaskMeta { stm := StoreTaskMeta{ MaxConcurrency: int32(o.Concurrency), Status: string(req.Status), LatestCompleted: req.ScheduleAfter, EffectiveCron: o.EffectiveCronString(), Offset: int32(o.Offset / time.Second), } if stm.Status == "" { stm.Status = string(DefaultTaskStatus) } if o.Every != 0 { t := time.Unix(stm.LatestCompleted, 0).Truncate(o.Every).Unix() if t == stm.LatestCompleted { // For example, every 1m truncates to exactly on the minute. // But the input request is schedule after, not "on or after". // Add one interval. t += int64(o.Every / time.Second) } stm.LatestCompleted = t } return stm }
go
func NewStoreTaskMeta(req CreateTaskRequest, o options.Options) StoreTaskMeta { stm := StoreTaskMeta{ MaxConcurrency: int32(o.Concurrency), Status: string(req.Status), LatestCompleted: req.ScheduleAfter, EffectiveCron: o.EffectiveCronString(), Offset: int32(o.Offset / time.Second), } if stm.Status == "" { stm.Status = string(DefaultTaskStatus) } if o.Every != 0 { t := time.Unix(stm.LatestCompleted, 0).Truncate(o.Every).Unix() if t == stm.LatestCompleted { // For example, every 1m truncates to exactly on the minute. // But the input request is schedule after, not "on or after". // Add one interval. t += int64(o.Every / time.Second) } stm.LatestCompleted = t } return stm }
[ "func", "NewStoreTaskMeta", "(", "req", "CreateTaskRequest", ",", "o", "options", ".", "Options", ")", "StoreTaskMeta", "{", "stm", ":=", "StoreTaskMeta", "{", "MaxConcurrency", ":", "int32", "(", "o", ".", "Concurrency", ")", ",", "Status", ":", "string", "(", "req", ".", "Status", ")", ",", "LatestCompleted", ":", "req", ".", "ScheduleAfter", ",", "EffectiveCron", ":", "o", ".", "EffectiveCronString", "(", ")", ",", "Offset", ":", "int32", "(", "o", ".", "Offset", "/", "time", ".", "Second", ")", ",", "}", "\n\n", "if", "stm", ".", "Status", "==", "\"", "\"", "{", "stm", ".", "Status", "=", "string", "(", "DefaultTaskStatus", ")", "\n", "}", "\n\n", "if", "o", ".", "Every", "!=", "0", "{", "t", ":=", "time", ".", "Unix", "(", "stm", ".", "LatestCompleted", ",", "0", ")", ".", "Truncate", "(", "o", ".", "Every", ")", ".", "Unix", "(", ")", "\n", "if", "t", "==", "stm", ".", "LatestCompleted", "{", "// For example, every 1m truncates to exactly on the minute.", "// But the input request is schedule after, not \"on or after\".", "// Add one interval.", "t", "+=", "int64", "(", "o", ".", "Every", "/", "time", ".", "Second", ")", "\n", "}", "\n", "stm", ".", "LatestCompleted", "=", "t", "\n", "}", "\n\n", "return", "stm", "\n", "}" ]
// This file contains helper methods for the StoreTaskMeta type defined in protobuf. // NewStoreTaskMeta returns a new StoreTaskMeta based on the given request and parsed options.
[ "This", "file", "contains", "helper", "methods", "for", "the", "StoreTaskMeta", "type", "defined", "in", "protobuf", ".", "NewStoreTaskMeta", "returns", "a", "new", "StoreTaskMeta", "based", "on", "the", "given", "request", "and", "parsed", "options", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/task/backend/meta.go#L16-L41
12,960
influxdata/platform
inmem/view.go
FindViews
func (s *Service) FindViews(ctx context.Context, filter platform.ViewFilter) ([]*platform.View, int, error) { var ds []*platform.View if filter.ID != nil { d, err := s.FindViewByID(ctx, *filter.ID) if err != nil && platform.ErrorCode(err) != platform.ENotFound { return nil, 0, &platform.Error{ Err: err, Op: OpPrefix + platform.OpFindViews, } } if d != nil { ds = append(ds, d) } return ds, len(ds), nil } var err error filterF := filterViewFn(filter) s.viewKV.Range(func(k, v interface{}) bool { d, ok := v.(*platform.View) if !ok { return false } if filterF(d) { ds = append(ds, d) } return true }) return ds, len(ds), err }
go
func (s *Service) FindViews(ctx context.Context, filter platform.ViewFilter) ([]*platform.View, int, error) { var ds []*platform.View if filter.ID != nil { d, err := s.FindViewByID(ctx, *filter.ID) if err != nil && platform.ErrorCode(err) != platform.ENotFound { return nil, 0, &platform.Error{ Err: err, Op: OpPrefix + platform.OpFindViews, } } if d != nil { ds = append(ds, d) } return ds, len(ds), nil } var err error filterF := filterViewFn(filter) s.viewKV.Range(func(k, v interface{}) bool { d, ok := v.(*platform.View) if !ok { return false } if filterF(d) { ds = append(ds, d) } return true }) return ds, len(ds), err }
[ "func", "(", "s", "*", "Service", ")", "FindViews", "(", "ctx", "context", ".", "Context", ",", "filter", "platform", ".", "ViewFilter", ")", "(", "[", "]", "*", "platform", ".", "View", ",", "int", ",", "error", ")", "{", "var", "ds", "[", "]", "*", "platform", ".", "View", "\n", "if", "filter", ".", "ID", "!=", "nil", "{", "d", ",", "err", ":=", "s", ".", "FindViewByID", "(", "ctx", ",", "*", "filter", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "&&", "platform", ".", "ErrorCode", "(", "err", ")", "!=", "platform", ".", "ENotFound", "{", "return", "nil", ",", "0", ",", "&", "platform", ".", "Error", "{", "Err", ":", "err", ",", "Op", ":", "OpPrefix", "+", "platform", ".", "OpFindViews", ",", "}", "\n", "}", "\n", "if", "d", "!=", "nil", "{", "ds", "=", "append", "(", "ds", ",", "d", ")", "\n", "}", "\n\n", "return", "ds", ",", "len", "(", "ds", ")", ",", "nil", "\n", "}", "\n\n", "var", "err", "error", "\n", "filterF", ":=", "filterViewFn", "(", "filter", ")", "\n", "s", ".", "viewKV", ".", "Range", "(", "func", "(", "k", ",", "v", "interface", "{", "}", ")", "bool", "{", "d", ",", "ok", ":=", "v", ".", "(", "*", "platform", ".", "View", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "if", "filterF", "(", "d", ")", "{", "ds", "=", "append", "(", "ds", ",", "d", ")", "\n", "}", "\n", "return", "true", "\n", "}", ")", "\n", "return", "ds", ",", "len", "(", "ds", ")", ",", "err", "\n", "}" ]
// FindViews implements platform.ViewService interface.
[ "FindViews", "implements", "platform", ".", "ViewService", "interface", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/view.go#L52-L83
12,961
influxdata/platform
inmem/view.go
CreateView
func (s *Service) CreateView(ctx context.Context, c *platform.View) error { c.ID = s.IDGenerator.ID() if err := s.PutView(ctx, c); err != nil { return &platform.Error{ Err: err, Op: OpPrefix + platform.OpCreateView, } } return nil }
go
func (s *Service) CreateView(ctx context.Context, c *platform.View) error { c.ID = s.IDGenerator.ID() if err := s.PutView(ctx, c); err != nil { return &platform.Error{ Err: err, Op: OpPrefix + platform.OpCreateView, } } return nil }
[ "func", "(", "s", "*", "Service", ")", "CreateView", "(", "ctx", "context", ".", "Context", ",", "c", "*", "platform", ".", "View", ")", "error", "{", "c", ".", "ID", "=", "s", ".", "IDGenerator", ".", "ID", "(", ")", "\n", "if", "err", ":=", "s", ".", "PutView", "(", "ctx", ",", "c", ")", ";", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Err", ":", "err", ",", "Op", ":", "OpPrefix", "+", "platform", ".", "OpCreateView", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CreateView implements platform.ViewService interface.
[ "CreateView", "implements", "platform", ".", "ViewService", "interface", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/view.go#L86-L95
12,962
influxdata/platform
inmem/view.go
UpdateView
func (s *Service) UpdateView(ctx context.Context, id platform.ID, upd platform.ViewUpdate) (*platform.View, error) { c, err := s.FindViewByID(ctx, id) if err != nil { return nil, &platform.Error{ Err: err, Op: OpPrefix + platform.OpUpdateView, } } if upd.Name != nil { c.Name = *upd.Name } if upd.Properties != nil { c.Properties = upd.Properties } s.viewKV.Store(c.ID.String(), c) return c, nil }
go
func (s *Service) UpdateView(ctx context.Context, id platform.ID, upd platform.ViewUpdate) (*platform.View, error) { c, err := s.FindViewByID(ctx, id) if err != nil { return nil, &platform.Error{ Err: err, Op: OpPrefix + platform.OpUpdateView, } } if upd.Name != nil { c.Name = *upd.Name } if upd.Properties != nil { c.Properties = upd.Properties } s.viewKV.Store(c.ID.String(), c) return c, nil }
[ "func", "(", "s", "*", "Service", ")", "UpdateView", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "upd", "platform", ".", "ViewUpdate", ")", "(", "*", "platform", ".", "View", ",", "error", ")", "{", "c", ",", "err", ":=", "s", ".", "FindViewByID", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "&", "platform", ".", "Error", "{", "Err", ":", "err", ",", "Op", ":", "OpPrefix", "+", "platform", ".", "OpUpdateView", ",", "}", "\n", "}", "\n\n", "if", "upd", ".", "Name", "!=", "nil", "{", "c", ".", "Name", "=", "*", "upd", ".", "Name", "\n", "}", "\n\n", "if", "upd", ".", "Properties", "!=", "nil", "{", "c", ".", "Properties", "=", "upd", ".", "Properties", "\n", "}", "\n\n", "s", ".", "viewKV", ".", "Store", "(", "c", ".", "ID", ".", "String", "(", ")", ",", "c", ")", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// UpdateView implements platform.ViewService interface.
[ "UpdateView", "implements", "platform", ".", "ViewService", "interface", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/view.go#L107-L127
12,963
influxdata/platform
inmem/view.go
DeleteView
func (s *Service) DeleteView(ctx context.Context, id platform.ID) error { if _, err := s.FindViewByID(ctx, id); err != nil { return &platform.Error{ Err: err, Op: OpPrefix + platform.OpDeleteView, } } s.viewKV.Delete(id.String()) return nil }
go
func (s *Service) DeleteView(ctx context.Context, id platform.ID) error { if _, err := s.FindViewByID(ctx, id); err != nil { return &platform.Error{ Err: err, Op: OpPrefix + platform.OpDeleteView, } } s.viewKV.Delete(id.String()) return nil }
[ "func", "(", "s", "*", "Service", ")", "DeleteView", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "error", "{", "if", "_", ",", "err", ":=", "s", ".", "FindViewByID", "(", "ctx", ",", "id", ")", ";", "err", "!=", "nil", "{", "return", "&", "platform", ".", "Error", "{", "Err", ":", "err", ",", "Op", ":", "OpPrefix", "+", "platform", ".", "OpDeleteView", ",", "}", "\n", "}", "\n", "s", ".", "viewKV", ".", "Delete", "(", "id", ".", "String", "(", ")", ")", "\n", "return", "nil", "\n", "}" ]
// DeleteView implements platform.ViewService interface.
[ "DeleteView", "implements", "platform", ".", "ViewService", "interface", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/inmem/view.go#L130-L139
12,964
influxdata/platform
bolt/kv.go
Open
func (s *KVStore) Open(ctx context.Context) error { // Ensure the required directory structure exists. if err := os.MkdirAll(filepath.Dir(s.path), 0700); err != nil { return fmt.Errorf("unable to create directory %s: %v", s.path, err) } if _, err := os.Stat(s.path); err != nil && !os.IsNotExist(err) { return err } // Open database file. db, err := bolt.Open(s.path, 0600, &bolt.Options{Timeout: 1 * time.Second}) if err != nil { return fmt.Errorf("unable to open boltdb file %v", err) } s.db = db s.logger.Info("Resources opened", zap.String("path", s.path)) return nil }
go
func (s *KVStore) Open(ctx context.Context) error { // Ensure the required directory structure exists. if err := os.MkdirAll(filepath.Dir(s.path), 0700); err != nil { return fmt.Errorf("unable to create directory %s: %v", s.path, err) } if _, err := os.Stat(s.path); err != nil && !os.IsNotExist(err) { return err } // Open database file. db, err := bolt.Open(s.path, 0600, &bolt.Options{Timeout: 1 * time.Second}) if err != nil { return fmt.Errorf("unable to open boltdb file %v", err) } s.db = db s.logger.Info("Resources opened", zap.String("path", s.path)) return nil }
[ "func", "(", "s", "*", "KVStore", ")", "Open", "(", "ctx", "context", ".", "Context", ")", "error", "{", "// Ensure the required directory structure exists.", "if", "err", ":=", "os", ".", "MkdirAll", "(", "filepath", ".", "Dir", "(", "s", ".", "path", ")", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "path", ",", "err", ")", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "s", ".", "path", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "err", "\n", "}", "\n\n", "// Open database file.", "db", ",", "err", ":=", "bolt", ".", "Open", "(", "s", ".", "path", ",", "0600", ",", "&", "bolt", ".", "Options", "{", "Timeout", ":", "1", "*", "time", ".", "Second", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "s", ".", "db", "=", "db", "\n\n", "s", ".", "logger", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "s", ".", "path", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Open creates boltDB file it doesn't exists and opens it otherwise.
[ "Open", "creates", "boltDB", "file", "it", "doesn", "t", "exists", "and", "opens", "it", "otherwise", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/kv.go#L32-L51
12,965
influxdata/platform
bolt/kv.go
Seek
func (c *Cursor) Seek(prefix []byte) ([]byte, []byte) { k, v := c.cursor.Seek(prefix) if len(v) == 0 { return nil, nil } return k, v }
go
func (c *Cursor) Seek(prefix []byte) ([]byte, []byte) { k, v := c.cursor.Seek(prefix) if len(v) == 0 { return nil, nil } return k, v }
[ "func", "(", "c", "*", "Cursor", ")", "Seek", "(", "prefix", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ")", "{", "k", ",", "v", ":=", "c", ".", "cursor", ".", "Seek", "(", "prefix", ")", "\n", "if", "len", "(", "v", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "k", ",", "v", "\n", "}" ]
// Seek seeks for the first key that matches the prefix provided.
[ "Seek", "seeks", "for", "the", "first", "key", "that", "matches", "the", "prefix", "provided", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/bolt/kv.go#L177-L183
12,966
influxdata/platform
mock/proxy_query_service.go
NewProxyQueryService
func NewProxyQueryService() *ProxyQueryService { return &ProxyQueryService{ QueryFn: func(context.Context, io.Writer, *query.ProxyRequest) (int64, error) { return 0, nil }, } }
go
func NewProxyQueryService() *ProxyQueryService { return &ProxyQueryService{ QueryFn: func(context.Context, io.Writer, *query.ProxyRequest) (int64, error) { return 0, nil }, } }
[ "func", "NewProxyQueryService", "(", ")", "*", "ProxyQueryService", "{", "return", "&", "ProxyQueryService", "{", "QueryFn", ":", "func", "(", "context", ".", "Context", ",", "io", ".", "Writer", ",", "*", "query", ".", "ProxyRequest", ")", "(", "int64", ",", "error", ")", "{", "return", "0", ",", "nil", "}", ",", "}", "\n", "}" ]
// NewProxyQueryService returns a mock of ProxyQueryService where its methods will return zero values.
[ "NewProxyQueryService", "returns", "a", "mock", "of", "ProxyQueryService", "where", "its", "methods", "will", "return", "zero", "values", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/mock/proxy_query_service.go#L18-L22
12,967
influxdata/platform
mock/proxy_query_service.go
Query
func (s *ProxyQueryService) Query(ctx context.Context, w io.Writer, req *query.ProxyRequest) (int64, error) { return s.QueryFn(ctx, w, req) }
go
func (s *ProxyQueryService) Query(ctx context.Context, w io.Writer, req *query.ProxyRequest) (int64, error) { return s.QueryFn(ctx, w, req) }
[ "func", "(", "s", "*", "ProxyQueryService", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "w", "io", ".", "Writer", ",", "req", "*", "query", ".", "ProxyRequest", ")", "(", "int64", ",", "error", ")", "{", "return", "s", ".", "QueryFn", "(", "ctx", ",", "w", ",", "req", ")", "\n", "}" ]
// Query performs the requested query and encodes the results into w.
[ "Query", "performs", "the", "requested", "query", "and", "encodes", "the", "results", "into", "w", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/mock/proxy_query_service.go#L25-L27
12,968
influxdata/platform
tsdb/index.go
NewSeriesIteratorAdapter
func NewSeriesIteratorAdapter(sfile *SeriesFile, itr SeriesIDIterator) SeriesIterator { return &seriesIteratorAdapter{ sfile: sfile, itr: itr, } }
go
func NewSeriesIteratorAdapter(sfile *SeriesFile, itr SeriesIDIterator) SeriesIterator { return &seriesIteratorAdapter{ sfile: sfile, itr: itr, } }
[ "func", "NewSeriesIteratorAdapter", "(", "sfile", "*", "SeriesFile", ",", "itr", "SeriesIDIterator", ")", "SeriesIterator", "{", "return", "&", "seriesIteratorAdapter", "{", "sfile", ":", "sfile", ",", "itr", ":", "itr", ",", "}", "\n", "}" ]
// NewSeriesIteratorAdapter returns an adapter for converting series ids to series.
[ "NewSeriesIteratorAdapter", "returns", "an", "adapter", "for", "converting", "series", "ids", "to", "series", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/index.go#L30-L35
12,969
influxdata/platform
tsdb/index.go
NewSeriesQueryAdapterIterator
func NewSeriesQueryAdapterIterator(sfile *SeriesFile, itr SeriesIDIterator, opt query.IteratorOptions) query.Iterator { return &seriesQueryAdapterIterator{ sfile: sfile, itr: itr, point: query.FloatPoint{ Aux: make([]interface{}, len(opt.Aux)), }, opt: opt, } }
go
func NewSeriesQueryAdapterIterator(sfile *SeriesFile, itr SeriesIDIterator, opt query.IteratorOptions) query.Iterator { return &seriesQueryAdapterIterator{ sfile: sfile, itr: itr, point: query.FloatPoint{ Aux: make([]interface{}, len(opt.Aux)), }, opt: opt, } }
[ "func", "NewSeriesQueryAdapterIterator", "(", "sfile", "*", "SeriesFile", ",", "itr", "SeriesIDIterator", ",", "opt", "query", ".", "IteratorOptions", ")", "query", ".", "Iterator", "{", "return", "&", "seriesQueryAdapterIterator", "{", "sfile", ":", "sfile", ",", "itr", ":", "itr", ",", "point", ":", "query", ".", "FloatPoint", "{", "Aux", ":", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "opt", ".", "Aux", ")", ")", ",", "}", ",", "opt", ":", "opt", ",", "}", "\n", "}" ]
// NewSeriesQueryAdapterIterator returns a new instance of SeriesQueryAdapterIterator.
[ "NewSeriesQueryAdapterIterator", "returns", "a", "new", "instance", "of", "SeriesQueryAdapterIterator", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/tsdb/index.go#L221-L230
12,970
influxdata/platform
task/backend/store.go
CreateArgs
func (StoreValidation) CreateArgs(req CreateTaskRequest) (options.Options, error) { var missing []string var o options.Options if req.Script == "" { missing = append(missing, "script") } else { var err error o, err = options.FromScript(req.Script) if err != nil { return o, err } } if !req.Org.Valid() { missing = append(missing, "organization ID") } if !req.User.Valid() { missing = append(missing, "user ID") } if len(missing) > 0 { return o, fmt.Errorf("missing required fields to create task: %s", strings.Join(missing, ", ")) } if err := req.Status.validate(true); err != nil { return o, err } return o, nil }
go
func (StoreValidation) CreateArgs(req CreateTaskRequest) (options.Options, error) { var missing []string var o options.Options if req.Script == "" { missing = append(missing, "script") } else { var err error o, err = options.FromScript(req.Script) if err != nil { return o, err } } if !req.Org.Valid() { missing = append(missing, "organization ID") } if !req.User.Valid() { missing = append(missing, "user ID") } if len(missing) > 0 { return o, fmt.Errorf("missing required fields to create task: %s", strings.Join(missing, ", ")) } if err := req.Status.validate(true); err != nil { return o, err } return o, nil }
[ "func", "(", "StoreValidation", ")", "CreateArgs", "(", "req", "CreateTaskRequest", ")", "(", "options", ".", "Options", ",", "error", ")", "{", "var", "missing", "[", "]", "string", "\n", "var", "o", "options", ".", "Options", "\n\n", "if", "req", ".", "Script", "==", "\"", "\"", "{", "missing", "=", "append", "(", "missing", ",", "\"", "\"", ")", "\n", "}", "else", "{", "var", "err", "error", "\n", "o", ",", "err", "=", "options", ".", "FromScript", "(", "req", ".", "Script", ")", "\n", "if", "err", "!=", "nil", "{", "return", "o", ",", "err", "\n", "}", "\n", "}", "\n\n", "if", "!", "req", ".", "Org", ".", "Valid", "(", ")", "{", "missing", "=", "append", "(", "missing", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "!", "req", ".", "User", ".", "Valid", "(", ")", "{", "missing", "=", "append", "(", "missing", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "missing", ")", ">", "0", "{", "return", "o", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "missing", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "err", ":=", "req", ".", "Status", ".", "validate", "(", "true", ")", ";", "err", "!=", "nil", "{", "return", "o", ",", "err", "\n", "}", "\n\n", "return", "o", ",", "nil", "\n", "}" ]
// CreateArgs returns the script's parsed options, // and an error if any of the provided fields are invalid for creating a task.
[ "CreateArgs", "returns", "the", "script", "s", "parsed", "options", "and", "an", "error", "if", "any", "of", "the", "provided", "fields", "are", "invalid", "for", "creating", "a", "task", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/task/backend/store.go#L352-L382
12,971
influxdata/platform
gather/handler.go
Process
func (h *handler) Process(s nats.Subscription, m nats.Message) { defer m.Ack() req := new(platform.ScraperTarget) err := json.Unmarshal(m.Data(), req) if err != nil { h.Logger.Error("unable to unmarshal json", zap.Error(err)) return } ms, err := h.Scraper.Gather(context.TODO(), *req) if err != nil { h.Logger.Error("unable to gather", zap.Error(err)) return } // send metrics to storage queue buf := new(bytes.Buffer) if err := json.NewEncoder(buf).Encode(ms); err != nil { h.Logger.Error("unable to marshal json", zap.Error(err)) return } if err := h.Publisher.Publish(MetricsSubject, buf); err != nil { h.Logger.Error("unable to publish scraper metrics", zap.Error(err)) return } }
go
func (h *handler) Process(s nats.Subscription, m nats.Message) { defer m.Ack() req := new(platform.ScraperTarget) err := json.Unmarshal(m.Data(), req) if err != nil { h.Logger.Error("unable to unmarshal json", zap.Error(err)) return } ms, err := h.Scraper.Gather(context.TODO(), *req) if err != nil { h.Logger.Error("unable to gather", zap.Error(err)) return } // send metrics to storage queue buf := new(bytes.Buffer) if err := json.NewEncoder(buf).Encode(ms); err != nil { h.Logger.Error("unable to marshal json", zap.Error(err)) return } if err := h.Publisher.Publish(MetricsSubject, buf); err != nil { h.Logger.Error("unable to publish scraper metrics", zap.Error(err)) return } }
[ "func", "(", "h", "*", "handler", ")", "Process", "(", "s", "nats", ".", "Subscription", ",", "m", "nats", ".", "Message", ")", "{", "defer", "m", ".", "Ack", "(", ")", "\n\n", "req", ":=", "new", "(", "platform", ".", "ScraperTarget", ")", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "m", ".", "Data", "(", ")", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "ms", ",", "err", ":=", "h", ".", "Scraper", ".", "Gather", "(", "context", ".", "TODO", "(", ")", ",", "*", "req", ")", "\n", "if", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "// send metrics to storage queue", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "json", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "ms", ")", ";", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", ":=", "h", ".", "Publisher", ".", "Publish", "(", "MetricsSubject", ",", "buf", ")", ";", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Error", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "}" ]
// Process consumes scraper target from scraper target queue, // call the scraper to gather, and publish to metrics queue.
[ "Process", "consumes", "scraper", "target", "from", "scraper", "target", "queue", "call", "the", "scraper", "to", "gather", "and", "publish", "to", "metrics", "queue", "." ]
d500d3cf55899337bc03259b46c58bae9c06f1eb
https://github.com/influxdata/platform/blob/d500d3cf55899337bc03259b46c58bae9c06f1eb/gather/handler.go#L22-L50
12,972
0xrawsec/golang-utils
net/sftp/sftp.go
PrivateKeyAuthMethod
func PrivateKeyAuthMethod(privateKeyPath string) ssh.AuthMethod { sss, err := loadPrivateKey(privateKeyPath) if err != nil { panic(err) } return ssh.PublicKeys(sss) }
go
func PrivateKeyAuthMethod(privateKeyPath string) ssh.AuthMethod { sss, err := loadPrivateKey(privateKeyPath) if err != nil { panic(err) } return ssh.PublicKeys(sss) }
[ "func", "PrivateKeyAuthMethod", "(", "privateKeyPath", "string", ")", "ssh", ".", "AuthMethod", "{", "sss", ",", "err", ":=", "loadPrivateKey", "(", "privateKeyPath", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "ssh", ".", "PublicKeys", "(", "sss", ")", "\n\n", "}" ]
// PrivateKeyAuthMethod returns a ssh.AuthMethod initialized with a private key // @privateKeyPath: path to the private key to use
[ "PrivateKeyAuthMethod", "returns", "a", "ssh", ".", "AuthMethod", "initialized", "with", "a", "private", "key" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/net/sftp/sftp.go#L45-L52
12,973
0xrawsec/golang-utils
net/sftp/sftp.go
New
func New(host, port, username string, sams ...ssh.AuthMethod) (*Client, error) { config := &ssh.ClientConfig{ User: username, Auth: sams, } client, err := ssh.Dial("tcp", BuildSSHURL(host, port), config) if err != nil { return nil, err } tmpSftpClient, err := sftp.NewClient(client) if err != nil { return nil, err } return (*Client)(unsafe.Pointer(tmpSftpClient)), err }
go
func New(host, port, username string, sams ...ssh.AuthMethod) (*Client, error) { config := &ssh.ClientConfig{ User: username, Auth: sams, } client, err := ssh.Dial("tcp", BuildSSHURL(host, port), config) if err != nil { return nil, err } tmpSftpClient, err := sftp.NewClient(client) if err != nil { return nil, err } return (*Client)(unsafe.Pointer(tmpSftpClient)), err }
[ "func", "New", "(", "host", ",", "port", ",", "username", "string", ",", "sams", "...", "ssh", ".", "AuthMethod", ")", "(", "*", "Client", ",", "error", ")", "{", "config", ":=", "&", "ssh", ".", "ClientConfig", "{", "User", ":", "username", ",", "Auth", ":", "sams", ",", "}", "\n", "client", ",", "err", ":=", "ssh", ".", "Dial", "(", "\"", "\"", ",", "BuildSSHURL", "(", "host", ",", "port", ")", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "tmpSftpClient", ",", "err", ":=", "sftp", ".", "NewClient", "(", "client", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "(", "*", "Client", ")", "(", "unsafe", ".", "Pointer", "(", "tmpSftpClient", ")", ")", ",", "err", "\n", "}" ]
// New returns a new SFTP Client // @host: hostname to connect to // @port: port on the hostname // @username: username to login // @sams: list of ssh.AuthMethod to use
[ "New", "returns", "a", "new", "SFTP", "Client" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/net/sftp/sftp.go#L59-L73
12,974
0xrawsec/golang-utils
net/sftp/sftp.go
ResolveSymlink
func (sc *Client) ResolveSymlink(path string) string { pointer, err := sc.ReadLink(path) if err != nil { return path } return pointer }
go
func (sc *Client) ResolveSymlink(path string) string { pointer, err := sc.ReadLink(path) if err != nil { return path } return pointer }
[ "func", "(", "sc", "*", "Client", ")", "ResolveSymlink", "(", "path", "string", ")", "string", "{", "pointer", ",", "err", ":=", "sc", ".", "ReadLink", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "path", "\n", "}", "\n", "return", "pointer", "\n", "}" ]
// ResolveSymlink resolve a path and returns the path of the file pointed if // it is a symlink // @path: path to resolve
[ "ResolveSymlink", "resolve", "a", "path", "and", "returns", "the", "path", "of", "the", "file", "pointed", "if", "it", "is", "a", "symlink" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/net/sftp/sftp.go#L78-L84
12,975
0xrawsec/golang-utils
net/sftp/sftp.go
Walk
func (sc *Client) Walk(root string) <-chan fswalker.WalkItem { iterChannel := make(chan fswalker.WalkItem) dirsToProcess := []string{root} go func() { for len(dirsToProcess) > 0 { dirs, files := []os.FileInfo{}, []os.FileInfo{} dirpath := dirsToProcess[len(dirsToProcess)-1] dirsToProcess = dirsToProcess[:len(dirsToProcess)-1] filesInfo, err := sc.ReadDir(sc.ResolveSymlink(dirpath)) if err != nil { fmt.Printf("Error reading directory (%s): %s\n", err.Error(), dirpath) } else { for _, fileInfo := range filesInfo { switch { case fileInfo.Mode().IsDir(): dirs = append(dirs, fileInfo) dirsToProcess = append(dirsToProcess, filepath.Join(dirpath, fileInfo.Name())) case fileInfo.Mode().IsRegular(): files = append(files, fileInfo) case fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink: sympath := filepath.Join(dirpath, fileInfo.Name()) pointerFI, err := sc.Stat(sympath) if err != nil { fmt.Fprintf(os.Stderr, "Error reading symlink (%s): %s\n", err.Error(), sympath) } else { switch { case pointerFI.Mode().IsDir(): dirs = append(dirs, fileInfo) dirsToProcess = append(dirsToProcess, sc.Join(dirpath, fileInfo.Name())) case pointerFI.Mode().IsRegular(): files = append(files, fileInfo) } } } } } iterChannel <- fswalker.WalkItem{Dirpath: dirpath, Dirs: dirs, Files: files, Err: err} } close(iterChannel) }() return iterChannel }
go
func (sc *Client) Walk(root string) <-chan fswalker.WalkItem { iterChannel := make(chan fswalker.WalkItem) dirsToProcess := []string{root} go func() { for len(dirsToProcess) > 0 { dirs, files := []os.FileInfo{}, []os.FileInfo{} dirpath := dirsToProcess[len(dirsToProcess)-1] dirsToProcess = dirsToProcess[:len(dirsToProcess)-1] filesInfo, err := sc.ReadDir(sc.ResolveSymlink(dirpath)) if err != nil { fmt.Printf("Error reading directory (%s): %s\n", err.Error(), dirpath) } else { for _, fileInfo := range filesInfo { switch { case fileInfo.Mode().IsDir(): dirs = append(dirs, fileInfo) dirsToProcess = append(dirsToProcess, filepath.Join(dirpath, fileInfo.Name())) case fileInfo.Mode().IsRegular(): files = append(files, fileInfo) case fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink: sympath := filepath.Join(dirpath, fileInfo.Name()) pointerFI, err := sc.Stat(sympath) if err != nil { fmt.Fprintf(os.Stderr, "Error reading symlink (%s): %s\n", err.Error(), sympath) } else { switch { case pointerFI.Mode().IsDir(): dirs = append(dirs, fileInfo) dirsToProcess = append(dirsToProcess, sc.Join(dirpath, fileInfo.Name())) case pointerFI.Mode().IsRegular(): files = append(files, fileInfo) } } } } } iterChannel <- fswalker.WalkItem{Dirpath: dirpath, Dirs: dirs, Files: files, Err: err} } close(iterChannel) }() return iterChannel }
[ "func", "(", "sc", "*", "Client", ")", "Walk", "(", "root", "string", ")", "<-", "chan", "fswalker", ".", "WalkItem", "{", "iterChannel", ":=", "make", "(", "chan", "fswalker", ".", "WalkItem", ")", "\n", "dirsToProcess", ":=", "[", "]", "string", "{", "root", "}", "\n", "go", "func", "(", ")", "{", "for", "len", "(", "dirsToProcess", ")", ">", "0", "{", "dirs", ",", "files", ":=", "[", "]", "os", ".", "FileInfo", "{", "}", ",", "[", "]", "os", ".", "FileInfo", "{", "}", "\n", "dirpath", ":=", "dirsToProcess", "[", "len", "(", "dirsToProcess", ")", "-", "1", "]", "\n", "dirsToProcess", "=", "dirsToProcess", "[", ":", "len", "(", "dirsToProcess", ")", "-", "1", "]", "\n", "filesInfo", ",", "err", ":=", "sc", ".", "ReadDir", "(", "sc", ".", "ResolveSymlink", "(", "dirpath", ")", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "err", ".", "Error", "(", ")", ",", "dirpath", ")", "\n", "}", "else", "{", "for", "_", ",", "fileInfo", ":=", "range", "filesInfo", "{", "switch", "{", "case", "fileInfo", ".", "Mode", "(", ")", ".", "IsDir", "(", ")", ":", "dirs", "=", "append", "(", "dirs", ",", "fileInfo", ")", "\n", "dirsToProcess", "=", "append", "(", "dirsToProcess", ",", "filepath", ".", "Join", "(", "dirpath", ",", "fileInfo", ".", "Name", "(", ")", ")", ")", "\n", "case", "fileInfo", ".", "Mode", "(", ")", ".", "IsRegular", "(", ")", ":", "files", "=", "append", "(", "files", ",", "fileInfo", ")", "\n", "case", "fileInfo", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "==", "os", ".", "ModeSymlink", ":", "sympath", ":=", "filepath", ".", "Join", "(", "dirpath", ",", "fileInfo", ".", "Name", "(", ")", ")", "\n", "pointerFI", ",", "err", ":=", "sc", ".", "Stat", "(", "sympath", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "err", ".", "Error", "(", ")", ",", "sympath", ")", "\n", "}", "else", "{", "switch", "{", "case", "pointerFI", ".", "Mode", "(", ")", ".", "IsDir", "(", ")", ":", "dirs", "=", "append", "(", "dirs", ",", "fileInfo", ")", "\n", "dirsToProcess", "=", "append", "(", "dirsToProcess", ",", "sc", ".", "Join", "(", "dirpath", ",", "fileInfo", ".", "Name", "(", ")", ")", ")", "\n", "case", "pointerFI", ".", "Mode", "(", ")", ".", "IsRegular", "(", ")", ":", "files", "=", "append", "(", "files", ",", "fileInfo", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "iterChannel", "<-", "fswalker", ".", "WalkItem", "{", "Dirpath", ":", "dirpath", ",", "Dirs", ":", "dirs", ",", "Files", ":", "files", ",", "Err", ":", "err", "}", "\n", "}", "\n", "close", "(", "iterChannel", ")", "\n", "}", "(", ")", "\n", "return", "iterChannel", "\n", "}" ]
// Walk walks recursively through the SFTP // @root: root path to start walking through
[ "Walk", "walks", "recursively", "through", "the", "SFTP" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/net/sftp/sftp.go#L88-L132
12,976
0xrawsec/golang-utils
crypto/data/data.go
Md5
func Md5(data []byte) string { md5 := md5.New() md5.Write(data) return hex.EncodeToString(md5.Sum(nil)) }
go
func Md5(data []byte) string { md5 := md5.New() md5.Write(data) return hex.EncodeToString(md5.Sum(nil)) }
[ "func", "Md5", "(", "data", "[", "]", "byte", ")", "string", "{", "md5", ":=", "md5", ".", "New", "(", ")", "\n", "md5", ".", "Write", "(", "data", ")", "\n", "return", "hex", ".", "EncodeToString", "(", "md5", ".", "Sum", "(", "nil", ")", ")", "\n", "}" ]
// Md5 returns the md5 sum of data
[ "Md5", "returns", "the", "md5", "sum", "of", "data" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/crypto/data/data.go#L12-L16
12,977
0xrawsec/golang-utils
crypto/data/data.go
Sha1
func Sha1(data []byte) string { sha1 := sha1.New() sha1.Write(data) return hex.EncodeToString(sha1.Sum(nil)) }
go
func Sha1(data []byte) string { sha1 := sha1.New() sha1.Write(data) return hex.EncodeToString(sha1.Sum(nil)) }
[ "func", "Sha1", "(", "data", "[", "]", "byte", ")", "string", "{", "sha1", ":=", "sha1", ".", "New", "(", ")", "\n", "sha1", ".", "Write", "(", "data", ")", "\n", "return", "hex", ".", "EncodeToString", "(", "sha1", ".", "Sum", "(", "nil", ")", ")", "\n", "}" ]
// Sha1 returns the sha1 sum of data
[ "Sha1", "returns", "the", "sha1", "sum", "of", "data" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/crypto/data/data.go#L19-L23
12,978
0xrawsec/golang-utils
crypto/data/data.go
Sha256
func Sha256(data []byte) string { sha256 := sha256.New() sha256.Write(data) return hex.EncodeToString(sha256.Sum(nil)) }
go
func Sha256(data []byte) string { sha256 := sha256.New() sha256.Write(data) return hex.EncodeToString(sha256.Sum(nil)) }
[ "func", "Sha256", "(", "data", "[", "]", "byte", ")", "string", "{", "sha256", ":=", "sha256", ".", "New", "(", ")", "\n", "sha256", ".", "Write", "(", "data", ")", "\n", "return", "hex", ".", "EncodeToString", "(", "sha256", ".", "Sum", "(", "nil", ")", ")", "\n", "}" ]
// Sha256 returns the sha256 sum of data
[ "Sha256", "returns", "the", "sha256", "sum", "of", "data" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/crypto/data/data.go#L26-L30
12,979
0xrawsec/golang-utils
crypto/data/data.go
Sha512
func Sha512(data []byte) string { sha512 := sha512.New() sha512.Write(data) return hex.EncodeToString(sha512.Sum(nil)) }
go
func Sha512(data []byte) string { sha512 := sha512.New() sha512.Write(data) return hex.EncodeToString(sha512.Sum(nil)) }
[ "func", "Sha512", "(", "data", "[", "]", "byte", ")", "string", "{", "sha512", ":=", "sha512", ".", "New", "(", ")", "\n", "sha512", ".", "Write", "(", "data", ")", "\n", "return", "hex", ".", "EncodeToString", "(", "sha512", ".", "Sum", "(", "nil", ")", ")", "\n", "}" ]
// Sha512 returns the sha512 sum of data
[ "Sha512", "returns", "the", "sha512", "sum", "of", "data" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/crypto/data/data.go#L33-L37
12,980
0xrawsec/golang-utils
stats/stats.go
Truncate
func Truncate(f float64, p int) float64 { return float64(int(f*math.Pow10(p))) / math.Pow10(p) }
go
func Truncate(f float64, p int) float64 { return float64(int(f*math.Pow10(p))) / math.Pow10(p) }
[ "func", "Truncate", "(", "f", "float64", ",", "p", "int", ")", "float64", "{", "return", "float64", "(", "int", "(", "f", "*", "math", ".", "Pow10", "(", "p", ")", ")", ")", "/", "math", ".", "Pow10", "(", "p", ")", "\n", "}" ]
// Trucate truncates a float with p figures of precision
[ "Trucate", "truncates", "a", "float", "with", "p", "figures", "of", "precision" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/stats/stats.go#L6-L8
12,981
0xrawsec/golang-utils
stats/stats.go
Average
func Average(floats []float64) float64 { var sum float64 var cnt float64 for _, f := range floats { sum += f cnt++ } return sum / cnt }
go
func Average(floats []float64) float64 { var sum float64 var cnt float64 for _, f := range floats { sum += f cnt++ } return sum / cnt }
[ "func", "Average", "(", "floats", "[", "]", "float64", ")", "float64", "{", "var", "sum", "float64", "\n", "var", "cnt", "float64", "\n", "for", "_", ",", "f", ":=", "range", "floats", "{", "sum", "+=", "f", "\n", "cnt", "++", "\n", "}", "\n", "return", "sum", "/", "cnt", "\n", "}" ]
// Average computes the average of a table of floats
[ "Average", "computes", "the", "average", "of", "a", "table", "of", "floats" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/stats/stats.go#L11-L19
12,982
0xrawsec/golang-utils
stats/stats.go
StdDev
func StdDev(floats []float64) float64 { var sum float64 a := Average(floats) for _, f := range floats { sum += math.Pow(f-a, 2) } return math.Sqrt(sum / float64(len(floats))) }
go
func StdDev(floats []float64) float64 { var sum float64 a := Average(floats) for _, f := range floats { sum += math.Pow(f-a, 2) } return math.Sqrt(sum / float64(len(floats))) }
[ "func", "StdDev", "(", "floats", "[", "]", "float64", ")", "float64", "{", "var", "sum", "float64", "\n", "a", ":=", "Average", "(", "floats", ")", "\n", "for", "_", ",", "f", ":=", "range", "floats", "{", "sum", "+=", "math", ".", "Pow", "(", "f", "-", "a", ",", "2", ")", "\n", "}", "\n", "return", "math", ".", "Sqrt", "(", "sum", "/", "float64", "(", "len", "(", "floats", ")", ")", ")", "\n", "}" ]
// StdDev returns the standard deviation of a random variable
[ "StdDev", "returns", "the", "standard", "deviation", "of", "a", "random", "variable" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/stats/stats.go#L22-L29
12,983
0xrawsec/golang-utils
fileutils/hash/hash.go
Update
func (h *Hashes) Update(path string) (err error) { var buffer [4096]byte file, err := os.Open(path) if err != nil { return err } defer file.Close() md5 := md5.New() sha1 := sha1.New() sha256 := sha256.New() sha512 := sha512.New() for read, err := file.Read(buffer[:]); err != io.EOF && read != 0; read, err = file.Read(buffer[:]) { if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { return err } md5.Write(buffer[:read]) sha1.Write(buffer[:read]) sha256.Write(buffer[:read]) sha512.Write(buffer[:read]) } h.Path = path h.Md5 = hex.EncodeToString(md5.Sum(nil)) h.Sha1 = hex.EncodeToString(sha1.Sum(nil)) h.Sha256 = hex.EncodeToString(sha256.Sum(nil)) h.Sha512 = hex.EncodeToString(sha512.Sum(nil)) return nil }
go
func (h *Hashes) Update(path string) (err error) { var buffer [4096]byte file, err := os.Open(path) if err != nil { return err } defer file.Close() md5 := md5.New() sha1 := sha1.New() sha256 := sha256.New() sha512 := sha512.New() for read, err := file.Read(buffer[:]); err != io.EOF && read != 0; read, err = file.Read(buffer[:]) { if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { return err } md5.Write(buffer[:read]) sha1.Write(buffer[:read]) sha256.Write(buffer[:read]) sha512.Write(buffer[:read]) } h.Path = path h.Md5 = hex.EncodeToString(md5.Sum(nil)) h.Sha1 = hex.EncodeToString(sha1.Sum(nil)) h.Sha256 = hex.EncodeToString(sha256.Sum(nil)) h.Sha512 = hex.EncodeToString(sha512.Sum(nil)) return nil }
[ "func", "(", "h", "*", "Hashes", ")", "Update", "(", "path", "string", ")", "(", "err", "error", ")", "{", "var", "buffer", "[", "4096", "]", "byte", "\n", "file", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n", "md5", ":=", "md5", ".", "New", "(", ")", "\n", "sha1", ":=", "sha1", ".", "New", "(", ")", "\n", "sha256", ":=", "sha256", ".", "New", "(", ")", "\n", "sha512", ":=", "sha512", ".", "New", "(", ")", "\n\n", "for", "read", ",", "err", ":=", "file", ".", "Read", "(", "buffer", "[", ":", "]", ")", ";", "err", "!=", "io", ".", "EOF", "&&", "read", "!=", "0", ";", "read", ",", "err", "=", "file", ".", "Read", "(", "buffer", "[", ":", "]", ")", "{", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "&&", "err", "!=", "io", ".", "ErrUnexpectedEOF", "{", "return", "err", "\n", "}", "\n", "md5", ".", "Write", "(", "buffer", "[", ":", "read", "]", ")", "\n", "sha1", ".", "Write", "(", "buffer", "[", ":", "read", "]", ")", "\n", "sha256", ".", "Write", "(", "buffer", "[", ":", "read", "]", ")", "\n", "sha512", ".", "Write", "(", "buffer", "[", ":", "read", "]", ")", "\n", "}", "\n\n", "h", ".", "Path", "=", "path", "\n", "h", ".", "Md5", "=", "hex", ".", "EncodeToString", "(", "md5", ".", "Sum", "(", "nil", ")", ")", "\n", "h", ".", "Sha1", "=", "hex", ".", "EncodeToString", "(", "sha1", ".", "Sum", "(", "nil", ")", ")", "\n", "h", ".", "Sha256", "=", "hex", ".", "EncodeToString", "(", "sha256", ".", "Sum", "(", "nil", ")", ")", "\n", "h", ".", "Sha512", "=", "hex", ".", "EncodeToString", "(", "sha512", ".", "Sum", "(", "nil", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Update the current Hashes structure
[ "Update", "the", "current", "Hashes", "structure" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/fileutils/hash/hash.go#L43-L71
12,984
0xrawsec/golang-utils
config/config.go
HasKey
func (c *Config) HasKey(key string) bool { _, ok := (*c)[key] return ok }
go
func (c *Config) HasKey(key string) bool { _, ok := (*c)[key] return ok }
[ "func", "(", "c", "*", "Config", ")", "HasKey", "(", "key", "string", ")", "bool", "{", "_", ",", "ok", ":=", "(", "*", "c", ")", "[", "key", "]", "\n", "return", "ok", "\n", "}" ]
// HasKey returns true if the configuration has the given key
[ "HasKey", "returns", "true", "if", "the", "configuration", "has", "the", "given", "key" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/config/config.go#L289-L292
12,985
0xrawsec/golang-utils
encoding/encoding.go
Unpack
func Unpack(reader io.ReadSeeker, endianness Endianness, data interface{}, offsets ...int64) error { switch { // No offset to deal with case len(offsets) == 0: if err := binary.Read(reader, endianness, data); err != nil { return err } // An offset to deal with case len(offsets) == 1: if soughtOffset, err := reader.Seek(offsets[0], os.SEEK_SET); soughtOffset != offsets[0] || err != nil { switch { case err != nil: return err case soughtOffset != offsets[0]: return ErrSeeking default: if err := binary.Read(reader, endianness, data); err != nil { return err } } } // Error if more than one offset default: return ErrMultipleOffsets } return nil }
go
func Unpack(reader io.ReadSeeker, endianness Endianness, data interface{}, offsets ...int64) error { switch { // No offset to deal with case len(offsets) == 0: if err := binary.Read(reader, endianness, data); err != nil { return err } // An offset to deal with case len(offsets) == 1: if soughtOffset, err := reader.Seek(offsets[0], os.SEEK_SET); soughtOffset != offsets[0] || err != nil { switch { case err != nil: return err case soughtOffset != offsets[0]: return ErrSeeking default: if err := binary.Read(reader, endianness, data); err != nil { return err } } } // Error if more than one offset default: return ErrMultipleOffsets } return nil }
[ "func", "Unpack", "(", "reader", "io", ".", "ReadSeeker", ",", "endianness", "Endianness", ",", "data", "interface", "{", "}", ",", "offsets", "...", "int64", ")", "error", "{", "switch", "{", "// No offset to deal with", "case", "len", "(", "offsets", ")", "==", "0", ":", "if", "err", ":=", "binary", ".", "Read", "(", "reader", ",", "endianness", ",", "data", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// An offset to deal with", "case", "len", "(", "offsets", ")", "==", "1", ":", "if", "soughtOffset", ",", "err", ":=", "reader", ".", "Seek", "(", "offsets", "[", "0", "]", ",", "os", ".", "SEEK_SET", ")", ";", "soughtOffset", "!=", "offsets", "[", "0", "]", "||", "err", "!=", "nil", "{", "switch", "{", "case", "err", "!=", "nil", ":", "return", "err", "\n", "case", "soughtOffset", "!=", "offsets", "[", "0", "]", ":", "return", "ErrSeeking", "\n", "default", ":", "if", "err", ":=", "binary", ".", "Read", "(", "reader", ",", "endianness", ",", "data", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "// Error if more than one offset", "default", ":", "return", "ErrMultipleOffsets", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Unpack data type from reader object. An optional offset can be specified.
[ "Unpack", "data", "type", "from", "reader", "object", ".", "An", "optional", "offset", "can", "be", "specified", "." ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/encoding/encoding.go#L28-L55
12,986
0xrawsec/golang-utils
crypto/file/file.go
Md5
func Md5(path string) (string, error) { var buffer [4096]byte file, err := os.Open(path) if err != nil { return "", err } defer file.Close() md5 := md5.New() for read, err := file.Read(buffer[:]); err != io.EOF && read != 0; read, err = file.Read(buffer[:]) { if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { return "", err } md5.Write(buffer[:read]) } return hex.EncodeToString(md5.Sum(nil)), nil }
go
func Md5(path string) (string, error) { var buffer [4096]byte file, err := os.Open(path) if err != nil { return "", err } defer file.Close() md5 := md5.New() for read, err := file.Read(buffer[:]); err != io.EOF && read != 0; read, err = file.Read(buffer[:]) { if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { return "", err } md5.Write(buffer[:read]) } return hex.EncodeToString(md5.Sum(nil)), nil }
[ "func", "Md5", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "var", "buffer", "[", "4096", "]", "byte", "\n", "file", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n", "md5", ":=", "md5", ".", "New", "(", ")", "\n\n", "for", "read", ",", "err", ":=", "file", ".", "Read", "(", "buffer", "[", ":", "]", ")", ";", "err", "!=", "io", ".", "EOF", "&&", "read", "!=", "0", ";", "read", ",", "err", "=", "file", ".", "Read", "(", "buffer", "[", ":", "]", ")", "{", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "&&", "err", "!=", "io", ".", "ErrUnexpectedEOF", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "md5", ".", "Write", "(", "buffer", "[", ":", "read", "]", ")", "\n", "}", "\n\n", "return", "hex", ".", "EncodeToString", "(", "md5", ".", "Sum", "(", "nil", ")", ")", ",", "nil", "\n", "}" ]
// Md5 return the md5 sum of a file
[ "Md5", "return", "the", "md5", "sum", "of", "a", "file" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/crypto/file/file.go#L14-L31
12,987
0xrawsec/golang-utils
readers/readers.go
NewReverseReader
func NewReverseReader(rs io.ReadSeeker) *ReverseReader { rr := ReverseReader{} rr.rs = rs s, err := rs.Seek(0, os.SEEK_END) if err != nil { panic(err) } rr.size = s rr.offset = s return &rr }
go
func NewReverseReader(rs io.ReadSeeker) *ReverseReader { rr := ReverseReader{} rr.rs = rs s, err := rs.Seek(0, os.SEEK_END) if err != nil { panic(err) } rr.size = s rr.offset = s return &rr }
[ "func", "NewReverseReader", "(", "rs", "io", ".", "ReadSeeker", ")", "*", "ReverseReader", "{", "rr", ":=", "ReverseReader", "{", "}", "\n", "rr", ".", "rs", "=", "rs", "\n", "s", ",", "err", ":=", "rs", ".", "Seek", "(", "0", ",", "os", ".", "SEEK_END", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "rr", ".", "size", "=", "s", "\n", "rr", ".", "offset", "=", "s", "\n", "return", "&", "rr", "\n", "}" ]
// NewReverseReader creates a new ReverseReader
[ "NewReverseReader", "creates", "a", "new", "ReverseReader" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/readers/readers.go#L22-L32
12,988
0xrawsec/golang-utils
readers/readers.go
Read
func (r *ReverseReader) Read(p []byte) (n int, err error) { //fmt.Printf("Offset %d\n", r.offset) //fmt.Printf("Reading %d bytes\n", len(p)) switch { case r.offset <= 0: return 0, io.EOF case r.offset-int64(len(p)) <= 0: r.rs.Seek(0, os.SEEK_SET) n, err = r.rs.Read(p[:r.offset]) r.rs.Seek(0, os.SEEK_SET) r.offset = 0 return n, nil default: r.offset -= int64(len(p)) r.rs.Seek(r.offset, os.SEEK_SET) n, err = r.rs.Read(p) r.rs.Seek(r.offset, os.SEEK_SET) return } }
go
func (r *ReverseReader) Read(p []byte) (n int, err error) { //fmt.Printf("Offset %d\n", r.offset) //fmt.Printf("Reading %d bytes\n", len(p)) switch { case r.offset <= 0: return 0, io.EOF case r.offset-int64(len(p)) <= 0: r.rs.Seek(0, os.SEEK_SET) n, err = r.rs.Read(p[:r.offset]) r.rs.Seek(0, os.SEEK_SET) r.offset = 0 return n, nil default: r.offset -= int64(len(p)) r.rs.Seek(r.offset, os.SEEK_SET) n, err = r.rs.Read(p) r.rs.Seek(r.offset, os.SEEK_SET) return } }
[ "func", "(", "r", "*", "ReverseReader", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "//fmt.Printf(\"Offset %d\\n\", r.offset)", "//fmt.Printf(\"Reading %d bytes\\n\", len(p))", "switch", "{", "case", "r", ".", "offset", "<=", "0", ":", "return", "0", ",", "io", ".", "EOF", "\n", "case", "r", ".", "offset", "-", "int64", "(", "len", "(", "p", ")", ")", "<=", "0", ":", "r", ".", "rs", ".", "Seek", "(", "0", ",", "os", ".", "SEEK_SET", ")", "\n", "n", ",", "err", "=", "r", ".", "rs", ".", "Read", "(", "p", "[", ":", "r", ".", "offset", "]", ")", "\n", "r", ".", "rs", ".", "Seek", "(", "0", ",", "os", ".", "SEEK_SET", ")", "\n", "r", ".", "offset", "=", "0", "\n", "return", "n", ",", "nil", "\n", "default", ":", "r", ".", "offset", "-=", "int64", "(", "len", "(", "p", ")", ")", "\n", "r", ".", "rs", ".", "Seek", "(", "r", ".", "offset", ",", "os", ".", "SEEK_SET", ")", "\n", "n", ",", "err", "=", "r", ".", "rs", ".", "Read", "(", "p", ")", "\n", "r", ".", "rs", ".", "Seek", "(", "r", ".", "offset", ",", "os", ".", "SEEK_SET", ")", "\n", "return", "\n", "}", "\n", "}" ]
// Read implements io.Reader interface // very likely bad performances due to the seeks
[ "Read", "implements", "io", ".", "Reader", "interface", "very", "likely", "bad", "performances", "due", "to", "the", "seeks" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/readers/readers.go#L36-L55
12,989
0xrawsec/golang-utils
readers/readers.go
ReadRune
func (r *ReverseReader) ReadRune() (ru rune, size int, err error) { var rb [4]byte n, err := r.Read(rb[:]) ru, size = utf8.DecodeLastRune(rb[:n]) if err != nil { return } r.offset += int64(n - size) r.rs.Seek(r.offset, os.SEEK_SET) if ru == utf8.RuneError { return ru, size, fmt.Errorf("RuneError") } return }
go
func (r *ReverseReader) ReadRune() (ru rune, size int, err error) { var rb [4]byte n, err := r.Read(rb[:]) ru, size = utf8.DecodeLastRune(rb[:n]) if err != nil { return } r.offset += int64(n - size) r.rs.Seek(r.offset, os.SEEK_SET) if ru == utf8.RuneError { return ru, size, fmt.Errorf("RuneError") } return }
[ "func", "(", "r", "*", "ReverseReader", ")", "ReadRune", "(", ")", "(", "ru", "rune", ",", "size", "int", ",", "err", "error", ")", "{", "var", "rb", "[", "4", "]", "byte", "\n", "n", ",", "err", ":=", "r", ".", "Read", "(", "rb", "[", ":", "]", ")", "\n", "ru", ",", "size", "=", "utf8", ".", "DecodeLastRune", "(", "rb", "[", ":", "n", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "r", ".", "offset", "+=", "int64", "(", "n", "-", "size", ")", "\n", "r", ".", "rs", ".", "Seek", "(", "r", ".", "offset", ",", "os", ".", "SEEK_SET", ")", "\n", "if", "ru", "==", "utf8", ".", "RuneError", "{", "return", "ru", ",", "size", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "\n", "}" ]
// ReadRune reads a rune backward
[ "ReadRune", "reads", "a", "rune", "backward" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/readers/readers.go#L58-L71
12,990
0xrawsec/golang-utils
readers/readers.go
ReversedReadlines
func ReversedReadlines(r io.ReadSeeker) (lines chan []byte) { lines = make(chan []byte) go func() { defer close(lines) var c [1]byte rr := NewReverseReader(r) line := make([]byte, 0, 4096) for n, err := rr.Read(c[:]); err != io.EOF && n != 0; n, err = rr.Read(c[:]) { if c[0] == '\n' { cpLine := make([]byte, len(line)) reversedCopy(cpLine, line) lines <- cpLine line = make([]byte, 0, 4096) } else { // don't append newline line = append(line, c[0]) } } // process the last line cpLine := make([]byte, len(line)) reversedCopy(cpLine, line) lines <- cpLine }() return }
go
func ReversedReadlines(r io.ReadSeeker) (lines chan []byte) { lines = make(chan []byte) go func() { defer close(lines) var c [1]byte rr := NewReverseReader(r) line := make([]byte, 0, 4096) for n, err := rr.Read(c[:]); err != io.EOF && n != 0; n, err = rr.Read(c[:]) { if c[0] == '\n' { cpLine := make([]byte, len(line)) reversedCopy(cpLine, line) lines <- cpLine line = make([]byte, 0, 4096) } else { // don't append newline line = append(line, c[0]) } } // process the last line cpLine := make([]byte, len(line)) reversedCopy(cpLine, line) lines <- cpLine }() return }
[ "func", "ReversedReadlines", "(", "r", "io", ".", "ReadSeeker", ")", "(", "lines", "chan", "[", "]", "byte", ")", "{", "lines", "=", "make", "(", "chan", "[", "]", "byte", ")", "\n", "go", "func", "(", ")", "{", "defer", "close", "(", "lines", ")", "\n\n", "var", "c", "[", "1", "]", "byte", "\n", "rr", ":=", "NewReverseReader", "(", "r", ")", "\n", "line", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "4096", ")", "\n", "for", "n", ",", "err", ":=", "rr", ".", "Read", "(", "c", "[", ":", "]", ")", ";", "err", "!=", "io", ".", "EOF", "&&", "n", "!=", "0", ";", "n", ",", "err", "=", "rr", ".", "Read", "(", "c", "[", ":", "]", ")", "{", "if", "c", "[", "0", "]", "==", "'\\n'", "{", "cpLine", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "line", ")", ")", "\n", "reversedCopy", "(", "cpLine", ",", "line", ")", "\n", "lines", "<-", "cpLine", "\n", "line", "=", "make", "(", "[", "]", "byte", ",", "0", ",", "4096", ")", "\n", "}", "else", "{", "// don't append newline", "line", "=", "append", "(", "line", ",", "c", "[", "0", "]", ")", "\n", "}", "\n", "}", "\n", "// process the last line", "cpLine", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "line", ")", ")", "\n", "reversedCopy", "(", "cpLine", ",", "line", ")", "\n", "lines", "<-", "cpLine", "\n", "}", "(", ")", "\n", "return", "\n", "}" ]
// ReversedReadlines returns the lines found in a reader in reversed order
[ "ReversedReadlines", "returns", "the", "lines", "found", "in", "a", "reader", "in", "reversed", "order" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/readers/readers.go#L97-L122
12,991
0xrawsec/golang-utils
datastructs/syncedset.go
NewSyncedSet
func NewSyncedSet(sets ...*SyncedSet) (ss SyncedSet) { ss.set = make(map[interface{}]bool) if len(sets) > 0 { for _, s := range sets { pDatas := s.List() ss.Add(*pDatas...) } } return }
go
func NewSyncedSet(sets ...*SyncedSet) (ss SyncedSet) { ss.set = make(map[interface{}]bool) if len(sets) > 0 { for _, s := range sets { pDatas := s.List() ss.Add(*pDatas...) } } return }
[ "func", "NewSyncedSet", "(", "sets", "...", "*", "SyncedSet", ")", "(", "ss", "SyncedSet", ")", "{", "ss", ".", "set", "=", "make", "(", "map", "[", "interface", "{", "}", "]", "bool", ")", "\n", "if", "len", "(", "sets", ")", ">", "0", "{", "for", "_", ",", "s", ":=", "range", "sets", "{", "pDatas", ":=", "s", ".", "List", "(", ")", "\n", "ss", ".", "Add", "(", "*", "pDatas", "...", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// NewSyncedSet constructs a new SyncedSet
[ "NewSyncedSet", "constructs", "a", "new", "SyncedSet" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L15-L24
12,992
0xrawsec/golang-utils
datastructs/syncedset.go
Equal
func (s *SyncedSet) Equal(other *SyncedSet) bool { s.RLock() defer s.RUnlock() test := reflect.DeepEqual(s.set, other.set) return test }
go
func (s *SyncedSet) Equal(other *SyncedSet) bool { s.RLock() defer s.RUnlock() test := reflect.DeepEqual(s.set, other.set) return test }
[ "func", "(", "s", "*", "SyncedSet", ")", "Equal", "(", "other", "*", "SyncedSet", ")", "bool", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "test", ":=", "reflect", ".", "DeepEqual", "(", "s", ".", "set", ",", "other", ".", "set", ")", "\n", "return", "test", "\n", "}" ]
// Equal returns true if both sets are equal
[ "Equal", "returns", "true", "if", "both", "sets", "are", "equal" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L33-L38
12,993
0xrawsec/golang-utils
datastructs/syncedset.go
Add
func (s *SyncedSet) Add(datas ...interface{}) { s.Lock() defer s.Unlock() for _, data := range datas { s.set[data] = true } }
go
func (s *SyncedSet) Add(datas ...interface{}) { s.Lock() defer s.Unlock() for _, data := range datas { s.set[data] = true } }
[ "func", "(", "s", "*", "SyncedSet", ")", "Add", "(", "datas", "...", "interface", "{", "}", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "data", ":=", "range", "datas", "{", "s", ".", "set", "[", "data", "]", "=", "true", "\n", "}", "\n", "}" ]
// Add adds data to the set
[ "Add", "adds", "data", "to", "the", "set" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L41-L47
12,994
0xrawsec/golang-utils
datastructs/syncedset.go
Del
func (s *SyncedSet) Del(datas ...interface{}) { s.Lock() defer s.Unlock() for _, data := range datas { delete(s.set, data) } }
go
func (s *SyncedSet) Del(datas ...interface{}) { s.Lock() defer s.Unlock() for _, data := range datas { delete(s.set, data) } }
[ "func", "(", "s", "*", "SyncedSet", ")", "Del", "(", "datas", "...", "interface", "{", "}", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "data", ":=", "range", "datas", "{", "delete", "(", "s", ".", "set", ",", "data", ")", "\n", "}", "\n", "}" ]
// Del deletes data from the set
[ "Del", "deletes", "data", "from", "the", "set" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L50-L56
12,995
0xrawsec/golang-utils
datastructs/syncedset.go
Intersect
func (s *SyncedSet) Intersect(other *SyncedSet) *SyncedSet { newSet := NewSyncedSet() for k := range s.set { if other.Contains(k) { newSet.Add(k) } } return &newSet }
go
func (s *SyncedSet) Intersect(other *SyncedSet) *SyncedSet { newSet := NewSyncedSet() for k := range s.set { if other.Contains(k) { newSet.Add(k) } } return &newSet }
[ "func", "(", "s", "*", "SyncedSet", ")", "Intersect", "(", "other", "*", "SyncedSet", ")", "*", "SyncedSet", "{", "newSet", ":=", "NewSyncedSet", "(", ")", "\n", "for", "k", ":=", "range", "s", ".", "set", "{", "if", "other", ".", "Contains", "(", "k", ")", "{", "newSet", ".", "Add", "(", "k", ")", "\n", "}", "\n", "}", "\n", "return", "&", "newSet", "\n", "}" ]
// Intersect returns a pointer to a new set containing the intersection of current // set and other
[ "Intersect", "returns", "a", "pointer", "to", "a", "new", "set", "containing", "the", "intersection", "of", "current", "set", "and", "other" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L60-L68
12,996
0xrawsec/golang-utils
datastructs/syncedset.go
Union
func (s *SyncedSet) Union(other *SyncedSet) *SyncedSet { newSet := NewSyncedSet() for elt := range s.set { newSet.Add(elt) } for elt := range other.set { newSet.Add(elt) } return &newSet }
go
func (s *SyncedSet) Union(other *SyncedSet) *SyncedSet { newSet := NewSyncedSet() for elt := range s.set { newSet.Add(elt) } for elt := range other.set { newSet.Add(elt) } return &newSet }
[ "func", "(", "s", "*", "SyncedSet", ")", "Union", "(", "other", "*", "SyncedSet", ")", "*", "SyncedSet", "{", "newSet", ":=", "NewSyncedSet", "(", ")", "\n", "for", "elt", ":=", "range", "s", ".", "set", "{", "newSet", ".", "Add", "(", "elt", ")", "\n", "}", "\n", "for", "elt", ":=", "range", "other", ".", "set", "{", "newSet", ".", "Add", "(", "elt", ")", "\n", "}", "\n", "return", "&", "newSet", "\n", "}" ]
// Union returns a pointer to a new set containing the union of current set and other
[ "Union", "returns", "a", "pointer", "to", "a", "new", "set", "containing", "the", "union", "of", "current", "set", "and", "other" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L71-L80
12,997
0xrawsec/golang-utils
datastructs/syncedset.go
Contains
func (s *SyncedSet) Contains(datas ...interface{}) bool { s.RLock() defer s.RUnlock() for _, data := range datas { if _, ok := s.set[data]; !ok { return false } } return true }
go
func (s *SyncedSet) Contains(datas ...interface{}) bool { s.RLock() defer s.RUnlock() for _, data := range datas { if _, ok := s.set[data]; !ok { return false } } return true }
[ "func", "(", "s", "*", "SyncedSet", ")", "Contains", "(", "datas", "...", "interface", "{", "}", ")", "bool", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "data", ":=", "range", "datas", "{", "if", "_", ",", "ok", ":=", "s", ".", "set", "[", "data", "]", ";", "!", "ok", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Contains returns true if the syncedset contains all the data
[ "Contains", "returns", "true", "if", "the", "syncedset", "contains", "all", "the", "data" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L83-L92
12,998
0xrawsec/golang-utils
datastructs/syncedset.go
List
func (s *SyncedSet) List() *[]interface{} { s.RLock() defer s.RUnlock() i := 0 l := make([]interface{}, s.Len()) for k := range s.set { l[i] = k i++ } return &l }
go
func (s *SyncedSet) List() *[]interface{} { s.RLock() defer s.RUnlock() i := 0 l := make([]interface{}, s.Len()) for k := range s.set { l[i] = k i++ } return &l }
[ "func", "(", "s", "*", "SyncedSet", ")", "List", "(", ")", "*", "[", "]", "interface", "{", "}", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "i", ":=", "0", "\n", "l", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "s", ".", "Len", "(", ")", ")", "\n", "for", "k", ":=", "range", "s", ".", "set", "{", "l", "[", "i", "]", "=", "k", "\n", "i", "++", "\n", "}", "\n", "return", "&", "l", "\n", "}" ]
// List returns a pointer to a new list containing the data in the set
[ "List", "returns", "a", "pointer", "to", "a", "new", "list", "containing", "the", "data", "in", "the", "set" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L95-L105
12,999
0xrawsec/golang-utils
datastructs/syncedset.go
Items
func (s *SyncedSet) Items() (c chan interface{}) { c = make(chan interface{}) go func() { s.RLock() defer s.RUnlock() defer close(c) for k := range s.set { c <- k } }() return c }
go
func (s *SyncedSet) Items() (c chan interface{}) { c = make(chan interface{}) go func() { s.RLock() defer s.RUnlock() defer close(c) for k := range s.set { c <- k } }() return c }
[ "func", "(", "s", "*", "SyncedSet", ")", "Items", "(", ")", "(", "c", "chan", "interface", "{", "}", ")", "{", "c", "=", "make", "(", "chan", "interface", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "defer", "close", "(", "c", ")", "\n", "for", "k", ":=", "range", "s", ".", "set", "{", "c", "<-", "k", "\n", "}", "\n", "}", "(", ")", "\n", "return", "c", "\n\n", "}" ]
// Items returns a channel with all the elements contained in the set
[ "Items", "returns", "a", "channel", "with", "all", "the", "elements", "contained", "in", "the", "set" ]
817f34752728629396193de0249e187c6ab1c5cb
https://github.com/0xrawsec/golang-utils/blob/817f34752728629396193de0249e187c6ab1c5cb/datastructs/syncedset.go#L108-L120