repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
francoispqt/gojay | encode_sqlnull.go | SQLNullFloat64KeyOmitEmpty | func (enc *Encoder) SQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64) {
if v != nil && v.Valid && v.Float64 != 0 {
enc.Float64KeyOmitEmpty(key, v.Float64)
}
} | go | func (enc *Encoder) SQLNullFloat64KeyOmitEmpty(key string, v *sql.NullFloat64) {
if v != nil && v.Valid && v.Float64 != 0 {
enc.Float64KeyOmitEmpty(key, v.Float64)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullFloat64KeyOmitEmpty",
"(",
"key",
"string",
",",
"v",
"*",
"sql",
".",
"NullFloat64",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"&&",
"v",
".",
"Float64",
"!=",
"0",
"{",
"enc",
".",... | // SQLNullFloat64KeyOmitEmpty adds a string to be encoded or skips it if it is zero value.
// Must be used inside an object as it will encode a key | [
"SQLNullFloat64KeyOmitEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"or",
"skips",
"it",
"if",
"it",
"is",
"zero",
"value",
".",
"Must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L275-L279 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullFloat64KeyNullEmpty | func (enc *Encoder) SQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64) {
if v != nil && v.Valid {
enc.Float64KeyNullEmpty(key, v.Float64)
}
} | go | func (enc *Encoder) SQLNullFloat64KeyNullEmpty(key string, v *sql.NullFloat64) {
if v != nil && v.Valid {
enc.Float64KeyNullEmpty(key, v.Float64)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullFloat64KeyNullEmpty",
"(",
"key",
"string",
",",
"v",
"*",
"sql",
".",
"NullFloat64",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"{",
"enc",
".",
"Float64KeyNullEmpty",
"(",
"key",
",",
... | // SQLNullFloat64KeyNullEmpty adds a string to be encoded or skips it if it is zero value.
// Must be used inside an object as it will encode a key | [
"SQLNullFloat64KeyNullEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"or",
"skips",
"it",
"if",
"it",
"is",
"zero",
"value",
".",
"Must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L283-L287 | train |
francoispqt/gojay | encode_sqlnull.go | EncodeSQLNullBool | func (enc *Encoder) EncodeSQLNullBool(v *sql.NullBool) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
_, _ = enc.encodeBool(v.Bool)
_, err := enc.Write()
if err != nil {
enc.err = err
return err
}
return nil
} | go | func (enc *Encoder) EncodeSQLNullBool(v *sql.NullBool) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
_, _ = enc.encodeBool(v.Bool)
_, err := enc.Write()
if err != nil {
enc.err = err
return err
}
return nil
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"EncodeSQLNullBool",
"(",
"v",
"*",
"sql",
".",
"NullBool",
")",
"error",
"{",
"if",
"enc",
".",
"isPooled",
"==",
"1",
"{",
"panic",
"(",
"InvalidUsagePooledEncoderError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
... | // NullBool
// EncodeSQLNullBool encodes a string to | [
"NullBool",
"EncodeSQLNullBool",
"encodes",
"a",
"string",
"to"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L292-L303 | train |
francoispqt/gojay | encode_sqlnull.go | AddSQLNullBoolKey | func (enc *Encoder) AddSQLNullBoolKey(key string, v *sql.NullBool) {
enc.BoolKey(key, v.Bool)
} | go | func (enc *Encoder) AddSQLNullBoolKey(key string, v *sql.NullBool) {
enc.BoolKey(key, v.Bool)
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"AddSQLNullBoolKey",
"(",
"key",
"string",
",",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"enc",
".",
"BoolKey",
"(",
"key",
",",
"v",
".",
"Bool",
")",
"\n",
"}"
] | // AddSQLNullBoolKey adds a string to be encoded, must be used inside an object as it will encode a key | [
"AddSQLNullBoolKey",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L319-L321 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullBool | func (enc *Encoder) SQLNullBool(v *sql.NullBool) {
enc.Bool(v.Bool)
} | go | func (enc *Encoder) SQLNullBool(v *sql.NullBool) {
enc.Bool(v.Bool)
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullBool",
"(",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"enc",
".",
"Bool",
"(",
"v",
".",
"Bool",
")",
"\n",
"}"
] | // SQLNullBool adds a string to be encoded, must be used inside an object as it will encode a key | [
"SQLNullBool",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L340-L342 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullBoolOmitEmpty | func (enc *Encoder) SQLNullBoolOmitEmpty(v *sql.NullBool) {
if v != nil && v.Valid && v.Bool != false {
enc.Bool(v.Bool)
}
} | go | func (enc *Encoder) SQLNullBoolOmitEmpty(v *sql.NullBool) {
if v != nil && v.Valid && v.Bool != false {
enc.Bool(v.Bool)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullBoolOmitEmpty",
"(",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"&&",
"v",
".",
"Bool",
"!=",
"false",
"{",
"enc",
".",
"Bool",
"(",
"v",
".",
"B... | // SQLNullBoolOmitEmpty adds a string to be encoded, must be used inside an object as it will encode a key | [
"SQLNullBoolOmitEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L345-L349 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullBoolNullEmpty | func (enc *Encoder) SQLNullBoolNullEmpty(v *sql.NullBool) {
if v != nil && v.Valid {
enc.BoolNullEmpty(v.Bool)
}
} | go | func (enc *Encoder) SQLNullBoolNullEmpty(v *sql.NullBool) {
if v != nil && v.Valid {
enc.BoolNullEmpty(v.Bool)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullBoolNullEmpty",
"(",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"{",
"enc",
".",
"BoolNullEmpty",
"(",
"v",
".",
"Bool",
")",
"\n",
"}",
"\n",
"}"
... | // SQLNullBoolNullEmpty adds a string to be encoded, must be used inside an object as it will encode a key | [
"SQLNullBoolNullEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L352-L356 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullBoolKeyOmitEmpty | func (enc *Encoder) SQLNullBoolKeyOmitEmpty(key string, v *sql.NullBool) {
if v != nil && v.Valid && v.Bool != false {
enc.BoolKeyOmitEmpty(key, v.Bool)
}
} | go | func (enc *Encoder) SQLNullBoolKeyOmitEmpty(key string, v *sql.NullBool) {
if v != nil && v.Valid && v.Bool != false {
enc.BoolKeyOmitEmpty(key, v.Bool)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullBoolKeyOmitEmpty",
"(",
"key",
"string",
",",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"&&",
"v",
".",
"Bool",
"!=",
"false",
"{",
"enc",
".",
"B... | // SQLNullBoolKeyOmitEmpty adds a string to be encoded or skips it if it is zero value.
// Must be used inside an object as it will encode a key | [
"SQLNullBoolKeyOmitEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"or",
"skips",
"it",
"if",
"it",
"is",
"zero",
"value",
".",
"Must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L365-L369 | train |
francoispqt/gojay | encode_sqlnull.go | SQLNullBoolKeyNullEmpty | func (enc *Encoder) SQLNullBoolKeyNullEmpty(key string, v *sql.NullBool) {
if v != nil && v.Valid {
enc.BoolKeyNullEmpty(key, v.Bool)
}
} | go | func (enc *Encoder) SQLNullBoolKeyNullEmpty(key string, v *sql.NullBool) {
if v != nil && v.Valid {
enc.BoolKeyNullEmpty(key, v.Bool)
}
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"SQLNullBoolKeyNullEmpty",
"(",
"key",
"string",
",",
"v",
"*",
"sql",
".",
"NullBool",
")",
"{",
"if",
"v",
"!=",
"nil",
"&&",
"v",
".",
"Valid",
"{",
"enc",
".",
"BoolKeyNullEmpty",
"(",
"key",
",",
"v",
"... | // SQLNullBoolKeyNullEmpty adds a string to be encoded or skips it if it is zero value.
// Must be used inside an object as it will encode a key | [
"SQLNullBoolKeyNullEmpty",
"adds",
"a",
"string",
"to",
"be",
"encoded",
"or",
"skips",
"it",
"if",
"it",
"is",
"zero",
"value",
".",
"Must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_sqlnull.go#L373-L377 | train |
francoispqt/gojay | encode_null.go | Null | func (enc *Encoder) Null() {
enc.grow(5)
r := enc.getPreviousRune()
if r != '[' {
enc.writeByte(',')
}
enc.writeBytes(nullBytes)
} | go | func (enc *Encoder) Null() {
enc.grow(5)
r := enc.getPreviousRune()
if r != '[' {
enc.writeByte(',')
}
enc.writeBytes(nullBytes)
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"Null",
"(",
")",
"{",
"enc",
".",
"grow",
"(",
"5",
")",
"\n",
"r",
":=",
"enc",
".",
"getPreviousRune",
"(",
")",
"\n",
"if",
"r",
"!=",
"'['",
"{",
"enc",
".",
"writeByte",
"(",
"','",
")",
"\n",
"}... | // Null adds a `null` to be encoded. Must be used while encoding an array.` | [
"Null",
"adds",
"a",
"null",
"to",
"be",
"encoded",
".",
"Must",
"be",
"used",
"while",
"encoding",
"an",
"array",
"."
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_null.go#L9-L16 | train |
francoispqt/gojay | encode_null.go | NullKey | func (enc *Encoder) NullKey(key string) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
enc.grow(5 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key)
enc.writeBytes(objKey)
enc.writeBytes(nullBytes)
} | go | func (enc *Encoder) NullKey(key string) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
enc.grow(5 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key)
enc.writeBytes(objKey)
enc.writeBytes(nullBytes)
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"NullKey",
"(",
"key",
"string",
")",
"{",
"if",
"enc",
".",
"hasKeys",
"{",
"if",
"!",
"enc",
".",
"keyExists",
"(",
"key",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"enc",
".",
"grow",
"(",
"5",
... | // NullKey adds a `null` to be encoded. Must be used while encoding an array.` | [
"NullKey",
"adds",
"a",
"null",
"to",
"be",
"encoded",
".",
"Must",
"be",
"used",
"while",
"encoding",
"an",
"array",
"."
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_null.go#L24-L39 | train |
francoispqt/gojay | encode_object.go | EncodeObject | func (enc *Encoder) EncodeObject(v MarshalerJSONObject) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
_, err := enc.encodeObject(v)
if err != nil {
enc.err = err
return err
}
_, err = enc.Write()
if err != nil {
enc.err = err
return err
}
re... | go | func (enc *Encoder) EncodeObject(v MarshalerJSONObject) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
_, err := enc.encodeObject(v)
if err != nil {
enc.err = err
return err
}
_, err = enc.Write()
if err != nil {
enc.err = err
return err
}
re... | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"EncodeObject",
"(",
"v",
"MarshalerJSONObject",
")",
"error",
"{",
"if",
"enc",
".",
"isPooled",
"==",
"1",
"{",
"panic",
"(",
"InvalidUsagePooledEncoderError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"_",
... | // EncodeObject encodes an object to JSON | [
"EncodeObject",
"encodes",
"an",
"object",
"to",
"JSON"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_object.go#L9-L24 | train |
francoispqt/gojay | encode_object.go | EncodeObjectKeys | func (enc *Encoder) EncodeObjectKeys(v MarshalerJSONObject, keys []string) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
enc.hasKeys = true
enc.keys = keys
_, err := enc.encodeObject(v)
if err != nil {
enc.err = err
return err
}
_, err = enc.Writ... | go | func (enc *Encoder) EncodeObjectKeys(v MarshalerJSONObject, keys []string) error {
if enc.isPooled == 1 {
panic(InvalidUsagePooledEncoderError("Invalid usage of pooled encoder"))
}
enc.hasKeys = true
enc.keys = keys
_, err := enc.encodeObject(v)
if err != nil {
enc.err = err
return err
}
_, err = enc.Writ... | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"EncodeObjectKeys",
"(",
"v",
"MarshalerJSONObject",
",",
"keys",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"enc",
".",
"isPooled",
"==",
"1",
"{",
"panic",
"(",
"InvalidUsagePooledEncoderError",
"(",
"\"",
"\"",... | // EncodeObjectKeys encodes an object to JSON | [
"EncodeObjectKeys",
"encodes",
"an",
"object",
"to",
"JSON"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_object.go#L27-L44 | train |
francoispqt/gojay | encode_object.go | AddObjectKey | func (enc *Encoder) AddObjectKey(key string, v MarshalerJSONObject) {
enc.ObjectKey(key, v)
} | go | func (enc *Encoder) AddObjectKey(key string, v MarshalerJSONObject) {
enc.ObjectKey(key, v)
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"AddObjectKey",
"(",
"key",
"string",
",",
"v",
"MarshalerJSONObject",
")",
"{",
"enc",
".",
"ObjectKey",
"(",
"key",
",",
"v",
")",
"\n",
"}"
] | // AddObjectKey adds a struct to be encoded, must be used inside an object as it will encode a key
// value must implement MarshalerJSONObject | [
"AddObjectKey",
"adds",
"a",
"struct",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key",
"value",
"must",
"implement",
"MarshalerJSONObject"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_object.go#L82-L84 | train |
francoispqt/gojay | encode_object.go | ObjectKey | func (enc *Encoder) ObjectKey(key string, v MarshalerJSONObject) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
if v.IsNil() {
enc.grow(2 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key)
enc.writeBytes(objKeyObj)
... | go | func (enc *Encoder) ObjectKey(key string, v MarshalerJSONObject) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
if v.IsNil() {
enc.grow(2 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key)
enc.writeBytes(objKeyObj)
... | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"ObjectKey",
"(",
"key",
"string",
",",
"v",
"MarshalerJSONObject",
")",
"{",
"if",
"enc",
".",
"hasKeys",
"{",
"if",
"!",
"enc",
".",
"keyExists",
"(",
"key",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",... | // ObjectKey adds a struct to be encoded, must be used inside an object as it will encode a key
// value must implement MarshalerJSONObject | [
"ObjectKey",
"adds",
"a",
"struct",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key",
"value",
"must",
"implement",
"MarshalerJSONObject"
] | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_object.go#L223-L261 | train |
francoispqt/gojay | encode_object.go | ObjectKeyWithKeys | func (enc *Encoder) ObjectKeyWithKeys(key string, value MarshalerJSONObject, keys []string) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
if value.IsNil() {
enc.grow(2 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key... | go | func (enc *Encoder) ObjectKeyWithKeys(key string, value MarshalerJSONObject, keys []string) {
if enc.hasKeys {
if !enc.keyExists(key) {
return
}
}
if value.IsNil() {
enc.grow(2 + len(key))
r := enc.getPreviousRune()
if r != '{' {
enc.writeByte(',')
}
enc.writeByte('"')
enc.writeStringEscape(key... | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"ObjectKeyWithKeys",
"(",
"key",
"string",
",",
"value",
"MarshalerJSONObject",
",",
"keys",
"[",
"]",
"string",
")",
"{",
"if",
"enc",
".",
"hasKeys",
"{",
"if",
"!",
"enc",
".",
"keyExists",
"(",
"key",
")",
... | // ObjectKeyWithKeys adds a struct to be encoded, must be used inside an object as it will encode a key.
// Value must implement MarshalerJSONObject. It will only encode the keys in keys. | [
"ObjectKeyWithKeys",
"adds",
"a",
"struct",
"to",
"be",
"encoded",
"must",
"be",
"used",
"inside",
"an",
"object",
"as",
"it",
"will",
"encode",
"a",
"key",
".",
"Value",
"must",
"implement",
"MarshalerJSONObject",
".",
"It",
"will",
"only",
"encode",
"the",... | e46791d21b5e950e35a725e34cbee72354cc7d10 | https://github.com/francoispqt/gojay/blob/e46791d21b5e950e35a725e34cbee72354cc7d10/encode_object.go#L265-L299 | train |
golang/snappy | encode.go | Encode | func Encode(dst, src []byte) []byte {
if n := MaxEncodedLen(len(src)); n < 0 {
panic(ErrTooLarge)
} else if len(dst) < n {
dst = make([]byte, n)
}
// The block starts with the varint-encoded length of the decompressed bytes.
d := binary.PutUvarint(dst, uint64(len(src)))
for len(src) > 0 {
p := src
src =... | go | func Encode(dst, src []byte) []byte {
if n := MaxEncodedLen(len(src)); n < 0 {
panic(ErrTooLarge)
} else if len(dst) < n {
dst = make([]byte, n)
}
// The block starts with the varint-encoded length of the decompressed bytes.
d := binary.PutUvarint(dst, uint64(len(src)))
for len(src) > 0 {
p := src
src =... | [
"func",
"Encode",
"(",
"dst",
",",
"src",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"n",
":=",
"MaxEncodedLen",
"(",
"len",
"(",
"src",
")",
")",
";",
"n",
"<",
"0",
"{",
"panic",
"(",
"ErrTooLarge",
")",
"\n",
"}",
"else",
"if",
"l... | // Encode returns the encoded form of src. The returned slice may be a sub-
// slice of dst if dst was large enough to hold the entire encoded block.
// Otherwise, a newly allocated slice will be returned.
//
// The dst and src must not overlap. It is valid to pass a nil dst. | [
"Encode",
"returns",
"the",
"encoded",
"form",
"of",
"src",
".",
"The",
"returned",
"slice",
"may",
"be",
"a",
"sub",
"-",
"slice",
"of",
"dst",
"if",
"dst",
"was",
"large",
"enough",
"to",
"hold",
"the",
"entire",
"encoded",
"block",
".",
"Otherwise",
... | 2a8bb927dd31d8daada140a5d09578521ce5c36a | https://github.com/golang/snappy/blob/2a8bb927dd31d8daada140a5d09578521ce5c36a/encode.go#L18-L41 | train |
golang/snappy | encode.go | MaxEncodedLen | func MaxEncodedLen(srcLen int) int {
n := uint64(srcLen)
if n > 0xffffffff {
return -1
}
// Compressed data can be defined as:
// compressed := item* literal*
// item := literal* copy
//
// The trailing literal sequence has a space blowup of at most 62/60
// since a literal of length 60 needs one... | go | func MaxEncodedLen(srcLen int) int {
n := uint64(srcLen)
if n > 0xffffffff {
return -1
}
// Compressed data can be defined as:
// compressed := item* literal*
// item := literal* copy
//
// The trailing literal sequence has a space blowup of at most 62/60
// since a literal of length 60 needs one... | [
"func",
"MaxEncodedLen",
"(",
"srcLen",
"int",
")",
"int",
"{",
"n",
":=",
"uint64",
"(",
"srcLen",
")",
"\n",
"if",
"n",
">",
"0xffffffff",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"// Compressed data can be defined as:",
"// compressed := item* literal*",
... | // MaxEncodedLen returns the maximum length of a snappy block, given its
// uncompressed length.
//
// It will return a negative value if srcLen is too large to encode. | [
"MaxEncodedLen",
"returns",
"the",
"maximum",
"length",
"of",
"a",
"snappy",
"block",
"given",
"its",
"uncompressed",
"length",
".",
"It",
"will",
"return",
"a",
"negative",
"value",
"if",
"srcLen",
"is",
"too",
"large",
"to",
"encode",
"."
] | 2a8bb927dd31d8daada140a5d09578521ce5c36a | https://github.com/golang/snappy/blob/2a8bb927dd31d8daada140a5d09578521ce5c36a/encode.go#L76-L106 | train |
golang/snappy | encode.go | Close | func (w *Writer) Close() error {
w.Flush()
ret := w.err
if w.err == nil {
w.err = errClosed
}
return ret
} | go | func (w *Writer) Close() error {
w.Flush()
ret := w.err
if w.err == nil {
w.err = errClosed
}
return ret
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"Flush",
"(",
")",
"\n",
"ret",
":=",
"w",
".",
"err",
"\n",
"if",
"w",
".",
"err",
"==",
"nil",
"{",
"w",
".",
"err",
"=",
"errClosed",
"\n",
"}",
"\n",
"retu... | // Close calls Flush and then closes the Writer. | [
"Close",
"calls",
"Flush",
"and",
"then",
"closes",
"the",
"Writer",
"."
] | 2a8bb927dd31d8daada140a5d09578521ce5c36a | https://github.com/golang/snappy/blob/2a8bb927dd31d8daada140a5d09578521ce5c36a/encode.go#L278-L285 | train |
golang/snappy | decode.go | Decode | func Decode(dst, src []byte) ([]byte, error) {
dLen, s, err := decodedLen(src)
if err != nil {
return nil, err
}
if dLen <= len(dst) {
dst = dst[:dLen]
} else {
dst = make([]byte, dLen)
}
switch decode(dst, src[s:]) {
case 0:
return dst, nil
case decodeErrCodeUnsupportedLiteralLength:
return nil, err... | go | func Decode(dst, src []byte) ([]byte, error) {
dLen, s, err := decodedLen(src)
if err != nil {
return nil, err
}
if dLen <= len(dst) {
dst = dst[:dLen]
} else {
dst = make([]byte, dLen)
}
switch decode(dst, src[s:]) {
case 0:
return dst, nil
case decodeErrCodeUnsupportedLiteralLength:
return nil, err... | [
"func",
"Decode",
"(",
"dst",
",",
"src",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"dLen",
",",
"s",
",",
"err",
":=",
"decodedLen",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err... | // Decode returns the decoded form of src. The returned slice may be a sub-
// slice of dst if dst was large enough to hold the entire decoded block.
// Otherwise, a newly allocated slice will be returned.
//
// The dst and src must not overlap. It is valid to pass a nil dst. | [
"Decode",
"returns",
"the",
"decoded",
"form",
"of",
"src",
".",
"The",
"returned",
"slice",
"may",
"be",
"a",
"sub",
"-",
"slice",
"of",
"dst",
"if",
"dst",
"was",
"large",
"enough",
"to",
"hold",
"the",
"entire",
"decoded",
"block",
".",
"Otherwise",
... | 2a8bb927dd31d8daada140a5d09578521ce5c36a | https://github.com/golang/snappy/blob/2a8bb927dd31d8daada140a5d09578521ce5c36a/decode.go#L55-L72 | train |
coreos/go-iptables | iptables/iptables.go | IsNotExist | func (e *Error) IsNotExist() bool {
return e.ExitStatus() == 1 &&
(e.msg == fmt.Sprintf("%s: Bad rule (does a matching rule exist in that chain?).\n", getIptablesCommand(e.proto)) ||
e.msg == fmt.Sprintf("%s: No chain/target/match by that name.\n", getIptablesCommand(e.proto)))
} | go | func (e *Error) IsNotExist() bool {
return e.ExitStatus() == 1 &&
(e.msg == fmt.Sprintf("%s: Bad rule (does a matching rule exist in that chain?).\n", getIptablesCommand(e.proto)) ||
e.msg == fmt.Sprintf("%s: No chain/target/match by that name.\n", getIptablesCommand(e.proto)))
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"IsNotExist",
"(",
")",
"bool",
"{",
"return",
"e",
".",
"ExitStatus",
"(",
")",
"==",
"1",
"&&",
"(",
"e",
".",
"msg",
"==",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"getIptablesCommand",
"(",
"e",... | // IsNotExist returns true if the error is due to the chain or rule not existing | [
"IsNotExist",
"returns",
"true",
"if",
"the",
"error",
"is",
"due",
"to",
"the",
"chain",
"or",
"rule",
"not",
"existing"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L50-L54 | train |
coreos/go-iptables | iptables/iptables.go | NewWithProtocol | func NewWithProtocol(proto Protocol) (*IPTables, error) {
path, err := exec.LookPath(getIptablesCommand(proto))
if err != nil {
return nil, err
}
vstring, err := getIptablesVersionString(path)
v1, v2, v3, mode, err := extractIptablesVersion(vstring)
checkPresent, waitPresent, randomFullyPresent := getIptablesC... | go | func NewWithProtocol(proto Protocol) (*IPTables, error) {
path, err := exec.LookPath(getIptablesCommand(proto))
if err != nil {
return nil, err
}
vstring, err := getIptablesVersionString(path)
v1, v2, v3, mode, err := extractIptablesVersion(vstring)
checkPresent, waitPresent, randomFullyPresent := getIptablesC... | [
"func",
"NewWithProtocol",
"(",
"proto",
"Protocol",
")",
"(",
"*",
"IPTables",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"getIptablesCommand",
"(",
"proto",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // New creates a new IPTables for the given proto.
// The proto will determine which command is used, either "iptables" or "ip6tables". | [
"New",
"creates",
"a",
"new",
"IPTables",
"for",
"the",
"given",
"proto",
".",
"The",
"proto",
"will",
"determine",
"which",
"command",
"is",
"used",
"either",
"iptables",
"or",
"ip6tables",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L84-L106 | train |
coreos/go-iptables | iptables/iptables.go | ListChains | func (ipt *IPTables) ListChains(table string) ([]string, error) {
args := []string{"-t", table, "-S"}
result, err := ipt.executeList(args)
if err != nil {
return nil, err
}
// Iterate over rules to find all default (-P) and user-specified (-N) chains.
// Chains definition always come before rules.
// Format ... | go | func (ipt *IPTables) ListChains(table string) ([]string, error) {
args := []string{"-t", table, "-S"}
result, err := ipt.executeList(args)
if err != nil {
return nil, err
}
// Iterate over rules to find all default (-P) and user-specified (-N) chains.
// Chains definition always come before rules.
// Format ... | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"ListChains",
"(",
"table",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
"}",
"\n\n",
"result",
",",
... | // ListChains returns a slice containing the name of each chain in the specified table. | [
"ListChains",
"returns",
"a",
"slice",
"containing",
"the",
"name",
"of",
"each",
"chain",
"in",
"the",
"specified",
"table",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L177-L199 | train |
coreos/go-iptables | iptables/iptables.go | Stats | func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
args := []string{"-t", table, "-L", chain, "-n", "-v", "-x"}
lines, err := ipt.executeList(args)
if err != nil {
return nil, err
}
appendSubnet := func(addr string) string {
if strings.IndexByte(addr, byte('/')) < 0 {
if strings.IndexByt... | go | func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
args := []string{"-t", table, "-L", chain, "-n", "-v", "-x"}
lines, err := ipt.executeList(args)
if err != nil {
return nil, err
}
appendSubnet := func(addr string) string {
if strings.IndexByte(addr, byte('/')) < 0 {
if strings.IndexByt... | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"Stats",
"(",
"table",
",",
"chain",
"string",
")",
"(",
"[",
"]",
"[",
"]",
"string",
",",
"error",
")",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
",",
"c... | // Stats lists rules including the byte and packet counts | [
"Stats",
"lists",
"rules",
"including",
"the",
"byte",
"and",
"packet",
"counts"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L202-L265 | train |
coreos/go-iptables | iptables/iptables.go | NewChain | func (ipt *IPTables) NewChain(table, chain string) error {
return ipt.run("-t", table, "-N", chain)
} | go | func (ipt *IPTables) NewChain(table, chain string) error {
return ipt.run("-t", table, "-N", chain)
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"NewChain",
"(",
"table",
",",
"chain",
"string",
")",
"error",
"{",
"return",
"ipt",
".",
"run",
"(",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
",",
"chain",
")",
"\n",
"}"
] | // NewChain creates a new chain in the specified table.
// If the chain already exists, it will result in an error. | [
"NewChain",
"creates",
"a",
"new",
"chain",
"in",
"the",
"specified",
"table",
".",
"If",
"the",
"chain",
"already",
"exists",
"it",
"will",
"result",
"in",
"an",
"error",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L301-L303 | train |
coreos/go-iptables | iptables/iptables.go | RenameChain | func (ipt *IPTables) RenameChain(table, oldChain, newChain string) error {
return ipt.run("-t", table, "-E", oldChain, newChain)
} | go | func (ipt *IPTables) RenameChain(table, oldChain, newChain string) error {
return ipt.run("-t", table, "-E", oldChain, newChain)
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"RenameChain",
"(",
"table",
",",
"oldChain",
",",
"newChain",
"string",
")",
"error",
"{",
"return",
"ipt",
".",
"run",
"(",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
",",
"oldChain",
",",
"newChain",
")",
... | // RenameChain renames the old chain to the new one. | [
"RenameChain",
"renames",
"the",
"old",
"chain",
"to",
"the",
"new",
"one",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L330-L332 | train |
coreos/go-iptables | iptables/iptables.go | DeleteChain | func (ipt *IPTables) DeleteChain(table, chain string) error {
return ipt.run("-t", table, "-X", chain)
} | go | func (ipt *IPTables) DeleteChain(table, chain string) error {
return ipt.run("-t", table, "-X", chain)
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"DeleteChain",
"(",
"table",
",",
"chain",
"string",
")",
"error",
"{",
"return",
"ipt",
".",
"run",
"(",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
",",
"chain",
")",
"\n",
"}"
] | // DeleteChain deletes the chain in the specified table.
// The chain must be empty | [
"DeleteChain",
"deletes",
"the",
"chain",
"in",
"the",
"specified",
"table",
".",
"The",
"chain",
"must",
"be",
"empty"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L336-L338 | train |
coreos/go-iptables | iptables/iptables.go | ChangePolicy | func (ipt *IPTables) ChangePolicy(table, chain, target string) error {
return ipt.run("-t", table, "-P", chain, target)
} | go | func (ipt *IPTables) ChangePolicy(table, chain, target string) error {
return ipt.run("-t", table, "-P", chain, target)
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"ChangePolicy",
"(",
"table",
",",
"chain",
",",
"target",
"string",
")",
"error",
"{",
"return",
"ipt",
".",
"run",
"(",
"\"",
"\"",
",",
"table",
",",
"\"",
"\"",
",",
"chain",
",",
"target",
")",
"\n",
... | // ChangePolicy changes policy on chain to target | [
"ChangePolicy",
"changes",
"policy",
"on",
"chain",
"to",
"target"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L341-L343 | train |
coreos/go-iptables | iptables/iptables.go | GetIptablesVersion | func (ipt *IPTables) GetIptablesVersion() (int, int, int) {
return ipt.v1, ipt.v2, ipt.v3
} | go | func (ipt *IPTables) GetIptablesVersion() (int, int, int) {
return ipt.v1, ipt.v2, ipt.v3
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"GetIptablesVersion",
"(",
")",
"(",
"int",
",",
"int",
",",
"int",
")",
"{",
"return",
"ipt",
".",
"v1",
",",
"ipt",
".",
"v2",
",",
"ipt",
".",
"v3",
"\n",
"}"
] | // Return version components of the underlying iptables command | [
"Return",
"version",
"components",
"of",
"the",
"underlying",
"iptables",
"command"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L351-L353 | train |
coreos/go-iptables | iptables/iptables.go | run | func (ipt *IPTables) run(args ...string) error {
return ipt.runWithOutput(args, nil)
} | go | func (ipt *IPTables) run(args ...string) error {
return ipt.runWithOutput(args, nil)
} | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"run",
"(",
"args",
"...",
"string",
")",
"error",
"{",
"return",
"ipt",
".",
"runWithOutput",
"(",
"args",
",",
"nil",
")",
"\n",
"}"
] | // run runs an iptables command with the given arguments, ignoring
// any stdout output | [
"run",
"runs",
"an",
"iptables",
"command",
"with",
"the",
"given",
"arguments",
"ignoring",
"any",
"stdout",
"output"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L357-L359 | train |
coreos/go-iptables | iptables/iptables.go | runWithOutput | func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
args = append([]string{ipt.path}, args...)
if ipt.hasWait {
args = append(args, "--wait")
} else {
fmu, err := newXtablesFileLock()
if err != nil {
return err
}
ul, err := fmu.tryLock()
if err != nil {
return err
}
defe... | go | func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
args = append([]string{ipt.path}, args...)
if ipt.hasWait {
args = append(args, "--wait")
} else {
fmu, err := newXtablesFileLock()
if err != nil {
return err
}
ul, err := fmu.tryLock()
if err != nil {
return err
}
defe... | [
"func",
"(",
"ipt",
"*",
"IPTables",
")",
"runWithOutput",
"(",
"args",
"[",
"]",
"string",
",",
"stdout",
"io",
".",
"Writer",
")",
"error",
"{",
"args",
"=",
"append",
"(",
"[",
"]",
"string",
"{",
"ipt",
".",
"path",
"}",
",",
"args",
"...",
"... | // runWithOutput runs an iptables command with the given arguments,
// writing any stdout output to the given writer | [
"runWithOutput",
"runs",
"an",
"iptables",
"command",
"with",
"the",
"given",
"arguments",
"writing",
"any",
"stdout",
"output",
"to",
"the",
"given",
"writer"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L363-L397 | train |
coreos/go-iptables | iptables/iptables.go | filterRuleOutput | func filterRuleOutput(rule string) string {
out := rule
// work around an output difference in nftables mode where counters
// are output in iptables-save format, rather than iptables -S format
// The string begins with "[0:0]"
//
// Fixes #49
if groups := counterRegex.FindStringSubmatch(out); groups != nil {
... | go | func filterRuleOutput(rule string) string {
out := rule
// work around an output difference in nftables mode where counters
// are output in iptables-save format, rather than iptables -S format
// The string begins with "[0:0]"
//
// Fixes #49
if groups := counterRegex.FindStringSubmatch(out); groups != nil {
... | [
"func",
"filterRuleOutput",
"(",
"rule",
"string",
")",
"string",
"{",
"out",
":=",
"rule",
"\n\n",
"// work around an output difference in nftables mode where counters",
"// are output in iptables-save format, rather than iptables -S format",
"// The string begins with \"[0:0]\"",
"//... | // filterRuleOutput works around some inconsistencies in output.
// For example, when iptables is in legacy vs. nftables mode, it produces
// different results. | [
"filterRuleOutput",
"works",
"around",
"some",
"inconsistencies",
"in",
"output",
".",
"For",
"example",
"when",
"iptables",
"is",
"in",
"legacy",
"vs",
".",
"nftables",
"mode",
"it",
"produces",
"different",
"results",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/iptables.go#L517-L532 | train |
coreos/go-iptables | iptables/lock.go | Unlock | func (l *fileLock) Unlock() error {
defer l.mu.Unlock()
return syscall.Close(l.fd)
} | go | func (l *fileLock) Unlock() error {
defer l.mu.Unlock()
return syscall.Close(l.fd)
} | [
"func",
"(",
"l",
"*",
"fileLock",
")",
"Unlock",
"(",
")",
"error",
"{",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"syscall",
".",
"Close",
"(",
"l",
".",
"fd",
")",
"\n",
"}"
] | // Unlock closes the underlying file, which implicitly unlocks it as well. It
// also unlocks the associated mutex. | [
"Unlock",
"closes",
"the",
"underlying",
"file",
"which",
"implicitly",
"unlocks",
"it",
"as",
"well",
".",
"It",
"also",
"unlocks",
"the",
"associated",
"mutex",
"."
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/lock.go#L71-L74 | train |
coreos/go-iptables | iptables/lock.go | newXtablesFileLock | func newXtablesFileLock() (*fileLock, error) {
fd, err := syscall.Open(xtablesLockFilePath, os.O_CREATE, defaultFilePerm)
if err != nil {
return nil, err
}
return &fileLock{fd: fd}, nil
} | go | func newXtablesFileLock() (*fileLock, error) {
fd, err := syscall.Open(xtablesLockFilePath, os.O_CREATE, defaultFilePerm)
if err != nil {
return nil, err
}
return &fileLock{fd: fd}, nil
} | [
"func",
"newXtablesFileLock",
"(",
")",
"(",
"*",
"fileLock",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"syscall",
".",
"Open",
"(",
"xtablesLockFilePath",
",",
"os",
".",
"O_CREATE",
",",
"defaultFilePerm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // newXtablesFileLock opens a new lock on the xtables lockfile without
// acquiring the lock | [
"newXtablesFileLock",
"opens",
"a",
"new",
"lock",
"on",
"the",
"xtables",
"lockfile",
"without",
"acquiring",
"the",
"lock"
] | 78b5fff24e6df8886ef8eca9411f683a884349a5 | https://github.com/coreos/go-iptables/blob/78b5fff24e6df8886ef8eca9411f683a884349a5/iptables/lock.go#L78-L84 | train |
edsrzf/mmap-go | mmap.go | Map | func Map(f *os.File, prot, flags int) (MMap, error) {
return MapRegion(f, -1, prot, flags, 0)
} | go | func Map(f *os.File, prot, flags int) (MMap, error) {
return MapRegion(f, -1, prot, flags, 0)
} | [
"func",
"Map",
"(",
"f",
"*",
"os",
".",
"File",
",",
"prot",
",",
"flags",
"int",
")",
"(",
"MMap",
",",
"error",
")",
"{",
"return",
"MapRegion",
"(",
"f",
",",
"-",
"1",
",",
"prot",
",",
"flags",
",",
"0",
")",
"\n",
"}"
] | // Map maps an entire file into memory.
// If ANON is set in flags, f is ignored. | [
"Map",
"maps",
"an",
"entire",
"file",
"into",
"memory",
".",
"If",
"ANON",
"is",
"set",
"in",
"flags",
"f",
"is",
"ignored",
"."
] | 904c4ced31cdffe19e971afa0b3d319ff06d9c72 | https://github.com/edsrzf/mmap-go/blob/904c4ced31cdffe19e971afa0b3d319ff06d9c72/mmap.go#L48-L50 | train |
edsrzf/mmap-go | mmap.go | MapRegion | func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MMap, error) {
if offset%int64(os.Getpagesize()) != 0 {
return nil, errors.New("offset parameter must be a multiple of the system's page size")
}
var fd uintptr
if flags&ANON == 0 {
fd = uintptr(f.Fd())
if length < 0 {
fi, err := f.Sta... | go | func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MMap, error) {
if offset%int64(os.Getpagesize()) != 0 {
return nil, errors.New("offset parameter must be a multiple of the system's page size")
}
var fd uintptr
if flags&ANON == 0 {
fd = uintptr(f.Fd())
if length < 0 {
fi, err := f.Sta... | [
"func",
"MapRegion",
"(",
"f",
"*",
"os",
".",
"File",
",",
"length",
"int",
",",
"prot",
",",
"flags",
"int",
",",
"offset",
"int64",
")",
"(",
"MMap",
",",
"error",
")",
"{",
"if",
"offset",
"%",
"int64",
"(",
"os",
".",
"Getpagesize",
"(",
")"... | // MapRegion maps part of a file into memory.
// The offset parameter must be a multiple of the system's page size.
// If length < 0, the entire file will be mapped.
// If ANON is set in flags, f is ignored. | [
"MapRegion",
"maps",
"part",
"of",
"a",
"file",
"into",
"memory",
".",
"The",
"offset",
"parameter",
"must",
"be",
"a",
"multiple",
"of",
"the",
"system",
"s",
"page",
"size",
".",
"If",
"length",
"<",
"0",
"the",
"entire",
"file",
"will",
"be",
"mappe... | 904c4ced31cdffe19e971afa0b3d319ff06d9c72 | https://github.com/edsrzf/mmap-go/blob/904c4ced31cdffe19e971afa0b3d319ff06d9c72/mmap.go#L56-L78 | train |
matrix-org/gomatrix | events.go | Body | func (event *Event) Body() (body string, ok bool) {
value, exists := event.Content["body"]
if !exists {
return
}
body, ok = value.(string)
return
} | go | func (event *Event) Body() (body string, ok bool) {
value, exists := event.Content["body"]
if !exists {
return
}
body, ok = value.(string)
return
} | [
"func",
"(",
"event",
"*",
"Event",
")",
"Body",
"(",
")",
"(",
"body",
"string",
",",
"ok",
"bool",
")",
"{",
"value",
",",
"exists",
":=",
"event",
".",
"Content",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"exists",
"{",
"return",
"\n",
"}",
"\n... | // Body returns the value of the "body" key in the event content if it is
// present and is a string. | [
"Body",
"returns",
"the",
"value",
"of",
"the",
"body",
"key",
"in",
"the",
"event",
"content",
"if",
"it",
"is",
"present",
"and",
"is",
"a",
"string",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/events.go#L23-L30 | train |
matrix-org/gomatrix | events.go | MessageType | func (event *Event) MessageType() (msgtype string, ok bool) {
value, exists := event.Content["msgtype"]
if !exists {
return
}
msgtype, ok = value.(string)
return
} | go | func (event *Event) MessageType() (msgtype string, ok bool) {
value, exists := event.Content["msgtype"]
if !exists {
return
}
msgtype, ok = value.(string)
return
} | [
"func",
"(",
"event",
"*",
"Event",
")",
"MessageType",
"(",
")",
"(",
"msgtype",
"string",
",",
"ok",
"bool",
")",
"{",
"value",
",",
"exists",
":=",
"event",
".",
"Content",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"exists",
"{",
"return",
"\n",
... | // MessageType returns the value of the "msgtype" key in the event content if
// it is present and is a string. | [
"MessageType",
"returns",
"the",
"value",
"of",
"the",
"msgtype",
"key",
"in",
"the",
"event",
"content",
"if",
"it",
"is",
"present",
"and",
"is",
"a",
"string",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/events.go#L34-L41 | train |
matrix-org/gomatrix | events.go | GetHTMLMessage | func GetHTMLMessage(msgtype, htmlText string) HTMLMessage {
return HTMLMessage{
Body: html.UnescapeString(htmlRegex.ReplaceAllLiteralString(htmlText, "")),
MsgType: msgtype,
Format: "org.matrix.custom.html",
FormattedBody: htmlText,
}
} | go | func GetHTMLMessage(msgtype, htmlText string) HTMLMessage {
return HTMLMessage{
Body: html.UnescapeString(htmlRegex.ReplaceAllLiteralString(htmlText, "")),
MsgType: msgtype,
Format: "org.matrix.custom.html",
FormattedBody: htmlText,
}
} | [
"func",
"GetHTMLMessage",
"(",
"msgtype",
",",
"htmlText",
"string",
")",
"HTMLMessage",
"{",
"return",
"HTMLMessage",
"{",
"Body",
":",
"html",
".",
"UnescapeString",
"(",
"htmlRegex",
".",
"ReplaceAllLiteralString",
"(",
"htmlText",
",",
"\"",
"\"",
")",
")"... | // GetHTMLMessage returns an HTMLMessage with the body set to a stripped version of the provided HTML, in addition
// to the provided HTML. | [
"GetHTMLMessage",
"returns",
"an",
"HTMLMessage",
"with",
"the",
"body",
"set",
"to",
"a",
"stripped",
"version",
"of",
"the",
"provided",
"HTML",
"in",
"addition",
"to",
"the",
"provided",
"HTML",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/events.go#L106-L113 | train |
matrix-org/gomatrix | room.go | GetMembershipState | func (room Room) GetMembershipState(userID string) string {
state := "leave"
event := room.GetStateEvent("m.room.member", userID)
if event != nil {
membershipState, found := event.Content["membership"]
if found {
mState, isString := membershipState.(string)
if isString {
state = mState
}
}
}
ret... | go | func (room Room) GetMembershipState(userID string) string {
state := "leave"
event := room.GetStateEvent("m.room.member", userID)
if event != nil {
membershipState, found := event.Content["membership"]
if found {
mState, isString := membershipState.(string)
if isString {
state = mState
}
}
}
ret... | [
"func",
"(",
"room",
"Room",
")",
"GetMembershipState",
"(",
"userID",
"string",
")",
"string",
"{",
"state",
":=",
"\"",
"\"",
"\n",
"event",
":=",
"room",
".",
"GetStateEvent",
"(",
"\"",
"\"",
",",
"userID",
")",
"\n",
"if",
"event",
"!=",
"nil",
... | // GetMembershipState returns the membership state of the given user ID in this room. If there is
// no entry for this member, 'leave' is returned for consistency with left users. | [
"GetMembershipState",
"returns",
"the",
"membership",
"state",
"of",
"the",
"given",
"user",
"ID",
"in",
"this",
"room",
".",
"If",
"there",
"is",
"no",
"entry",
"for",
"this",
"member",
"leave",
"is",
"returned",
"for",
"consistency",
"with",
"left",
"users... | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/room.go#L28-L41 | train |
matrix-org/gomatrix | room.go | NewRoom | func NewRoom(roomID string) *Room {
// Init the State map and return a pointer to the Room
return &Room{
ID: roomID,
State: make(map[string]map[string]*Event),
}
} | go | func NewRoom(roomID string) *Room {
// Init the State map and return a pointer to the Room
return &Room{
ID: roomID,
State: make(map[string]map[string]*Event),
}
} | [
"func",
"NewRoom",
"(",
"roomID",
"string",
")",
"*",
"Room",
"{",
"// Init the State map and return a pointer to the Room",
"return",
"&",
"Room",
"{",
"ID",
":",
"roomID",
",",
"State",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]"... | // NewRoom creates a new Room with the given ID | [
"NewRoom",
"creates",
"a",
"new",
"Room",
"with",
"the",
"given",
"ID"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/room.go#L44-L50 | train |
matrix-org/gomatrix | responses.go | HasSingleStageFlow | func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool {
for _, f := range r.Flows {
if len(f.Stages) == 1 && f.Stages[0] == stageName {
return true
}
}
return false
} | go | func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool {
for _, f := range r.Flows {
if len(f.Stages) == 1 && f.Stages[0] == stageName {
return true
}
}
return false
} | [
"func",
"(",
"r",
"RespUserInteractive",
")",
"HasSingleStageFlow",
"(",
"stageName",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"r",
".",
"Flows",
"{",
"if",
"len",
"(",
"f",
".",
"Stages",
")",
"==",
"1",
"&&",
"f",
".",
"St... | // HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName. | [
"HasSingleStageFlow",
"returns",
"true",
"if",
"there",
"exists",
"at",
"least",
"1",
"Flow",
"with",
"a",
"single",
"stage",
"of",
"stageName",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/responses.go#L94-L101 | train |
matrix-org/gomatrix | client.go | SetCredentials | func (cli *Client) SetCredentials(userID, accessToken string) {
cli.AccessToken = accessToken
cli.UserID = userID
} | go | func (cli *Client) SetCredentials(userID, accessToken string) {
cli.AccessToken = accessToken
cli.UserID = userID
} | [
"func",
"(",
"cli",
"*",
"Client",
")",
"SetCredentials",
"(",
"userID",
",",
"accessToken",
"string",
")",
"{",
"cli",
".",
"AccessToken",
"=",
"accessToken",
"\n",
"cli",
".",
"UserID",
"=",
"userID",
"\n",
"}"
] | // SetCredentials sets the user ID and access token on this client instance. | [
"SetCredentials",
"sets",
"the",
"user",
"ID",
"and",
"access",
"token",
"on",
"this",
"client",
"instance",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/client.go#L99-L102 | train |
matrix-org/gomatrix | client.go | MakeRequest | func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) ([]byte, error) {
var req *http.Request
var err error
if reqBody != nil {
var jsonStr []byte
jsonStr, err = json.Marshal(reqBody)
if err != nil {
return nil, err
}
req, err = http.NewRequest(method, h... | go | func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) ([]byte, error) {
var req *http.Request
var err error
if reqBody != nil {
var jsonStr []byte
jsonStr, err = json.Marshal(reqBody)
if err != nil {
return nil, err
}
req, err = http.NewRequest(method, h... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"MakeRequest",
"(",
"method",
"string",
",",
"httpURL",
"string",
",",
"reqBody",
"interface",
"{",
"}",
",",
"resBody",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"req",
... | // MakeRequest makes a JSON HTTP request to the given URL.
// If "resBody" is not nil, the response body will be json.Unmarshalled into it.
//
// Returns the HTTP body as bytes on 2xx with a nil error. Returns an error if the response is not 2xx along
// with the HTTP body bytes if it got that far. This error is an HTT... | [
"MakeRequest",
"makes",
"a",
"JSON",
"HTTP",
"request",
"to",
"the",
"given",
"URL",
".",
"If",
"resBody",
"is",
"not",
"nil",
"the",
"response",
"body",
"will",
"be",
"json",
".",
"Unmarshalled",
"into",
"it",
".",
"Returns",
"the",
"HTTP",
"body",
"as"... | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/client.go#L191-L248 | train |
matrix-org/gomatrix | client.go | UploadLink | func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) {
res, err := cli.Client.Get(link)
if res != nil {
defer res.Body.Close()
}
if err != nil {
return nil, err
}
return cli.UploadToContentRepo(res.Body, res.Header.Get("Content-Type"), res.ContentLength)
} | go | func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) {
res, err := cli.Client.Get(link)
if res != nil {
defer res.Body.Close()
}
if err != nil {
return nil, err
}
return cli.UploadToContentRepo(res.Body, res.Header.Get("Content-Type"), res.ContentLength)
} | [
"func",
"(",
"cli",
"*",
"Client",
")",
"UploadLink",
"(",
"link",
"string",
")",
"(",
"*",
"RespMediaUpload",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"cli",
".",
"Client",
".",
"Get",
"(",
"link",
")",
"\n",
"if",
"res",
"!=",
"nil",
"{... | // UploadLink uploads an HTTP URL and then returns an MXC URI. | [
"UploadLink",
"uploads",
"an",
"HTTP",
"URL",
"and",
"then",
"returns",
"an",
"MXC",
"URI",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/client.go#L587-L596 | train |
matrix-org/gomatrix | client.go | NewClient | func NewClient(homeserverURL, userID, accessToken string) (*Client, error) {
hsURL, err := url.Parse(homeserverURL)
if err != nil {
return nil, err
}
// By default, use an in-memory store which will never save filter ids / next batch tokens to disk.
// The client will work with this storer: it just won't remembe... | go | func NewClient(homeserverURL, userID, accessToken string) (*Client, error) {
hsURL, err := url.Parse(homeserverURL)
if err != nil {
return nil, err
}
// By default, use an in-memory store which will never save filter ids / next batch tokens to disk.
// The client will work with this storer: it just won't remembe... | [
"func",
"NewClient",
"(",
"homeserverURL",
",",
"userID",
",",
"accessToken",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"hsURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"homeserverURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // NewClient creates a new Matrix Client ready for syncing | [
"NewClient",
"creates",
"a",
"new",
"Matrix",
"Client",
"ready",
"for",
"syncing"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/client.go#L687-L708 | train |
matrix-org/gomatrix | userids.go | escape | func escape(buf *bytes.Buffer, b byte) {
buf.WriteByte('_')
if b == '_' {
buf.WriteByte('_') // another _
} else {
buf.WriteByte(b + 0x20) // ASCII shift A-Z to a-z
}
} | go | func escape(buf *bytes.Buffer, b byte) {
buf.WriteByte('_')
if b == '_' {
buf.WriteByte('_') // another _
} else {
buf.WriteByte(b + 0x20) // ASCII shift A-Z to a-z
}
} | [
"func",
"escape",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
",",
"b",
"byte",
")",
"{",
"buf",
".",
"WriteByte",
"(",
"'_'",
")",
"\n",
"if",
"b",
"==",
"'_'",
"{",
"buf",
".",
"WriteByte",
"(",
"'_'",
")",
"// another _",
"\n",
"}",
"else",
"{",
... | // escape the given alpha character and writes it to the buffer | [
"escape",
"the",
"given",
"alpha",
"character",
"and",
"writes",
"it",
"to",
"the",
"buffer"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/userids.go#L22-L29 | train |
matrix-org/gomatrix | sync.go | NewDefaultSyncer | func NewDefaultSyncer(userID string, store Storer) *DefaultSyncer {
return &DefaultSyncer{
UserID: userID,
Store: store,
listeners: make(map[string][]OnEventListener),
}
} | go | func NewDefaultSyncer(userID string, store Storer) *DefaultSyncer {
return &DefaultSyncer{
UserID: userID,
Store: store,
listeners: make(map[string][]OnEventListener),
}
} | [
"func",
"NewDefaultSyncer",
"(",
"userID",
"string",
",",
"store",
"Storer",
")",
"*",
"DefaultSyncer",
"{",
"return",
"&",
"DefaultSyncer",
"{",
"UserID",
":",
"userID",
",",
"Store",
":",
"store",
",",
"listeners",
":",
"make",
"(",
"map",
"[",
"string",... | // NewDefaultSyncer returns an instantiated DefaultSyncer | [
"NewDefaultSyncer",
"returns",
"an",
"instantiated",
"DefaultSyncer"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/sync.go#L35-L41 | train |
matrix-org/gomatrix | sync.go | OnEventType | func (s *DefaultSyncer) OnEventType(eventType string, callback OnEventListener) {
_, exists := s.listeners[eventType]
if !exists {
s.listeners[eventType] = []OnEventListener{}
}
s.listeners[eventType] = append(s.listeners[eventType], callback)
} | go | func (s *DefaultSyncer) OnEventType(eventType string, callback OnEventListener) {
_, exists := s.listeners[eventType]
if !exists {
s.listeners[eventType] = []OnEventListener{}
}
s.listeners[eventType] = append(s.listeners[eventType], callback)
} | [
"func",
"(",
"s",
"*",
"DefaultSyncer",
")",
"OnEventType",
"(",
"eventType",
"string",
",",
"callback",
"OnEventListener",
")",
"{",
"_",
",",
"exists",
":=",
"s",
".",
"listeners",
"[",
"eventType",
"]",
"\n",
"if",
"!",
"exists",
"{",
"s",
".",
"lis... | // OnEventType allows callers to be notified when there are new events for the given event type.
// There are no duplicate checks. | [
"OnEventType",
"allows",
"callers",
"to",
"be",
"notified",
"when",
"there",
"are",
"new",
"events",
"for",
"the",
"given",
"event",
"type",
".",
"There",
"are",
"no",
"duplicate",
"checks",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/sync.go#L91-L97 | train |
matrix-org/gomatrix | sync.go | shouldProcessResponse | func (s *DefaultSyncer) shouldProcessResponse(resp *RespSync, since string) bool {
if since == "" {
return false
}
// This is a horrible hack because /sync will return the most recent messages for a room
// as soon as you /join it. We do NOT want to process those events in that particular room
// because they ma... | go | func (s *DefaultSyncer) shouldProcessResponse(resp *RespSync, since string) bool {
if since == "" {
return false
}
// This is a horrible hack because /sync will return the most recent messages for a room
// as soon as you /join it. We do NOT want to process those events in that particular room
// because they ma... | [
"func",
"(",
"s",
"*",
"DefaultSyncer",
")",
"shouldProcessResponse",
"(",
"resp",
"*",
"RespSync",
",",
"since",
"string",
")",
"bool",
"{",
"if",
"since",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// This is a horrible hack because /sync wi... | // shouldProcessResponse returns true if the response should be processed. May modify the response to remove
// stuff that shouldn't be processed. | [
"shouldProcessResponse",
"returns",
"true",
"if",
"the",
"response",
"should",
"be",
"processed",
".",
"May",
"modify",
"the",
"response",
"to",
"remove",
"stuff",
"that",
"shouldn",
"t",
"be",
"processed",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/sync.go#L101-L134 | train |
matrix-org/gomatrix | store.go | SaveFilterID | func (s *InMemoryStore) SaveFilterID(userID, filterID string) {
s.Filters[userID] = filterID
} | go | func (s *InMemoryStore) SaveFilterID(userID, filterID string) {
s.Filters[userID] = filterID
} | [
"func",
"(",
"s",
"*",
"InMemoryStore",
")",
"SaveFilterID",
"(",
"userID",
",",
"filterID",
"string",
")",
"{",
"s",
".",
"Filters",
"[",
"userID",
"]",
"=",
"filterID",
"\n",
"}"
] | // SaveFilterID to memory. | [
"SaveFilterID",
"to",
"memory",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/store.go#L29-L31 | train |
matrix-org/gomatrix | store.go | SaveNextBatch | func (s *InMemoryStore) SaveNextBatch(userID, nextBatchToken string) {
s.NextBatch[userID] = nextBatchToken
} | go | func (s *InMemoryStore) SaveNextBatch(userID, nextBatchToken string) {
s.NextBatch[userID] = nextBatchToken
} | [
"func",
"(",
"s",
"*",
"InMemoryStore",
")",
"SaveNextBatch",
"(",
"userID",
",",
"nextBatchToken",
"string",
")",
"{",
"s",
".",
"NextBatch",
"[",
"userID",
"]",
"=",
"nextBatchToken",
"\n",
"}"
] | // SaveNextBatch to memory. | [
"SaveNextBatch",
"to",
"memory",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/store.go#L39-L41 | train |
matrix-org/gomatrix | store.go | SaveRoom | func (s *InMemoryStore) SaveRoom(room *Room) {
s.Rooms[room.ID] = room
} | go | func (s *InMemoryStore) SaveRoom(room *Room) {
s.Rooms[room.ID] = room
} | [
"func",
"(",
"s",
"*",
"InMemoryStore",
")",
"SaveRoom",
"(",
"room",
"*",
"Room",
")",
"{",
"s",
".",
"Rooms",
"[",
"room",
".",
"ID",
"]",
"=",
"room",
"\n",
"}"
] | // SaveRoom to memory. | [
"SaveRoom",
"to",
"memory",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/store.go#L49-L51 | train |
matrix-org/gomatrix | store.go | NewInMemoryStore | func NewInMemoryStore() *InMemoryStore {
return &InMemoryStore{
Filters: make(map[string]string),
NextBatch: make(map[string]string),
Rooms: make(map[string]*Room),
}
} | go | func NewInMemoryStore() *InMemoryStore {
return &InMemoryStore{
Filters: make(map[string]string),
NextBatch: make(map[string]string),
Rooms: make(map[string]*Room),
}
} | [
"func",
"NewInMemoryStore",
"(",
")",
"*",
"InMemoryStore",
"{",
"return",
"&",
"InMemoryStore",
"{",
"Filters",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"NextBatch",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"... | // NewInMemoryStore constructs a new InMemoryStore. | [
"NewInMemoryStore",
"constructs",
"a",
"new",
"InMemoryStore",
"."
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/store.go#L59-L65 | train |
matrix-org/gomatrix | filter.go | Validate | func (filter *Filter) Validate() error {
if filter.EventFormat != "client" && filter.EventFormat != "federation" {
return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
}
return nil
} | go | func (filter *Filter) Validate() error {
if filter.EventFormat != "client" && filter.EventFormat != "federation" {
return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
}
return nil
} | [
"func",
"(",
"filter",
"*",
"Filter",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"filter",
".",
"EventFormat",
"!=",
"\"",
"\"",
"&&",
"filter",
".",
"EventFormat",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\\\"",
"\\\"",... | // Validate checks if the filter contains valid property values | [
"Validate",
"checks",
"if",
"the",
"filter",
"contains",
"valid",
"property",
"values"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/filter.go#L53-L58 | train |
matrix-org/gomatrix | filter.go | DefaultFilter | func DefaultFilter() Filter {
return Filter{
AccountData: DefaultFilterPart(),
EventFields: nil,
EventFormat: "client",
Presence: DefaultFilterPart(),
Room: RoomFilter{
AccountData: DefaultFilterPart(),
Ephemeral: DefaultFilterPart(),
IncludeLeave: false,
NotRooms: nil,
Rooms: ... | go | func DefaultFilter() Filter {
return Filter{
AccountData: DefaultFilterPart(),
EventFields: nil,
EventFormat: "client",
Presence: DefaultFilterPart(),
Room: RoomFilter{
AccountData: DefaultFilterPart(),
Ephemeral: DefaultFilterPart(),
IncludeLeave: false,
NotRooms: nil,
Rooms: ... | [
"func",
"DefaultFilter",
"(",
")",
"Filter",
"{",
"return",
"Filter",
"{",
"AccountData",
":",
"DefaultFilterPart",
"(",
")",
",",
"EventFields",
":",
"nil",
",",
"EventFormat",
":",
"\"",
"\"",
",",
"Presence",
":",
"DefaultFilterPart",
"(",
")",
",",
"Ro... | // DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request | [
"DefaultFilter",
"returns",
"the",
"default",
"filter",
"used",
"by",
"the",
"Matrix",
"server",
"if",
"no",
"filter",
"is",
"provided",
"in",
"the",
"request"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/filter.go#L61-L77 | train |
matrix-org/gomatrix | filter.go | DefaultFilterPart | func DefaultFilterPart() FilterPart {
return FilterPart{
NotRooms: nil,
Rooms: nil,
Limit: 20,
NotSenders: nil,
NotTypes: nil,
Senders: nil,
Types: nil,
}
} | go | func DefaultFilterPart() FilterPart {
return FilterPart{
NotRooms: nil,
Rooms: nil,
Limit: 20,
NotSenders: nil,
NotTypes: nil,
Senders: nil,
Types: nil,
}
} | [
"func",
"DefaultFilterPart",
"(",
")",
"FilterPart",
"{",
"return",
"FilterPart",
"{",
"NotRooms",
":",
"nil",
",",
"Rooms",
":",
"nil",
",",
"Limit",
":",
"20",
",",
"NotSenders",
":",
"nil",
",",
"NotTypes",
":",
"nil",
",",
"Senders",
":",
"nil",
",... | // DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request | [
"DefaultFilterPart",
"returns",
"the",
"default",
"filter",
"part",
"used",
"by",
"the",
"Matrix",
"server",
"if",
"no",
"filter",
"is",
"provided",
"in",
"the",
"request"
] | 0c31efc5dc7385fa91705093d77bfc554c2751f9 | https://github.com/matrix-org/gomatrix/blob/0c31efc5dc7385fa91705093d77bfc554c2751f9/filter.go#L80-L90 | train |
go-ozzo/ozzo-validation | error.go | MarshalJSON | func (es Errors) MarshalJSON() ([]byte, error) {
errs := map[string]interface{}{}
for key, err := range es {
if ms, ok := err.(json.Marshaler); ok {
errs[key] = ms
} else {
errs[key] = err.Error()
}
}
return json.Marshal(errs)
} | go | func (es Errors) MarshalJSON() ([]byte, error) {
errs := map[string]interface{}{}
for key, err := range es {
if ms, ok := err.(json.Marshaler); ok {
errs[key] = ms
} else {
errs[key] = err.Error()
}
}
return json.Marshal(errs)
} | [
"func",
"(",
"es",
"Errors",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"errs",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"key",
",",
"err",
":=",
"range",
"es",
"{",
"if",
... | // MarshalJSON converts the Errors into a valid JSON. | [
"MarshalJSON",
"converts",
"the",
"Errors",
"into",
"a",
"valid",
"JSON",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/error.go#L65-L75 | train |
go-ozzo/ozzo-validation | error.go | Filter | func (es Errors) Filter() error {
for key, value := range es {
if value == nil {
delete(es, key)
}
}
if len(es) == 0 {
return nil
}
return es
} | go | func (es Errors) Filter() error {
for key, value := range es {
if value == nil {
delete(es, key)
}
}
if len(es) == 0 {
return nil
}
return es
} | [
"func",
"(",
"es",
"Errors",
")",
"Filter",
"(",
")",
"error",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"es",
"{",
"if",
"value",
"==",
"nil",
"{",
"delete",
"(",
"es",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"es... | // Filter removes all nils from Errors and returns back the updated Errors as an error.
// If the length of Errors becomes 0, it will return nil. | [
"Filter",
"removes",
"all",
"nils",
"from",
"Errors",
"and",
"returns",
"back",
"the",
"updated",
"Errors",
"as",
"an",
"error",
".",
"If",
"the",
"length",
"of",
"Errors",
"becomes",
"0",
"it",
"will",
"return",
"nil",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/error.go#L79-L89 | train |
go-ozzo/ozzo-validation | string.go | NewStringRule | func NewStringRule(validator stringValidator, message string) *StringRule {
return &StringRule{
validate: validator,
message: message,
}
} | go | func NewStringRule(validator stringValidator, message string) *StringRule {
return &StringRule{
validate: validator,
message: message,
}
} | [
"func",
"NewStringRule",
"(",
"validator",
"stringValidator",
",",
"message",
"string",
")",
"*",
"StringRule",
"{",
"return",
"&",
"StringRule",
"{",
"validate",
":",
"validator",
",",
"message",
":",
"message",
",",
"}",
"\n",
"}"
] | // NewStringRule creates a new validation rule using a function that takes a string value and returns a bool.
// The rule returned will use the function to check if a given string or byte slice is valid or not.
// An empty value is considered to be valid. Please use the Required rule to make sure a value is not empty. | [
"NewStringRule",
"creates",
"a",
"new",
"validation",
"rule",
"using",
"a",
"function",
"that",
"takes",
"a",
"string",
"value",
"and",
"returns",
"a",
"bool",
".",
"The",
"rule",
"returned",
"will",
"use",
"the",
"function",
"to",
"check",
"if",
"a",
"giv... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/string.go#L20-L25 | train |
go-ozzo/ozzo-validation | date.go | Error | func (r *DateRule) Error(message string) *DateRule {
r.message = message
return r
} | go | func (r *DateRule) Error(message string) *DateRule {
r.message = message
return r
} | [
"func",
"(",
"r",
"*",
"DateRule",
")",
"Error",
"(",
"message",
"string",
")",
"*",
"DateRule",
"{",
"r",
".",
"message",
"=",
"message",
"\n",
"return",
"r",
"\n",
"}"
] | // Error sets the error message that is used when the value being validated is not a valid date. | [
"Error",
"sets",
"the",
"error",
"message",
"that",
"is",
"used",
"when",
"the",
"value",
"being",
"validated",
"is",
"not",
"a",
"valid",
"date",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/date.go#L39-L42 | train |
go-ozzo/ozzo-validation | date.go | Min | func (r *DateRule) Min(min time.Time) *DateRule {
r.min = min
return r
} | go | func (r *DateRule) Min(min time.Time) *DateRule {
r.min = min
return r
} | [
"func",
"(",
"r",
"*",
"DateRule",
")",
"Min",
"(",
"min",
"time",
".",
"Time",
")",
"*",
"DateRule",
"{",
"r",
".",
"min",
"=",
"min",
"\n",
"return",
"r",
"\n",
"}"
] | // Min sets the minimum date range. A zero value means skipping the minimum range validation. | [
"Min",
"sets",
"the",
"minimum",
"date",
"range",
".",
"A",
"zero",
"value",
"means",
"skipping",
"the",
"minimum",
"range",
"validation",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/date.go#L51-L54 | train |
go-ozzo/ozzo-validation | date.go | Max | func (r *DateRule) Max(max time.Time) *DateRule {
r.max = max
return r
} | go | func (r *DateRule) Max(max time.Time) *DateRule {
r.max = max
return r
} | [
"func",
"(",
"r",
"*",
"DateRule",
")",
"Max",
"(",
"max",
"time",
".",
"Time",
")",
"*",
"DateRule",
"{",
"r",
".",
"max",
"=",
"max",
"\n",
"return",
"r",
"\n",
"}"
] | // Max sets the maximum date range. A zero value means skipping the maximum range validation. | [
"Max",
"sets",
"the",
"maximum",
"date",
"range",
".",
"A",
"zero",
"value",
"means",
"skipping",
"the",
"maximum",
"range",
"validation",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/date.go#L57-L60 | train |
go-ozzo/ozzo-validation | date.go | Validate | func (r *DateRule) Validate(value interface{}) error {
value, isNil := Indirect(value)
if isNil || IsEmpty(value) {
return nil
}
str, err := EnsureString(value)
if err != nil {
return err
}
date, err := time.Parse(r.layout, str)
if err != nil {
return errors.New(r.message)
}
if !r.min.IsZero() && r.m... | go | func (r *DateRule) Validate(value interface{}) error {
value, isNil := Indirect(value)
if isNil || IsEmpty(value) {
return nil
}
str, err := EnsureString(value)
if err != nil {
return err
}
date, err := time.Parse(r.layout, str)
if err != nil {
return errors.New(r.message)
}
if !r.min.IsZero() && r.m... | [
"func",
"(",
"r",
"*",
"DateRule",
")",
"Validate",
"(",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"value",
",",
"isNil",
":=",
"Indirect",
"(",
"value",
")",
"\n",
"if",
"isNil",
"||",
"IsEmpty",
"(",
"value",
")",
"{",
"return",
"nil",
"... | // Validate checks if the given value is a valid date. | [
"Validate",
"checks",
"if",
"the",
"given",
"value",
"is",
"a",
"valid",
"date",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/date.go#L63-L84 | train |
go-ozzo/ozzo-validation | util.go | EnsureString | func EnsureString(value interface{}) (string, error) {
v := reflect.ValueOf(value)
if v.Kind() == reflect.String {
return v.String(), nil
}
if v.Type() == bytesType {
return string(v.Interface().([]byte)), nil
}
return "", errors.New("must be either a string or byte slice")
} | go | func EnsureString(value interface{}) (string, error) {
v := reflect.ValueOf(value)
if v.Kind() == reflect.String {
return v.String(), nil
}
if v.Type() == bytesType {
return string(v.Interface().([]byte)), nil
}
return "", errors.New("must be either a string or byte slice")
} | [
"func",
"EnsureString",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"String",
"{",
"return",... | // EnsureString ensures the given value is a string.
// If the value is a byte slice, it will be typecast into a string.
// An error is returned otherwise. | [
"EnsureString",
"ensures",
"the",
"given",
"value",
"is",
"a",
"string",
".",
"If",
"the",
"value",
"is",
"a",
"byte",
"slice",
"it",
"will",
"be",
"typecast",
"into",
"a",
"string",
".",
"An",
"error",
"is",
"returned",
"otherwise",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L23-L32 | train |
go-ozzo/ozzo-validation | util.go | StringOrBytes | func StringOrBytes(value interface{}) (isString bool, str string, isBytes bool, bs []byte) {
v := reflect.ValueOf(value)
if v.Kind() == reflect.String {
str = v.String()
isString = true
} else if v.Kind() == reflect.Slice && v.Type() == bytesType {
bs = v.Interface().([]byte)
isBytes = true
}
return
} | go | func StringOrBytes(value interface{}) (isString bool, str string, isBytes bool, bs []byte) {
v := reflect.ValueOf(value)
if v.Kind() == reflect.String {
str = v.String()
isString = true
} else if v.Kind() == reflect.Slice && v.Type() == bytesType {
bs = v.Interface().([]byte)
isBytes = true
}
return
} | [
"func",
"StringOrBytes",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"isString",
"bool",
",",
"str",
"string",
",",
"isBytes",
"bool",
",",
"bs",
"[",
"]",
"byte",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"if",
"v... | // StringOrBytes typecasts a value into a string or byte slice.
// Boolean flags are returned to indicate if the typecasting succeeds or not. | [
"StringOrBytes",
"typecasts",
"a",
"value",
"into",
"a",
"string",
"or",
"byte",
"slice",
".",
"Boolean",
"flags",
"are",
"returned",
"to",
"indicate",
"if",
"the",
"typecasting",
"succeeds",
"or",
"not",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L36-L46 | train |
go-ozzo/ozzo-validation | util.go | LengthOfValue | func LengthOfValue(value interface{}) (int, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.String, reflect.Slice, reflect.Map, reflect.Array:
return v.Len(), nil
}
return 0, fmt.Errorf("cannot get the length of %v", v.Kind())
} | go | func LengthOfValue(value interface{}) (int, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.String, reflect.Slice, reflect.Map, reflect.Array:
return v.Len(), nil
}
return 0, fmt.Errorf("cannot get the length of %v", v.Kind())
} | [
"func",
"LengthOfValue",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"String",
",",
... | // LengthOfValue returns the length of a value that is a string, slice, map, or array.
// An error is returned for all other types. | [
"LengthOfValue",
"returns",
"the",
"length",
"of",
"a",
"value",
"that",
"is",
"a",
"string",
"slice",
"map",
"or",
"array",
".",
"An",
"error",
"is",
"returned",
"for",
"all",
"other",
"types",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L50-L57 | train |
go-ozzo/ozzo-validation | util.go | ToInt | func ToInt(value interface{}) (int64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int(), nil
}
return 0, fmt.Errorf("cannot convert %v to int64", v.Kind())
} | go | func ToInt(value interface{}) (int64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int(), nil
}
return 0, fmt.Errorf("cannot convert %v to int64", v.Kind())
} | [
"func",
"ToInt",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"int64",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Int",
",",
"reflec... | // ToInt converts the given value to an int64.
// An error is returned for all incompatible types. | [
"ToInt",
"converts",
"the",
"given",
"value",
"to",
"an",
"int64",
".",
"An",
"error",
"is",
"returned",
"for",
"all",
"incompatible",
"types",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L61-L68 | train |
go-ozzo/ozzo-validation | util.go | ToUint | func ToUint(value interface{}) (uint64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return v.Uint(), nil
}
return 0, fmt.Errorf("cannot convert %v to uint64", v.Kind())
} | go | func ToUint(value interface{}) (uint64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return v.Uint(), nil
}
return 0, fmt.Errorf("cannot convert %v to uint64", v.Kind())
} | [
"func",
"ToUint",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Uint",
",",
"ref... | // ToUint converts the given value to an uint64.
// An error is returned for all incompatible types. | [
"ToUint",
"converts",
"the",
"given",
"value",
"to",
"an",
"uint64",
".",
"An",
"error",
"is",
"returned",
"for",
"all",
"incompatible",
"types",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L72-L79 | train |
go-ozzo/ozzo-validation | util.go | ToFloat | func ToFloat(value interface{}) (float64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Float32, reflect.Float64:
return v.Float(), nil
}
return 0, fmt.Errorf("cannot convert %v to float64", v.Kind())
} | go | func ToFloat(value interface{}) (float64, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
case reflect.Float32, reflect.Float64:
return v.Float(), nil
}
return 0, fmt.Errorf("cannot convert %v to float64", v.Kind())
} | [
"func",
"ToFloat",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"float64",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Float32",
",",
... | // ToFloat converts the given value to a float64.
// An error is returned for all incompatible types. | [
"ToFloat",
"converts",
"the",
"given",
"value",
"to",
"a",
"float64",
".",
"An",
"error",
"is",
"returned",
"for",
"all",
"incompatible",
"types",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/util.go#L83-L90 | train |
go-ozzo/ozzo-validation | validation.go | validateMap | func validateMap(rv reflect.Value) error {
errs := Errors{}
for _, key := range rv.MapKeys() {
if mv := rv.MapIndex(key).Interface(); mv != nil {
if err := mv.(Validatable).Validate(); err != nil {
errs[fmt.Sprintf("%v", key.Interface())] = err
}
}
}
if len(errs) > 0 {
return errs
}
return nil
} | go | func validateMap(rv reflect.Value) error {
errs := Errors{}
for _, key := range rv.MapKeys() {
if mv := rv.MapIndex(key).Interface(); mv != nil {
if err := mv.(Validatable).Validate(); err != nil {
errs[fmt.Sprintf("%v", key.Interface())] = err
}
}
}
if len(errs) > 0 {
return errs
}
return nil
} | [
"func",
"validateMap",
"(",
"rv",
"reflect",
".",
"Value",
")",
"error",
"{",
"errs",
":=",
"Errors",
"{",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"rv",
".",
"MapKeys",
"(",
")",
"{",
"if",
"mv",
":=",
"rv",
".",
"MapIndex",
"(",
"key",... | // validateMap validates a map of validatable elements | [
"validateMap",
"validates",
"a",
"map",
"of",
"validatable",
"elements"
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/validation.go#L84-L97 | train |
go-ozzo/ozzo-validation | minmax.go | Min | func Min(min interface{}) *ThresholdRule {
return &ThresholdRule{
threshold: min,
operator: greaterEqualThan,
message: fmt.Sprintf("must be no less than %v", min),
}
} | go | func Min(min interface{}) *ThresholdRule {
return &ThresholdRule{
threshold: min,
operator: greaterEqualThan,
message: fmt.Sprintf("must be no less than %v", min),
}
} | [
"func",
"Min",
"(",
"min",
"interface",
"{",
"}",
")",
"*",
"ThresholdRule",
"{",
"return",
"&",
"ThresholdRule",
"{",
"threshold",
":",
"min",
",",
"operator",
":",
"greaterEqualThan",
",",
"message",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
... | // Min is a validation rule that checks if a value is greater or equal than the specified value.
// By calling Exclusive, the rule will check if the value is strictly greater than the specified value.
// Note that the value being checked and the threshold value must be of the same type.
// Only int, uint, float and tim... | [
"Min",
"is",
"a",
"validation",
"rule",
"that",
"checks",
"if",
"a",
"value",
"is",
"greater",
"or",
"equal",
"than",
"the",
"specified",
"value",
".",
"By",
"calling",
"Exclusive",
"the",
"rule",
"will",
"check",
"if",
"the",
"value",
"is",
"strictly",
... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/minmax.go#L32-L38 | train |
go-ozzo/ozzo-validation | minmax.go | Max | func Max(max interface{}) *ThresholdRule {
return &ThresholdRule{
threshold: max,
operator: lessEqualThan,
message: fmt.Sprintf("must be no greater than %v", max),
}
} | go | func Max(max interface{}) *ThresholdRule {
return &ThresholdRule{
threshold: max,
operator: lessEqualThan,
message: fmt.Sprintf("must be no greater than %v", max),
}
} | [
"func",
"Max",
"(",
"max",
"interface",
"{",
"}",
")",
"*",
"ThresholdRule",
"{",
"return",
"&",
"ThresholdRule",
"{",
"threshold",
":",
"max",
",",
"operator",
":",
"lessEqualThan",
",",
"message",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ma... | // Max is a validation rule that checks if a value is less or equal than the specified value.
// By calling Exclusive, the rule will check if the value is strictly less than the specified value.
// Note that the value being checked and the threshold value must be of the same type.
// Only int, uint, float and time.Time... | [
"Max",
"is",
"a",
"validation",
"rule",
"that",
"checks",
"if",
"a",
"value",
"is",
"less",
"or",
"equal",
"than",
"the",
"specified",
"value",
".",
"By",
"calling",
"Exclusive",
"the",
"rule",
"will",
"check",
"if",
"the",
"value",
"is",
"strictly",
"le... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/minmax.go#L45-L51 | train |
go-ozzo/ozzo-validation | minmax.go | Exclusive | func (r *ThresholdRule) Exclusive() *ThresholdRule {
if r.operator == greaterEqualThan {
r.operator = greaterThan
r.message = fmt.Sprintf("must be greater than %v", r.threshold)
} else if r.operator == lessEqualThan {
r.operator = lessThan
r.message = fmt.Sprintf("must be less than %v", r.threshold)
}
retur... | go | func (r *ThresholdRule) Exclusive() *ThresholdRule {
if r.operator == greaterEqualThan {
r.operator = greaterThan
r.message = fmt.Sprintf("must be greater than %v", r.threshold)
} else if r.operator == lessEqualThan {
r.operator = lessThan
r.message = fmt.Sprintf("must be less than %v", r.threshold)
}
retur... | [
"func",
"(",
"r",
"*",
"ThresholdRule",
")",
"Exclusive",
"(",
")",
"*",
"ThresholdRule",
"{",
"if",
"r",
".",
"operator",
"==",
"greaterEqualThan",
"{",
"r",
".",
"operator",
"=",
"greaterThan",
"\n",
"r",
".",
"message",
"=",
"fmt",
".",
"Sprintf",
"... | // Exclusive sets the comparison to exclude the boundary value. | [
"Exclusive",
"sets",
"the",
"comparison",
"to",
"exclude",
"the",
"boundary",
"value",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/minmax.go#L54-L63 | train |
go-ozzo/ozzo-validation | length.go | Length | func Length(min, max int) *LengthRule {
message := "the value must be empty"
if min == 0 && max > 0 {
message = fmt.Sprintf("the length must be no more than %v", max)
} else if min > 0 && max == 0 {
message = fmt.Sprintf("the length must be no less than %v", min)
} else if min > 0 && max > 0 {
if min == max {... | go | func Length(min, max int) *LengthRule {
message := "the value must be empty"
if min == 0 && max > 0 {
message = fmt.Sprintf("the length must be no more than %v", max)
} else if min > 0 && max == 0 {
message = fmt.Sprintf("the length must be no less than %v", min)
} else if min > 0 && max > 0 {
if min == max {... | [
"func",
"Length",
"(",
"min",
",",
"max",
"int",
")",
"*",
"LengthRule",
"{",
"message",
":=",
"\"",
"\"",
"\n",
"if",
"min",
"==",
"0",
"&&",
"max",
">",
"0",
"{",
"message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"max",
")",
"\n",
... | // Length returns a validation rule that checks if a value's length is within the specified range.
// If max is 0, it means there is no upper bound for the length.
// This rule should only be used for validating strings, slices, maps, and arrays.
// An empty value is considered valid. Use the Required rule to make sure... | [
"Length",
"returns",
"a",
"validation",
"rule",
"that",
"checks",
"if",
"a",
"value",
"s",
"length",
"is",
"within",
"the",
"specified",
"range",
".",
"If",
"max",
"is",
"0",
"it",
"means",
"there",
"is",
"no",
"upper",
"bound",
"for",
"the",
"length",
... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/length.go#L17-L35 | train |
go-ozzo/ozzo-validation | length.go | RuneLength | func RuneLength(min, max int) *LengthRule {
r := Length(min, max)
r.rune = true
return r
} | go | func RuneLength(min, max int) *LengthRule {
r := Length(min, max)
r.rune = true
return r
} | [
"func",
"RuneLength",
"(",
"min",
",",
"max",
"int",
")",
"*",
"LengthRule",
"{",
"r",
":=",
"Length",
"(",
"min",
",",
"max",
")",
"\n",
"r",
".",
"rune",
"=",
"true",
"\n",
"return",
"r",
"\n",
"}"
] | // RuneLength returns a validation rule that checks if a string's rune length is within the specified range.
// If max is 0, it means there is no upper bound for the length.
// This rule should only be used for validating strings, slices, maps, and arrays.
// An empty value is considered valid. Use the Required rule to... | [
"RuneLength",
"returns",
"a",
"validation",
"rule",
"that",
"checks",
"if",
"a",
"string",
"s",
"rune",
"length",
"is",
"within",
"the",
"specified",
"range",
".",
"If",
"max",
"is",
"0",
"it",
"means",
"there",
"is",
"no",
"upper",
"bound",
"for",
"the"... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/length.go#L42-L46 | train |
go-ozzo/ozzo-validation | struct.go | Field | func Field(fieldPtr interface{}, rules ...Rule) *FieldRules {
return &FieldRules{
fieldPtr: fieldPtr,
rules: rules,
}
} | go | func Field(fieldPtr interface{}, rules ...Rule) *FieldRules {
return &FieldRules{
fieldPtr: fieldPtr,
rules: rules,
}
} | [
"func",
"Field",
"(",
"fieldPtr",
"interface",
"{",
"}",
",",
"rules",
"...",
"Rule",
")",
"*",
"FieldRules",
"{",
"return",
"&",
"FieldRules",
"{",
"fieldPtr",
":",
"fieldPtr",
",",
"rules",
":",
"rules",
",",
"}",
"\n",
"}"
] | // Field specifies a struct field and the corresponding validation rules.
// The struct field must be specified as a pointer to it. | [
"Field",
"specifies",
"a",
"struct",
"field",
"and",
"the",
"corresponding",
"validation",
"rules",
".",
"The",
"struct",
"field",
"must",
"be",
"specified",
"as",
"a",
"pointer",
"to",
"it",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/struct.go#L109-L114 | train |
go-ozzo/ozzo-validation | struct.go | findStructField | func findStructField(structValue reflect.Value, fieldValue reflect.Value) *reflect.StructField {
ptr := fieldValue.Pointer()
for i := structValue.NumField() - 1; i >= 0; i-- {
sf := structValue.Type().Field(i)
if ptr == structValue.Field(i).UnsafeAddr() {
// do additional type comparison because it's possible ... | go | func findStructField(structValue reflect.Value, fieldValue reflect.Value) *reflect.StructField {
ptr := fieldValue.Pointer()
for i := structValue.NumField() - 1; i >= 0; i-- {
sf := structValue.Type().Field(i)
if ptr == structValue.Field(i).UnsafeAddr() {
// do additional type comparison because it's possible ... | [
"func",
"findStructField",
"(",
"structValue",
"reflect",
".",
"Value",
",",
"fieldValue",
"reflect",
".",
"Value",
")",
"*",
"reflect",
".",
"StructField",
"{",
"ptr",
":=",
"fieldValue",
".",
"Pointer",
"(",
")",
"\n",
"for",
"i",
":=",
"structValue",
".... | // findStructField looks for a field in the given struct.
// The field being looked for should be a pointer to the actual struct field.
// If found, the field info will be returned. Otherwise, nil will be returned. | [
"findStructField",
"looks",
"for",
"a",
"field",
"in",
"the",
"given",
"struct",
".",
"The",
"field",
"being",
"looked",
"for",
"should",
"be",
"a",
"pointer",
"to",
"the",
"actual",
"struct",
"field",
".",
"If",
"found",
"the",
"field",
"info",
"will",
... | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/struct.go#L119-L144 | train |
go-ozzo/ozzo-validation | struct.go | getErrorFieldName | func getErrorFieldName(f *reflect.StructField) string {
if tag := f.Tag.Get(ErrorTag); tag != "" {
if cps := strings.SplitN(tag, ",", 2); cps[0] != "" {
return cps[0]
}
}
return f.Name
} | go | func getErrorFieldName(f *reflect.StructField) string {
if tag := f.Tag.Get(ErrorTag); tag != "" {
if cps := strings.SplitN(tag, ",", 2); cps[0] != "" {
return cps[0]
}
}
return f.Name
} | [
"func",
"getErrorFieldName",
"(",
"f",
"*",
"reflect",
".",
"StructField",
")",
"string",
"{",
"if",
"tag",
":=",
"f",
".",
"Tag",
".",
"Get",
"(",
"ErrorTag",
")",
";",
"tag",
"!=",
"\"",
"\"",
"{",
"if",
"cps",
":=",
"strings",
".",
"SplitN",
"("... | // getErrorFieldName returns the name that should be used to represent the validation error of a struct field. | [
"getErrorFieldName",
"returns",
"the",
"name",
"that",
"should",
"be",
"used",
"to",
"represent",
"the",
"validation",
"error",
"of",
"a",
"struct",
"field",
"."
] | 2f76ea62300c36e72bd56c804484cb6db53b69a5 | https://github.com/go-ozzo/ozzo-validation/blob/2f76ea62300c36e72bd56c804484cb6db53b69a5/struct.go#L147-L154 | train |
containers/storage | drivers/btrfs/btrfs.go | Metadata | func (d *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
} | go | func (d *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Metadata",
"(",
"id",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // Metadata returns empty metadata for this driver. | [
"Metadata",
"returns",
"empty",
"metadata",
"for",
"this",
"driver",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/btrfs/btrfs.go#L153-L155 | train |
containers/storage | drivers/btrfs/btrfs.go | Remove | func (d *Driver) Remove(id string) error {
dir := d.subvolumesDirID(id)
if _, err := os.Stat(dir); err != nil {
return err
}
quotasDir := d.quotasDirID(id)
if _, err := os.Stat(quotasDir); err == nil {
if err := os.Remove(quotasDir); err != nil {
return err
}
} else if !os.IsNotExist(err) {
return err
... | go | func (d *Driver) Remove(id string) error {
dir := d.subvolumesDirID(id)
if _, err := os.Stat(dir); err != nil {
return err
}
quotasDir := d.quotasDirID(id)
if _, err := os.Stat(quotasDir); err == nil {
if err := os.Remove(quotasDir); err != nil {
return err
}
} else if !os.IsNotExist(err) {
return err
... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Remove",
"(",
"id",
"string",
")",
"error",
"{",
"dir",
":=",
"d",
".",
"subvolumesDirID",
"(",
"id",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
... | // Remove the filesystem with given id. | [
"Remove",
"the",
"filesystem",
"with",
"given",
"id",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/btrfs/btrfs.go#L612-L639 | train |
containers/storage | drivers/overlay/overlay.go | Metadata | func (d *Driver) Metadata(id string) (map[string]string, error) {
dir := d.dir(id)
if _, err := os.Stat(dir); err != nil {
return nil, err
}
metadata := map[string]string{
"WorkDir": path.Join(dir, "work"),
"MergedDir": path.Join(dir, "merged"),
"UpperDir": path.Join(dir, "diff"),
}
lowerDirs, err :=... | go | func (d *Driver) Metadata(id string) (map[string]string, error) {
dir := d.dir(id)
if _, err := os.Stat(dir); err != nil {
return nil, err
}
metadata := map[string]string{
"WorkDir": path.Join(dir, "work"),
"MergedDir": path.Join(dir, "merged"),
"UpperDir": path.Join(dir, "diff"),
}
lowerDirs, err :=... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Metadata",
"(",
"id",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"dir",
":=",
"d",
".",
"dir",
"(",
"id",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
... | // Metadata returns meta data about the overlay driver such as
// LowerDir, UpperDir, WorkDir and MergeDir used to store data. | [
"Metadata",
"returns",
"meta",
"data",
"about",
"the",
"overlay",
"driver",
"such",
"as",
"LowerDir",
"UpperDir",
"WorkDir",
"and",
"MergeDir",
"used",
"to",
"store",
"data",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/overlay/overlay.go#L397-L418 | train |
containers/storage | drivers/overlay/overlay.go | recreateSymlinks | func (d *Driver) recreateSymlinks() error {
// List all the directories under the home directory
dirs, err := ioutil.ReadDir(d.home)
if err != nil {
return fmt.Errorf("error reading driver home directory %q: %v", d.home, err)
}
// This makes the link directory if it doesn't exist
rootUID, rootGID, err := idtool... | go | func (d *Driver) recreateSymlinks() error {
// List all the directories under the home directory
dirs, err := ioutil.ReadDir(d.home)
if err != nil {
return fmt.Errorf("error reading driver home directory %q: %v", d.home, err)
}
// This makes the link directory if it doesn't exist
rootUID, rootGID, err := idtool... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"recreateSymlinks",
"(",
")",
"error",
"{",
"// List all the directories under the home directory",
"dirs",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"d",
".",
"home",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // recreateSymlinks goes through the driver's home directory and checks if the diff directory
// under each layer has a symlink created for it under the linkDir. If the symlink does not
// exist, it creates them | [
"recreateSymlinks",
"goes",
"through",
"the",
"driver",
"s",
"home",
"directory",
"and",
"checks",
"if",
"the",
"diff",
"directory",
"under",
"each",
"layer",
"has",
"a",
"symlink",
"created",
"for",
"it",
"under",
"the",
"linkDir",
".",
"If",
"the",
"symlin... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/overlay/overlay.go#L699-L736 | train |
containers/storage | drivers/overlay/overlay.go | UpdateLayerIDMap | func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
var err error
dir := d.dir(id)
diffDir := filepath.Join(dir, "diff")
rootUID, rootGID := 0, 0
if toHost != nil {
rootUID, rootGID, err = idtools.GetRootUIDGID(toHost.UIDs(), toHost.GIDs())
if err !... | go | func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMappings, mountLabel string) error {
var err error
dir := d.dir(id)
diffDir := filepath.Join(dir, "diff")
rootUID, rootGID := 0, 0
if toHost != nil {
rootUID, rootGID, err = idtools.GetRootUIDGID(toHost.UIDs(), toHost.GIDs())
if err !... | [
"func",
"(",
"d",
"*",
"Driver",
")",
"UpdateLayerIDMap",
"(",
"id",
"string",
",",
"toContainer",
",",
"toHost",
"*",
"idtools",
".",
"IDMappings",
",",
"mountLabel",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"dir",
":=",
"d",
".",
"di... | // UpdateLayerIDMap updates ID mappings in a from matching the ones specified
// by toContainer to those specified by toHost. | [
"UpdateLayerIDMap",
"updates",
"ID",
"mappings",
"in",
"a",
"from",
"matching",
"the",
"ones",
"specified",
"by",
"toContainer",
"to",
"those",
"specified",
"by",
"toHost",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/overlay/overlay.go#L1069-L1122 | train |
containers/storage | drivers/aufs/aufs.go | Metadata | func (a *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
} | go | func (a *Driver) Metadata(id string) (map[string]string, error) {
return nil, nil
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Metadata",
"(",
"id",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // Metadata not implemented | [
"Metadata",
"not",
"implemented"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/aufs/aufs.go#L238-L240 | train |
containers/storage | drivers/aufs/aufs.go | CreateFromTemplate | func (a *Driver) CreateFromTemplate(id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *graphdriver.CreateOpts, readWrite bool) error {
return graphdriver.NaiveCreateFromTemplate(a, id, template, templateIDMappings, parent, parentIDMappings, opts, rea... | go | func (a *Driver) CreateFromTemplate(id, template string, templateIDMappings *idtools.IDMappings, parent string, parentIDMappings *idtools.IDMappings, opts *graphdriver.CreateOpts, readWrite bool) error {
return graphdriver.NaiveCreateFromTemplate(a, id, template, templateIDMappings, parent, parentIDMappings, opts, rea... | [
"func",
"(",
"a",
"*",
"Driver",
")",
"CreateFromTemplate",
"(",
"id",
",",
"template",
"string",
",",
"templateIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"parent",
"string",
",",
"parentIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"opts",
... | // CreateFromTemplate creates a layer with the same contents and parent as another layer. | [
"CreateFromTemplate",
"creates",
"a",
"layer",
"with",
"the",
"same",
"contents",
"and",
"parent",
"as",
"another",
"layer",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/aufs/aufs.go#L257-L259 | train |
containers/storage | drivers/aufs/aufs.go | Put | func (a *Driver) Put(id string) error {
a.locker.Lock(id)
defer a.locker.Unlock(id)
a.pathCacheLock.Lock()
m, exists := a.pathCache[id]
if !exists {
m = a.getMountpoint(id)
a.pathCache[id] = m
}
a.pathCacheLock.Unlock()
if count := a.ctr.Decrement(m); count > 0 {
return nil
}
err := a.unmount(m)
if er... | go | func (a *Driver) Put(id string) error {
a.locker.Lock(id)
defer a.locker.Unlock(id)
a.pathCacheLock.Lock()
m, exists := a.pathCache[id]
if !exists {
m = a.getMountpoint(id)
a.pathCache[id] = m
}
a.pathCacheLock.Unlock()
if count := a.ctr.Decrement(m); count > 0 {
return nil
}
err := a.unmount(m)
if er... | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Put",
"(",
"id",
"string",
")",
"error",
"{",
"a",
".",
"locker",
".",
"Lock",
"(",
"id",
")",
"\n",
"defer",
"a",
".",
"locker",
".",
"Unlock",
"(",
"id",
")",
"\n",
"a",
".",
"pathCacheLock",
".",
"Lock"... | // Put unmounts and updates list of active mounts. | [
"Put",
"unmounts",
"and",
"updates",
"list",
"of",
"active",
"mounts",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/drivers/aufs/aufs.go#L461-L480 | train |
containers/storage | pkg/chrootarchive/archive.go | NewArchiverWithChown | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *archive.Archiver {
archiver := archive.NewArchiverWithChown(tarIDMappings, chownOpts, untarIDMappings)
archiver.Untar = Untar
return archiver
} | go | func NewArchiverWithChown(tarIDMappings *idtools.IDMappings, chownOpts *idtools.IDPair, untarIDMappings *idtools.IDMappings) *archive.Archiver {
archiver := archive.NewArchiverWithChown(tarIDMappings, chownOpts, untarIDMappings)
archiver.Untar = Untar
return archiver
} | [
"func",
"NewArchiverWithChown",
"(",
"tarIDMappings",
"*",
"idtools",
".",
"IDMappings",
",",
"chownOpts",
"*",
"idtools",
".",
"IDPair",
",",
"untarIDMappings",
"*",
"idtools",
".",
"IDMappings",
")",
"*",
"archive",
".",
"Archiver",
"{",
"archiver",
":=",
"a... | // NewArchiverWithChown returns a new Archiver which uses chrootarchive.Untar and the provided ID mapping configuration on both ends | [
"NewArchiverWithChown",
"returns",
"a",
"new",
"Archiver",
"which",
"uses",
"chrootarchive",
".",
"Untar",
"and",
"the",
"provided",
"ID",
"mapping",
"configuration",
"on",
"both",
"ends"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/chrootarchive/archive.go#L26-L30 | train |
containers/storage | pkg/chrootarchive/archive.go | CopyFileWithTarAndChown | func CopyFileWithTarAndChown(chownOpts *idtools.IDPair, hasher io.Writer, uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(src, dest string) error {
untarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
archiver := NewArchiverWithChown(nil, chownOpts, untarMappings)
if hasher != nil {
originalUntar :=... | go | func CopyFileWithTarAndChown(chownOpts *idtools.IDPair, hasher io.Writer, uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(src, dest string) error {
untarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
archiver := NewArchiverWithChown(nil, chownOpts, untarMappings)
if hasher != nil {
originalUntar :=... | [
"func",
"CopyFileWithTarAndChown",
"(",
"chownOpts",
"*",
"idtools",
".",
"IDPair",
",",
"hasher",
"io",
".",
"Writer",
",",
"uidmap",
"[",
"]",
"idtools",
".",
"IDMap",
",",
"gidmap",
"[",
"]",
"idtools",
".",
"IDMap",
")",
"func",
"(",
"src",
",",
"d... | // CopyFileWithTarAndChown returns a function which copies a single file from outside
// of any container into our working container, mapping permissions using the
// container's ID maps, possibly overridden using the passed-in chownOpts | [
"CopyFileWithTarAndChown",
"returns",
"a",
"function",
"which",
"copies",
"a",
"single",
"file",
"from",
"outside",
"of",
"any",
"container",
"into",
"our",
"working",
"container",
"mapping",
"permissions",
"using",
"the",
"container",
"s",
"ID",
"maps",
"possibly... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/chrootarchive/archive.go#L86-L123 | train |
containers/storage | pkg/chrootarchive/archive.go | CopyWithTarAndChown | func CopyWithTarAndChown(chownOpts *idtools.IDPair, hasher io.Writer, uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(src, dest string) error {
untarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
archiver := NewArchiverWithChown(nil, chownOpts, untarMappings)
if hasher != nil {
originalUntar := arc... | go | func CopyWithTarAndChown(chownOpts *idtools.IDPair, hasher io.Writer, uidmap []idtools.IDMap, gidmap []idtools.IDMap) func(src, dest string) error {
untarMappings := idtools.NewIDMappingsFromMaps(uidmap, gidmap)
archiver := NewArchiverWithChown(nil, chownOpts, untarMappings)
if hasher != nil {
originalUntar := arc... | [
"func",
"CopyWithTarAndChown",
"(",
"chownOpts",
"*",
"idtools",
".",
"IDPair",
",",
"hasher",
"io",
".",
"Writer",
",",
"uidmap",
"[",
"]",
"idtools",
".",
"IDMap",
",",
"gidmap",
"[",
"]",
"idtools",
".",
"IDMap",
")",
"func",
"(",
"src",
",",
"dest"... | // CopyWithTarAndChown returns a function which copies a directory tree from outside of
// any container into our working container, mapping permissions using the
// container's ID maps, possibly overridden using the passed-in chownOpts | [
"CopyWithTarAndChown",
"returns",
"a",
"function",
"which",
"copies",
"a",
"directory",
"tree",
"from",
"outside",
"of",
"any",
"container",
"into",
"our",
"working",
"container",
"mapping",
"permissions",
"using",
"the",
"container",
"s",
"ID",
"maps",
"possibly"... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/chrootarchive/archive.go#L128-L138 | train |
containers/storage | utils.go | ParseIDMapping | func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap string) (*IDMappingOptions, error) {
options := IDMappingOptions{
HostUIDMapping: true,
HostGIDMapping: true,
}
if subGIDMap == "" && subUIDMap != "" {
subGIDMap = subUIDMap
}
if subUIDMap == "" && subGIDMap != "" {
subUIDMap = sub... | go | func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap string) (*IDMappingOptions, error) {
options := IDMappingOptions{
HostUIDMapping: true,
HostGIDMapping: true,
}
if subGIDMap == "" && subUIDMap != "" {
subGIDMap = subUIDMap
}
if subUIDMap == "" && subGIDMap != "" {
subUIDMap = sub... | [
"func",
"ParseIDMapping",
"(",
"UIDMapSlice",
",",
"GIDMapSlice",
"[",
"]",
"string",
",",
"subUIDMap",
",",
"subGIDMap",
"string",
")",
"(",
"*",
"IDMappingOptions",
",",
"error",
")",
"{",
"options",
":=",
"IDMappingOptions",
"{",
"HostUIDMapping",
":",
"tru... | // ParseIDMapping takes idmappings and subuid and subgid maps and returns a storage mapping | [
"ParseIDMapping",
"takes",
"idmappings",
"and",
"subuid",
"and",
"subgid",
"maps",
"and",
"returns",
"a",
"storage",
"mapping"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/utils.go#L20-L69 | train |
containers/storage | utils.go | GetRootlessRuntimeDir | func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir == "" {
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid)
st, err := system.Stat(tmpDir)
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
... | go | func GetRootlessRuntimeDir(rootlessUid int) (string, error) {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir == "" {
tmpDir := fmt.Sprintf("/run/user/%d", rootlessUid)
st, err := system.Stat(tmpDir)
if err == nil && int(st.UID()) == os.Getuid() && st.Mode()&0700 == 0700 && st.Mode()&0066 == 0000 {
... | [
"func",
"GetRootlessRuntimeDir",
"(",
"rootlessUid",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"runtimeDir",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"runtimeDir",
"==",
"\"",
"\"",
"{",
"tmpDir",
":=",
"fmt",
".",
"Sprintf... | // GetRootlessRuntimeDir returns the runtime directory when running as non root | [
"GetRootlessRuntimeDir",
"returns",
"the",
"runtime",
"directory",
"when",
"running",
"as",
"non",
"root"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/utils.go#L72-L96 | train |
containers/storage | utils.go | getRootlessDirInfo | func getRootlessDirInfo(rootlessUid int) (string, string, error) {
rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUid)
if err != nil {
return "", "", err
}
dataDir := os.Getenv("XDG_DATA_HOME")
if dataDir == "" {
home, err := homeDir()
if err != nil {
return "", "", errors.Wrapf(err, "neither XDG_... | go | func getRootlessDirInfo(rootlessUid int) (string, string, error) {
rootlessRuntime, err := GetRootlessRuntimeDir(rootlessUid)
if err != nil {
return "", "", err
}
dataDir := os.Getenv("XDG_DATA_HOME")
if dataDir == "" {
home, err := homeDir()
if err != nil {
return "", "", errors.Wrapf(err, "neither XDG_... | [
"func",
"getRootlessDirInfo",
"(",
"rootlessUid",
"int",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"rootlessRuntime",
",",
"err",
":=",
"GetRootlessRuntimeDir",
"(",
"rootlessUid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
... | // getRootlessDirInfo returns the parent path of where the storage for containers and
// volumes will be in rootless mode | [
"getRootlessDirInfo",
"returns",
"the",
"parent",
"path",
"of",
"where",
"the",
"storage",
"for",
"containers",
"and",
"volumes",
"will",
"be",
"in",
"rootless",
"mode"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/utils.go#L100-L121 | train |
containers/storage | utils.go | getRootlessStorageOpts | func getRootlessStorageOpts(rootlessUid int) (StoreOptions, error) {
var opts StoreOptions
dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUid)
if err != nil {
return opts, err
}
opts.RunRoot = rootlessRuntime
opts.GraphRoot = filepath.Join(dataDir, "containers", "storage")
if path, err := exec.Lo... | go | func getRootlessStorageOpts(rootlessUid int) (StoreOptions, error) {
var opts StoreOptions
dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUid)
if err != nil {
return opts, err
}
opts.RunRoot = rootlessRuntime
opts.GraphRoot = filepath.Join(dataDir, "containers", "storage")
if path, err := exec.Lo... | [
"func",
"getRootlessStorageOpts",
"(",
"rootlessUid",
"int",
")",
"(",
"StoreOptions",
",",
"error",
")",
"{",
"var",
"opts",
"StoreOptions",
"\n\n",
"dataDir",
",",
"rootlessRuntime",
",",
"err",
":=",
"getRootlessDirInfo",
"(",
"rootlessUid",
")",
"\n",
"if",
... | // getRootlessStorageOpts returns the storage opts for containers running as non root | [
"getRootlessStorageOpts",
"returns",
"the",
"storage",
"opts",
"for",
"containers",
"running",
"as",
"non",
"root"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/utils.go#L124-L140 | train |
containers/storage | utils.go | DefaultStoreOptions | func DefaultStoreOptions(rootless bool, rootlessUid int) (StoreOptions, error) {
var (
defaultRootlessRunRoot string
defaultRootlessGraphRoot string
err error
)
storageOpts := defaultStoreOptions
if rootless && rootlessUid != 0 {
storageOpts, err = getRootlessStorageOpts(rootlessUid)
... | go | func DefaultStoreOptions(rootless bool, rootlessUid int) (StoreOptions, error) {
var (
defaultRootlessRunRoot string
defaultRootlessGraphRoot string
err error
)
storageOpts := defaultStoreOptions
if rootless && rootlessUid != 0 {
storageOpts, err = getRootlessStorageOpts(rootlessUid)
... | [
"func",
"DefaultStoreOptions",
"(",
"rootless",
"bool",
",",
"rootlessUid",
"int",
")",
"(",
"StoreOptions",
",",
"error",
")",
"{",
"var",
"(",
"defaultRootlessRunRoot",
"string",
"\n",
"defaultRootlessGraphRoot",
"string",
"\n",
"err",
"error",
"\n",
")",
"\n"... | // DefaultStoreOptions returns the default storage ops for containers | [
"DefaultStoreOptions",
"returns",
"the",
"default",
"storage",
"ops",
"for",
"containers"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/utils.go#L178-L238 | train |
containers/storage | pkg/ostree/ostree.go | ConvertToOSTree | func ConvertToOSTree(repoLocation, root, id string) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
repo, err := otbuiltin.OpenRepo(repoLocation)
if err != nil {
return errors.Wrap(err, "could not open the OSTree repository")
}
skip, whiteouts, err := fixFiles(root, os.Getuid() != 0)
if err != n... | go | func ConvertToOSTree(repoLocation, root, id string) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
repo, err := otbuiltin.OpenRepo(repoLocation)
if err != nil {
return errors.Wrap(err, "could not open the OSTree repository")
}
skip, whiteouts, err := fixFiles(root, os.Getuid() != 0)
if err != n... | [
"func",
"ConvertToOSTree",
"(",
"repoLocation",
",",
"root",
",",
"id",
"string",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n",
"repo",
",",
"err",
":=",
"otbuiltin",
".",
"O... | // Create prepares the filesystem for the OSTREE driver and copies the directory for the given id under the parent. | [
"Create",
"prepares",
"the",
"filesystem",
"for",
"the",
"OSTREE",
"driver",
"and",
"copies",
"the",
"directory",
"for",
"the",
"given",
"id",
"under",
"the",
"parent",
"."
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/ostree/ostree.go#L80-L141 | train |
containers/storage | pkg/archive/copy.go | CopyInfoDestinationPath | func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
maxSymlinkIter := 10 // filepath.EvalSymlinks uses 255, but 10 already seems like a lot.
path = normalizePath(path)
originalPath := path
stat, err := os.Lstat(path)
if err == nil && stat.Mode()&os.ModeSymlink == 0 {
// The path exists and i... | go | func CopyInfoDestinationPath(path string) (info CopyInfo, err error) {
maxSymlinkIter := 10 // filepath.EvalSymlinks uses 255, but 10 already seems like a lot.
path = normalizePath(path)
originalPath := path
stat, err := os.Lstat(path)
if err == nil && stat.Mode()&os.ModeSymlink == 0 {
// The path exists and i... | [
"func",
"CopyInfoDestinationPath",
"(",
"path",
"string",
")",
"(",
"info",
"CopyInfo",
",",
"err",
"error",
")",
"{",
"maxSymlinkIter",
":=",
"10",
"// filepath.EvalSymlinks uses 255, but 10 already seems like a lot.",
"\n",
"path",
"=",
"normalizePath",
"(",
"path",
... | // CopyInfoDestinationPath stats the given path to create a CopyInfo
// struct representing that resource for the destination of an archive copy
// operation. The given path should be an absolute local path. | [
"CopyInfoDestinationPath",
"stats",
"the",
"given",
"path",
"to",
"create",
"a",
"CopyInfo",
"struct",
"representing",
"that",
"resource",
"for",
"the",
"destination",
"of",
"an",
"archive",
"copy",
"operation",
".",
"The",
"given",
"path",
"should",
"be",
"an",... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/copy.go#L165-L238 | train |
containers/storage | pkg/archive/copy.go | CopyResource | func CopyResource(srcPath, dstPath string, followLink bool) error {
var (
srcInfo CopyInfo
err error
)
// Ensure in platform semantics
srcPath = normalizePath(srcPath)
dstPath = normalizePath(dstPath)
// Clean the source and destination paths.
srcPath = PreserveTrailingDotOrSeparator(filepath.Clean(src... | go | func CopyResource(srcPath, dstPath string, followLink bool) error {
var (
srcInfo CopyInfo
err error
)
// Ensure in platform semantics
srcPath = normalizePath(srcPath)
dstPath = normalizePath(dstPath)
// Clean the source and destination paths.
srcPath = PreserveTrailingDotOrSeparator(filepath.Clean(src... | [
"func",
"CopyResource",
"(",
"srcPath",
",",
"dstPath",
"string",
",",
"followLink",
"bool",
")",
"error",
"{",
"var",
"(",
"srcInfo",
"CopyInfo",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"// Ensure in platform semantics",
"srcPath",
"=",
"normalizePath",
"(",
... | // CopyResource performs an archive copy from the given source path to the
// given destination path. The source path MUST exist and the destination
// path's parent directory must exist. | [
"CopyResource",
"performs",
"an",
"archive",
"copy",
"from",
"the",
"given",
"source",
"path",
"to",
"the",
"given",
"destination",
"path",
".",
"The",
"source",
"path",
"MUST",
"exist",
"and",
"the",
"destination",
"path",
"s",
"parent",
"directory",
"must",
... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/copy.go#L357-L382 | train |
containers/storage | pkg/archive/copy.go | ResolveHostSourcePath | func ResolveHostSourcePath(path string, followLink bool) (resolvedPath, rebaseName string, err error) {
if followLink {
resolvedPath, err = filepath.EvalSymlinks(path)
if err != nil {
return
}
resolvedPath, rebaseName = GetRebaseName(path, resolvedPath)
} else {
dirPath, basePath := filepath.Split(path)... | go | func ResolveHostSourcePath(path string, followLink bool) (resolvedPath, rebaseName string, err error) {
if followLink {
resolvedPath, err = filepath.EvalSymlinks(path)
if err != nil {
return
}
resolvedPath, rebaseName = GetRebaseName(path, resolvedPath)
} else {
dirPath, basePath := filepath.Split(path)... | [
"func",
"ResolveHostSourcePath",
"(",
"path",
"string",
",",
"followLink",
"bool",
")",
"(",
"resolvedPath",
",",
"rebaseName",
"string",
",",
"err",
"error",
")",
"{",
"if",
"followLink",
"{",
"resolvedPath",
",",
"err",
"=",
"filepath",
".",
"EvalSymlinks",
... | // ResolveHostSourcePath decides real path need to be copied with parameters such as
// whether to follow symbol link or not, if followLink is true, resolvedPath will return
// link target of any symbol link file, else it will only resolve symlink of directory
// but return symbol link file itself without resolving. | [
"ResolveHostSourcePath",
"decides",
"real",
"path",
"need",
"to",
"be",
"copied",
"with",
"parameters",
"such",
"as",
"whether",
"to",
"follow",
"symbol",
"link",
"or",
"not",
"if",
"followLink",
"is",
"true",
"resolvedPath",
"will",
"return",
"link",
"target",
... | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/copy.go#L412-L437 | train |
containers/storage | pkg/archive/copy.go | GetRebaseName | func GetRebaseName(path, resolvedPath string) (string, string) {
// linkTarget will have been cleaned (no trailing path separators and dot) so
// we can manually join it with them
var rebaseName string
if specifiesCurrentDir(path) && !specifiesCurrentDir(resolvedPath) {
resolvedPath += string(filepath.Separator) ... | go | func GetRebaseName(path, resolvedPath string) (string, string) {
// linkTarget will have been cleaned (no trailing path separators and dot) so
// we can manually join it with them
var rebaseName string
if specifiesCurrentDir(path) && !specifiesCurrentDir(resolvedPath) {
resolvedPath += string(filepath.Separator) ... | [
"func",
"GetRebaseName",
"(",
"path",
",",
"resolvedPath",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"// linkTarget will have been cleaned (no trailing path separators and dot) so",
"// we can manually join it with them",
"var",
"rebaseName",
"string",
"\n",
"if"... | // GetRebaseName normalizes and compares path and resolvedPath,
// return completed resolved path and rebased file name | [
"GetRebaseName",
"normalizes",
"and",
"compares",
"path",
"and",
"resolvedPath",
"return",
"completed",
"resolved",
"path",
"and",
"rebased",
"file",
"name"
] | 94f0324a5d0c063ffa4adb04361dc2f863b17e05 | https://github.com/containers/storage/blob/94f0324a5d0c063ffa4adb04361dc2f863b17e05/pkg/archive/copy.go#L441-L461 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.