query stringlengths 7 8.52k | document stringlengths 9 5.47M | metadata dict |
|---|---|---|
Validate returns an error if key is empty | func (kv BatchKeyRotateKV) Validate() error {
if kv.Key == "" {
return errInvalidArgument
}
return nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Empty indicates if kv is not set | func (kv BatchKeyRotateKV) Empty() bool {
return kv.Key == "" && kv.Value == ""
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Match matches input kv with kv, value will be wildcard matched depending on the user input | func (kv BatchKeyRotateKV) Match(ikv BatchKeyRotateKV) bool {
if kv.Empty() {
return true
}
if strings.EqualFold(kv.Key, ikv.Key) {
return wildcard.Match(kv.Value, ikv.Value)
}
return false
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Validate validates input replicate retries. | func (r BatchKeyRotateRetry) Validate() error {
if r.Attempts < 0 {
return errInvalidArgument
}
if r.Delay < 0 {
return errInvalidArgument
}
return nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Validate validates input key rotation encryption options. | func (e BatchJobKeyRotateEncryption) Validate() error {
if e.Type != sses3 && e.Type != ssekms {
return errInvalidArgument
}
spaces := strings.HasPrefix(e.Key, " ") || strings.HasSuffix(e.Key, " ")
if e.Type == ssekms && spaces {
return crypto.ErrInvalidEncryptionKeyID
}
if e.Type == ssekms && GlobalKMS != ni... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Notify notifies notification endpoint if configured regarding job failure or success. | func (r BatchJobKeyRotateV1) Notify(ctx context.Context, body io.Reader) error {
if r.Flags.Notify.Endpoint == "" {
return nil
}
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.Flags.Notify.Endpoint, body)
if err != nil {
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
KeyRotate rotates encryption key of an object | func (r *BatchJobKeyRotateV1) KeyRotate(ctx context.Context, api ObjectLayer, objInfo ObjectInfo) error {
srcBucket := r.Bucket
srcObject := objInfo.Name
if objInfo.DeleteMarker || !objInfo.VersionPurgeStatus.Empty() {
return nil
}
sseKMS := crypto.S3KMS.IsEncrypted(objInfo.UserDefined)
sseS3 := crypto.S3.IsEn... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Start the batch key rottion job, resumes if there was a pending job via "job.ID" | func (r *BatchJobKeyRotateV1) Start(ctx context.Context, api ObjectLayer, job BatchJobRequest) error {
ri := &batchJobInfo{
JobID: job.ID,
JobType: string(job.Type()),
StartTime: job.Started,
}
if err := ri.load(ctx, api, job); err != nil {
return err
}
globalBatchJobsMetrics.save(job.ID, ri)
lastO... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Validate validates the job definition input | func (r *BatchJobKeyRotateV1) Validate(ctx context.Context, job BatchJobRequest, o ObjectLayer) error {
if r == nil {
return nil
}
if r.APIVersion != batchKeyRotateAPIVersion {
return errInvalidArgument
}
if r.Bucket == "" {
return errInvalidArgument
}
if _, err := o.GetBucketInfo(ctx, r.Bucket, BucketO... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
toGA is an utility method to return the baseInstance data as a GA Instance object | func (bi *baseInstance) toGA() *ga.Instance {
inst := &ga.Instance{Name: bi.name, Zone: bi.zone, NetworkInterfaces: []*ga.NetworkInterface{{}}}
if bi.aliasRange != "" {
inst.NetworkInterfaces[0].AliasIpRanges = []*ga.AliasIpRange{
{IpCidrRange: bi.aliasRange, SubnetworkRangeName: util.TestSecondaryRangeName},
... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
toGA is an utility method to return the baseInstance data as a beta Instance object | func (bi *baseInstance) toBeta() *beta.Instance {
inst := &beta.Instance{Name: bi.name, Zone: bi.zone, NetworkInterfaces: []*beta.NetworkInterface{{}}}
if bi.aliasRange != "" {
inst.NetworkInterfaces[0].AliasIpRanges = []*beta.AliasIpRange{
{IpCidrRange: bi.aliasRange, SubnetworkRangeName: util.TestSecondaryRang... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
newBaseInstanceList is the baseInstanceList constructor | func newBaseInstanceList(allocateCIDR bool, clusterCIDR *net.IPNet, subnetMaskSize int) *baseInstanceList {
cidrSet, _ := cidrset.NewCIDRSet(clusterCIDR, subnetMaskSize)
return &baseInstanceList{
allocateCIDR: allocateCIDR,
clusterCIDR: clusterCIDR,
subnetMaskSize: subnetMaskSize,
cidrSet: cidrSet... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
getOrCreateBaseInstance lazily creates a new base instance, assigning if allocateCIDR is true | func (bil *baseInstanceList) getOrCreateBaseInstance(key *meta.Key) *baseInstance {
bil.lock.Lock()
defer bil.lock.Unlock()
inst, found := bil.instances[*key]
if !found {
inst = &baseInstance{name: key.Name, zone: key.Zone}
if bil.allocateCIDR {
nextRange, _ := bil.cidrSet.AllocateNext()
inst.aliasRange ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
newGAGetHook creates a new closure with the current baseInstanceList to be used as a MockInstances.GetHook | func (bil *baseInstanceList) newGAGetHook() func(ctx context.Context, key *meta.Key, m *cloud.MockInstances) (bool, *ga.Instance, error) {
return func(ctx context.Context, key *meta.Key, m *cloud.MockInstances) (bool, *ga.Instance, error) {
m.Lock.Lock()
defer m.Lock.Unlock()
if _, found := m.Objects[*key]; !fo... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
newBetaGetHook creates a new closure with the current baseInstanceList to be used as a MockBetaInstances.GetHook | func (bil *baseInstanceList) newBetaGetHook() func(ctx context.Context, key *meta.Key, m *cloud.MockBetaInstances) (bool, *beta.Instance, error) {
return func(ctx context.Context, key *meta.Key, m *cloud.MockBetaInstances) (bool, *beta.Instance, error) {
m.Lock.Lock()
defer m.Lock.Unlock()
if _, found := m.Obje... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
newMockCloud returns a mock GCE instance with the appropriate handlers hooks | func (bil *baseInstanceList) newMockCloud() cloud.Cloud {
c := cloud.NewMockGCE(nil)
// insert hooks to lazy create a instance when needed
c.MockInstances.GetHook = bil.newGAGetHook()
c.MockBetaInstances.GetHook = bil.newBetaGetHook()
return c
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded. | func Asset(name string) ([]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found"... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AssetString returns the asset contents as a string (instead of a []byte). | func AssetString(name string) (string, error) {
data, err := Asset(name)
return string(data), err
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables. | func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables. | func MustAssetString(name string) string {
return string(MustAsset(name))
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded. | func AssetInfo(name string) (os.FileInfo, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetIn... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded. | func AssetDigest(name string) ([sha256.Size]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
a, err := f()
if err != nil {
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err)
}
return a.digest, nil
}
ret... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Digests returns a map of all known files and their checksums. | func Digests() (map[string][sha256.Size]byte, error) {
mp := make(map[string][sha256.Size]byte, len(_bindata))
for name := range _bindata {
a, err := _bindata[name]()
if err != nil {
return nil, err
}
mp[name] = a.digest
}
return mp, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AssetNames returns the names of the assets. | func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
RestoreAsset restores an asset under the given directory. | func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), d... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
RestoreAssets restores an asset under the given directory recursively. | func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GetTask returns a new task for the action | func GetTask(name, action string, conf *config.MountConfig) (iface.Task, error) {
switch action {
case "", "create":
return NewCreateTask(name, conf), nil
case "remove", "rm":
return NewRemoveTask(name, conf), nil
default:
return nil, fmt.Errorf("Invalid mount action %q for task %q", action, name)
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NewCommonTime returns a simple 4/4 meter at the specified tempo | func NewCommonTime(bpm float64) *Meter {
return &Meter{
BeatsPerMinute: bpm,
BeatsPerBar: 4,
BeatValue: notes.Quarter,
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
New returns a new meter with the specified parameters | func New(bpm, beatsPerBar float64, beatValue notes.Duration) *Meter {
return &Meter{
BeatsPerMinute: bpm,
BeatsPerBar: beatsPerBar,
BeatValue: beatValue,
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NoteToTime converts a notes.Duration to a time.Duration based on the meter | func (m Meter) NoteToTime(noteVal notes.Duration) time.Duration {
return time.Duration((float64(noteVal/m.BeatValue) / m.BeatsPerMinute) * float64(time.Minute))
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NoteToFreq converts a notes.Duration into a frequency with period equal to that note length | func (m Meter) NoteToFreq(noteVal notes.Duration) float64 {
duration := m.NoteToTime(noteVal)
return 1 / float64(duration.Seconds())
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
/ A tuple is a finite sorted list of elements. It is a data structure that groups data. Tuples are typically immutable sequential collections. The element has related fields of different datatypes. The only way to modify a tuple is to change the fields. Operators such as + and can be applied to tuples. A database recor... | func powerSeries(a int) (int, int) {
return a * a, a * a * a
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GenerateJWTToken generates a JWT token with the username and singed by the given secret key | func GenerateJWTToken(userName, jwtAccSecretKey string) (string, error) {
claims := jwt.MapClaims{
"username": userName,
"ExpiresAt": jwt.TimeFunc().Add(1 * time.Minute).Unix(),
"IssuedAt": jwt.TimeFunc().Unix(),
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString([]byte(... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ValidateJWTToken validates a JWT token with the given key | func ValidateJWTToken(jwtKey, tokenString string) (*Claims, error) {
clms := &Claims{}
tkn, err := jwt.ParseWithClaims(tokenString, clms, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["al... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
WriteCloserWithContext converts ContextCloser to io.Closer, whenever new Close method will be called, the ctx will be passed to it | func WriteCloserWithContext(ctx context.Context, closer WriteContextCloser) io.WriteCloser {
return &closerWithContext{
WriteContextCloser: closer,
ctx: ctx,
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Close closes all resources and returns the result | func (c *closerWithContext) Close() error {
return c.WriteContextCloser.Close(c.ctx)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NilCloser returns closer if it's not nil otherwise returns a nop closer | func NilCloser(r io.Closer) io.Closer {
if r == nil {
return &nilCloser{}
}
return r
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NopWriteCloser returns a WriteCloser with a noop Close method wrapping the provided Writer w | func NopWriteCloser(r io.Writer) io.WriteCloser {
return nopWriteCloser{r}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
NewTracer returns a new tracer | func NewTracer(description string) *Tracer {
return &Tracer{Started: time.Now().UTC(), Description: description}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Start logs start of the trace | func (t *Tracer) Start() *Tracer {
log.Debugf("Tracer started %v.", t.Description)
return t
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Stop logs stop of the trace | func (t *Tracer) Stop() *Tracer {
log.Debugf("Tracer completed %v in %v.", t.Description, time.Since(t.Started))
return t
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ThisFunction returns calling function name | func ThisFunction() string {
var pc [32]uintptr
runtime.Callers(2, pc[:])
return runtime.FuncForPC(pc[0]).Name()
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Value returns value of the string | func (s *SyncString) Value() string {
s.Lock()
defer s.Unlock()
return s.string
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set sets the value of the string | func (s *SyncString) Set(v string) {
s.Lock()
defer s.Unlock()
s.string = v
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ClickableURL fixes address in url to make sure it's clickable, e.g. it replaces "undefined" address like 0.0.0.0 used in network listeners format with loopback 127.0.0.1 | func ClickableURL(in string) string {
out, err := url.Parse(in)
if err != nil {
return in
}
host, port, err := net.SplitHostPort(out.Host)
if err != nil {
return in
}
ip := net.ParseIP(host)
// if address is not an IP, unspecified, e.g. all interfaces 0.0.0.0 or multicast,
// replace with localhost that is... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AsBool converts string to bool, in case of the value is empty or unknown, defaults to false | func AsBool(v string) bool {
if v == "" {
return false
}
out, _ := apiutils.ParseBool(v)
return out
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ParseAdvertiseAddr validates advertise address, makes sure it's not an unreachable or multicast address returns address split into host and port, port could be empty if not specified | func ParseAdvertiseAddr(advertiseIP string) (string, string, error) {
advertiseIP = strings.TrimSpace(advertiseIP)
host := advertiseIP
port := ""
if len(net.ParseIP(host)) == 0 && strings.Contains(advertiseIP, ":") {
var err error
host, port, err = net.SplitHostPort(advertiseIP)
if err != nil {
return "", ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
StringsSliceFromSet returns a sorted strings slice from set | func StringsSliceFromSet(in map[string]struct{}) []string {
if in == nil {
return nil
}
out := make([]string, 0, len(in))
for key := range in {
out = append(out, key)
}
sort.Strings(out)
return out
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ParseOnOff parses whether value is "on" or "off", parameterName is passed for error reporting purposes, defaultValue is returned when no value is set | func ParseOnOff(parameterName, val string, defaultValue bool) (bool, error) {
switch val {
case teleport.On:
return true, nil
case teleport.Off:
return false, nil
case "":
return defaultValue, nil
default:
return false, trace.BadParameter("bad %q parameter value: %q, supported values are on or off", parame... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
IsGroupMember returns whether currently logged user is a member of a group | func IsGroupMember(gid int) (bool, error) {
groups, err := os.Getgroups()
if err != nil {
return false, trace.ConvertSystemError(err)
}
for _, group := range groups {
if group == gid {
return true, nil
}
}
return false, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DNSName extracts DNS name from host:port string. | func DNSName(hostport string) (string, error) {
host, err := Host(hostport)
if err != nil {
return "", trace.Wrap(err)
}
if ip := net.ParseIP(host); len(ip) != 0 {
return "", trace.BadParameter("%v is an IP address", host)
}
return host, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Host extracts host from host:port string | func Host(hostname string) (string, error) {
if hostname == "" {
return "", trace.BadParameter("missing parameter hostname")
}
// if this is IPv4 or V6, return as is
if ip := net.ParseIP(hostname); len(ip) != 0 {
return hostname, nil
}
// has no indication of port, return, note that
// it will not break ipv6... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
SplitHostPort splits host and port and checks that host is not empty | func SplitHostPort(hostname string) (string, string, error) {
host, port, err := net.SplitHostPort(hostname)
if err != nil {
return "", "", trace.Wrap(err)
}
if host == "" {
return "", "", trace.BadParameter("empty hostname")
}
return host, port, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
IsValidHostname checks if a string represents a valid hostname. | func IsValidHostname(hostname string) bool {
for _, label := range strings.Split(hostname, ".") {
if len(validation.IsDNS1035Label(label)) > 0 {
return false
}
}
return true
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ReadPath reads file contents | func ReadPath(path string) ([]byte, error) {
if path == "" {
return nil, trace.NotFound("empty path")
}
s, err := filepath.Abs(path)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
abs, err := filepath.EvalSymlinks(s)
if err != nil {
if errors.Is(err, fs.ErrPermission) {
//do not convert to ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MultiCloser implements io.Close, it sequentially calls Close() on each object | func MultiCloser(closers ...io.Closer) io.Closer {
return &multiCloser{
closers: closers,
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
OpaqueAccessDenied returns a generic NotFound instead of AccessDenied so as to avoid leaking the existence of secret resources. | func OpaqueAccessDenied(err error) error {
if trace.IsAccessDenied(err) {
return trace.NotFound("not found")
}
return trace.Wrap(err)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Pop returns a value from the list, it panics if the value is not there | func (p *PortList) Pop() string {
p.Lock()
defer p.Unlock()
if len(p.ports) == 0 {
panic("list is empty")
}
val := p.ports[len(p.ports)-1]
p.ports = p.ports[:len(p.ports)-1]
return val
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PopInt returns a value from the list, it panics if not enough values were allocated | func (p *PortList) PopInt() int {
i, err := strconv.Atoi(p.Pop())
if err != nil {
panic(err)
}
return i
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GetFreeTCPPorts returns n ports starting from port 20000. | func GetFreeTCPPorts(n int, offset ...int) (PortList, error) {
list := make([]string, 0, n)
start := PortStartingNumber
if len(offset) != 0 {
start = offset[0]
}
for i := start; i < start+n; i++ {
list = append(list, strconv.Itoa(i))
}
return PortList{ports: list}, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
HostUUIDExistsLocally checks if dataDir/host_uuid file exists in local storage. | func HostUUIDExistsLocally(dataDir string) bool {
_, err := ReadHostUUID(dataDir)
return err == nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ReadHostUUID reads host UUID from the file in the data dir | func ReadHostUUID(dataDir string) (string, error) {
out, err := ReadPath(filepath.Join(dataDir, HostUUIDFile))
if err != nil {
if errors.Is(err, fs.ErrPermission) {
//do not convert to system error as this loses the ability to compare that it is a permission error
return "", err
}
return "", trace.Convert... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
WriteHostUUID writes host UUID into a file | func WriteHostUUID(dataDir string, id string) error {
err := os.WriteFile(filepath.Join(dataDir, HostUUIDFile), []byte(id), os.ModeExclusive|0400)
if err != nil {
if errors.Is(err, fs.ErrPermission) {
//do not convert to system error as this loses the ability to compare that it is a permission error
return er... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ReadOrMakeHostUUID looks for a hostid file in the data dir. If present, returns the UUID from it, otherwise generates one | func ReadOrMakeHostUUID(dataDir string) (string, error) {
id, err := ReadHostUUID(dataDir)
if err == nil {
return id, nil
}
if !trace.IsNotFound(err) {
return "", trace.Wrap(err)
}
// Checking error instead of the usual uuid.New() in case uuid generation
// fails due to not enough randomness. It's been known... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
StringSliceSubset returns true if b is a subset of a. | func StringSliceSubset(a []string, b []string) error {
aset := make(map[string]bool)
for _, v := range a {
aset[v] = true
}
for _, v := range b {
_, ok := aset[v]
if !ok {
return trace.BadParameter("%v not in set", v)
}
}
return nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UintSliceSubset returns true if b is a subset of a. | func UintSliceSubset(a []uint16, b []uint16) error {
aset := make(map[uint16]bool)
for _, v := range a {
aset[v] = true
}
for _, v := range b {
_, ok := aset[v]
if !ok {
return trace.BadParameter("%v not in set", v)
}
}
return nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
RemoveFromSlice makes a copy of the slice and removes the passed in values from the copy. | func RemoveFromSlice(slice []string, values ...string) []string {
output := make([]string, 0, len(slice))
remove := make(map[string]bool)
for _, value := range values {
remove[value] = true
}
for _, s := range slice {
_, ok := remove[s]
if ok {
continue
}
output = append(output, s)
}
return outpu... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ChooseRandomString returns a random string from the given slice. | func ChooseRandomString(slice []string) string {
switch len(slice) {
case 0:
return ""
case 1:
return slice[0]
default:
return slice[rand.Intn(len(slice))]
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
CheckCertificateFormatFlag checks if the certificate format is valid. | func CheckCertificateFormatFlag(s string) (string, error) {
switch s {
case constants.CertificateFormatStandard, teleport.CertificateFormatOldSSH, teleport.CertificateFormatUnspecified:
return s, nil
default:
return "", trace.BadParameter("invalid certificate format parameter: %q", s)
}
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
AddrsFromStrings returns strings list converted to address list | func AddrsFromStrings(s apiutils.Strings, defaultPort int) ([]NetAddr, error) {
addrs := make([]NetAddr, len(s))
for i, val := range s {
addr, err := ParseHostPortAddr(val, defaultPort)
if err != nil {
return nil, trace.Wrap(err)
}
addrs[i] = *addr
}
return addrs, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
FileExists checks whether a file exists at a given path | func FileExists(fp string) bool {
_, err := os.Stat(fp)
if err != nil && os.IsNotExist(err) {
return false
}
return true
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ReadAtMost reads up to limit bytes from r, and reports an error when limit bytes are read. | func ReadAtMost(r io.Reader, limit int64) ([]byte, error) {
limitedReader := &io.LimitedReader{R: r, N: limit}
data, err := io.ReadAll(limitedReader)
if err != nil {
return data, err
}
if limitedReader.N <= 0 {
return data, ErrLimitReached
}
return data, nil
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
HasPrefixAny determines if any of the string values have the given prefix. | func HasPrefixAny(prefix string, values []string) bool {
for _, val := range values {
if strings.HasPrefix(val, prefix) {
return true
}
}
return false
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ByteCount converts a size in bytes to a humanreadable string. | func ByteCount(b int64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB",
float64(b)/float64(div), "kMGTPE"[exp])
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Equals checks two matches for equality | func (m *Match) Equals(other *Match) bool {
if m == nil && other == nil {
return true
} else if m == nil {
return false
} else if other == nil {
return false
}
return m.PC == other.PC &&
m.StartLine == other.StartLine &&
m.StartColumn == other.StartColumn &&
m.EndLine == other.EndLine &&
m.EndColumn ... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
String formats the match for humans | func (m Match) String() string {
return fmt.Sprintf("<Match %d %d (%d, %d)-(%d, %d) '%v'>", m.PC, m.TC, m.StartLine, m.StartColumn, m.EndLine, m.EndColumn, string(m.Bytes))
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
LexerEngine does the actual tokenization of the byte slice text using the NFA bytecode in program. If the lexing process fails the Scanner will return an UnconsumedInput error. | func LexerEngine(program inst.Slice, text []byte) Scanner {
done := false
matchPC := -1
matchTC := -1
prevTC := 0
line := 1
col := 1
var scan Scanner
var cqueue, nqueue *queue.Queue = queue.New(len(program)), queue.New(len(program))
scan = func(tc int) (int, *Match, error, Scanner) {
if done && tc == len(t... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Test_Add_Read adds random entries to a testdb then tries to read those entries | func Test_Add_Read(t *testing.T) {
var test_shorthand = make([]byte, 20)
var test_fullpath = make([]byte, 20)
prio := -1
rand.Read(test_shorthand)
rand.Read(test_fullpath)
short := make_printable(test_shorthand)
full := make_printable(test_fullpath)
e := Entry{
shorthand: short,
full_path: full,
pri... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GetUsersHandler lista todos los usuarios | func GetUsersHandler(w http.ResponseWriter, r *http.Request) {
var users []User
for _, v := range Listusers {
users = append(users, v)
}
w.Header().Set("Content-Type", "application/json")
j, err := json.Marshal(users)
if err != nil {
panic(err)
}
w.WriteHeader(http.StatusOK)
w.Write(j)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PostUserHandler crea un usuario en la base de datos | func PostUserHandler(w http.ResponseWriter, r *http.Request) {
var user User
err := json.NewDecoder(r.Body).Decode(&user)
if err != nil {
panic(err)
}
user.CreateAt = time.Now()
id++
k := strconv.Itoa(id)
Listusers[k] = user
w.Header().Set("Content-Type", "application/json")
j, err := json.Marshal(user)
if... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PutUserHandler Actualiza un usuario en base al id | func PutUserHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
k := params["id"]
var userupdate User
err := json.NewDecoder(r.Body).Decode(&userupdate)
if err != nil {
panic(err)
}
if user, ok := Listusers[k]; ok {
userupdate.CreateAt = user.CreateAt
delete(Listusers, k)
Listusers[k]... | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DeleteUserHandler elimina un usuario en base al id | func DeleteUserHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
k := params["id"]
if _, ok := Listusers[k]; ok {
delete(Listusers, k)
} else {
log.Printf("No encontramos el id %s", k)
}
w.WriteHeader(http.StatusNoContent)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalJSON supports json.Marshaler interface | func (v UnloadCheckResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson6a975c40EncodeJsonBenchmark(&w, v)
return w.Buffer.BuildBytes(), w.Error
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalEasyJSON supports easyjson.Marshaler interface | func (v UnloadCheckResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjson6a975c40EncodeJsonBenchmark(w, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalJSON supports json.Unmarshaler interface | func (v *UnloadCheckResponse) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson6a975c40DecodeJsonBenchmark(&r, v)
return r.Error()
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalEasyJSON supports easyjson.Unmarshaler interface | func (v *UnloadCheckResponse) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson6a975c40DecodeJsonBenchmark(l, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalJSON supports json.Marshaler interface | func (v OrderCheckResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson6a975c40EncodeJsonBenchmark1(&w, v)
return w.Buffer.BuildBytes(), w.Error
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalEasyJSON supports easyjson.Marshaler interface | func (v OrderCheckResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjson6a975c40EncodeJsonBenchmark1(w, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalJSON supports json.Unmarshaler interface | func (v *OrderCheckResponse) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson6a975c40DecodeJsonBenchmark1(&r, v)
return r.Error()
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalEasyJSON supports easyjson.Unmarshaler interface | func (v *OrderCheckResponse) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson6a975c40DecodeJsonBenchmark1(l, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalJSON supports json.Marshaler interface | func (v ItemCheckResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson6a975c40EncodeJsonBenchmark2(&w, v)
return w.Buffer.BuildBytes(), w.Error
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalEasyJSON supports easyjson.Marshaler interface | func (v ItemCheckResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjson6a975c40EncodeJsonBenchmark2(w, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalJSON supports json.Unmarshaler interface | func (v *ItemCheckResponse) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson6a975c40DecodeJsonBenchmark2(&r, v)
return r.Error()
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalEasyJSON supports easyjson.Unmarshaler interface | func (v *ItemCheckResponse) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson6a975c40DecodeJsonBenchmark2(l, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalJSON supports json.Marshaler interface | func (v DocumentResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson6a975c40EncodeJsonBenchmark3(&w, v)
return w.Buffer.BuildBytes(), w.Error
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalEasyJSON supports easyjson.Marshaler interface | func (v DocumentResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjson6a975c40EncodeJsonBenchmark3(w, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalJSON supports json.Unmarshaler interface | func (v *DocumentResponse) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson6a975c40DecodeJsonBenchmark3(&r, v)
return r.Error()
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
UnmarshalEasyJSON supports easyjson.Unmarshaler interface | func (v *DocumentResponse) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson6a975c40DecodeJsonBenchmark3(l, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalJSON supports json.Marshaler interface | func (v BlitzedItemResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson6a975c40EncodeJsonBenchmark4(&w, v)
return w.Buffer.BuildBytes(), w.Error
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
MarshalEasyJSON supports easyjson.Marshaler interface | func (v BlitzedItemResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjson6a975c40EncodeJsonBenchmark4(w, v)
} | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.