id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,900 |
coreos/coreos-cloudinit
|
config/validate/validate.go
|
parseCloudConfig
|
func parseCloudConfig(cfg []byte, report *Report) (node, error) {
yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) {
return nameIn
}
// unmarshal the config into an implicitly-typed form. The yaml library
// will implicitly convert types into their normalized form
// (e.g. 0744 -> 484, off -> false).
var weak map[interface{}]interface{}
if err := yaml.Unmarshal(cfg, &weak); err != nil {
matches := yamlLineError.FindStringSubmatch(err.Error())
if len(matches) == 3 {
line, err := strconv.Atoi(matches[1])
if err != nil {
return node{}, err
}
msg := matches[2]
report.Error(line, msg)
return node{}, nil
}
matches = yamlError.FindStringSubmatch(err.Error())
if len(matches) == 2 {
report.Error(1, matches[1])
return node{}, nil
}
return node{}, errors.New("couldn't parse yaml error")
}
w := NewNode(weak, NewContext(cfg))
w = normalizeNodeNames(w, report)
// unmarshal the config into the explicitly-typed form.
yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) {
return strings.Replace(nameIn, "-", "_", -1)
}
var strong config.CloudConfig
if err := yaml.Unmarshal([]byte(cfg), &strong); err != nil {
return node{}, err
}
s := NewNode(strong, NewContext(cfg))
// coerceNodes weak nodes and strong nodes. strong nodes replace weak nodes
// if they are compatible types (this happens when the yaml library
// converts the input).
// (e.g. weak 484 is replaced by strong 0744, weak 4 is not replaced by
// strong false)
return coerceNodes(w, s), nil
}
|
go
|
func parseCloudConfig(cfg []byte, report *Report) (node, error) {
yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) {
return nameIn
}
// unmarshal the config into an implicitly-typed form. The yaml library
// will implicitly convert types into their normalized form
// (e.g. 0744 -> 484, off -> false).
var weak map[interface{}]interface{}
if err := yaml.Unmarshal(cfg, &weak); err != nil {
matches := yamlLineError.FindStringSubmatch(err.Error())
if len(matches) == 3 {
line, err := strconv.Atoi(matches[1])
if err != nil {
return node{}, err
}
msg := matches[2]
report.Error(line, msg)
return node{}, nil
}
matches = yamlError.FindStringSubmatch(err.Error())
if len(matches) == 2 {
report.Error(1, matches[1])
return node{}, nil
}
return node{}, errors.New("couldn't parse yaml error")
}
w := NewNode(weak, NewContext(cfg))
w = normalizeNodeNames(w, report)
// unmarshal the config into the explicitly-typed form.
yaml.UnmarshalMappingKeyTransform = func(nameIn string) (nameOut string) {
return strings.Replace(nameIn, "-", "_", -1)
}
var strong config.CloudConfig
if err := yaml.Unmarshal([]byte(cfg), &strong); err != nil {
return node{}, err
}
s := NewNode(strong, NewContext(cfg))
// coerceNodes weak nodes and strong nodes. strong nodes replace weak nodes
// if they are compatible types (this happens when the yaml library
// converts the input).
// (e.g. weak 484 is replaced by strong 0744, weak 4 is not replaced by
// strong false)
return coerceNodes(w, s), nil
}
|
[
"func",
"parseCloudConfig",
"(",
"cfg",
"[",
"]",
"byte",
",",
"report",
"*",
"Report",
")",
"(",
"node",
",",
"error",
")",
"{",
"yaml",
".",
"UnmarshalMappingKeyTransform",
"=",
"func",
"(",
"nameIn",
"string",
")",
"(",
"nameOut",
"string",
")",
"{",
"return",
"nameIn",
"\n",
"}",
"\n",
"// unmarshal the config into an implicitly-typed form. The yaml library",
"// will implicitly convert types into their normalized form",
"// (e.g. 0744 -> 484, off -> false).",
"var",
"weak",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"cfg",
",",
"&",
"weak",
")",
";",
"err",
"!=",
"nil",
"{",
"matches",
":=",
"yamlLineError",
".",
"FindStringSubmatch",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"==",
"3",
"{",
"line",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"matches",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"node",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"msg",
":=",
"matches",
"[",
"2",
"]",
"\n",
"report",
".",
"Error",
"(",
"line",
",",
"msg",
")",
"\n",
"return",
"node",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"matches",
"=",
"yamlError",
".",
"FindStringSubmatch",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"==",
"2",
"{",
"report",
".",
"Error",
"(",
"1",
",",
"matches",
"[",
"1",
"]",
")",
"\n",
"return",
"node",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"node",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
":=",
"NewNode",
"(",
"weak",
",",
"NewContext",
"(",
"cfg",
")",
")",
"\n",
"w",
"=",
"normalizeNodeNames",
"(",
"w",
",",
"report",
")",
"\n\n",
"// unmarshal the config into the explicitly-typed form.",
"yaml",
".",
"UnmarshalMappingKeyTransform",
"=",
"func",
"(",
"nameIn",
"string",
")",
"(",
"nameOut",
"string",
")",
"{",
"return",
"strings",
".",
"Replace",
"(",
"nameIn",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"var",
"strong",
"config",
".",
"CloudConfig",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"cfg",
")",
",",
"&",
"strong",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"node",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"NewNode",
"(",
"strong",
",",
"NewContext",
"(",
"cfg",
")",
")",
"\n\n",
"// coerceNodes weak nodes and strong nodes. strong nodes replace weak nodes",
"// if they are compatible types (this happens when the yaml library",
"// converts the input).",
"// (e.g. weak 484 is replaced by strong 0744, weak 4 is not replaced by",
"// strong false)",
"return",
"coerceNodes",
"(",
"w",
",",
"s",
")",
",",
"nil",
"\n",
"}"
] |
// parseCloudConfig parses the provided config into a node structure and logs
// any parsing issues into the provided report. Unrecoverable errors are
// returned as an error.
|
[
"parseCloudConfig",
"parses",
"the",
"provided",
"config",
"into",
"a",
"node",
"structure",
"and",
"logs",
"any",
"parsing",
"issues",
"into",
"the",
"provided",
"report",
".",
"Unrecoverable",
"errors",
"are",
"returned",
"as",
"an",
"error",
"."
] |
f1f0405491dfd073bbf074f7e374c9ef85600691
|
https://github.com/coreos/coreos-cloudinit/blob/f1f0405491dfd073bbf074f7e374c9ef85600691/config/validate/validate.go#L77-L124
|
16,901 |
coreos/coreos-cloudinit
|
config/validate/validate.go
|
normalizeNodeNames
|
func normalizeNodeNames(node node, report *Report) node {
if strings.Contains(node.name, "-") {
// TODO(crawford): Enable this message once the new validator hits stable.
//report.Info(node.line, fmt.Sprintf("%q uses '-' instead of '_'", node.name))
node.name = strings.Replace(node.name, "-", "_", -1)
}
for i := range node.children {
node.children[i] = normalizeNodeNames(node.children[i], report)
}
return node
}
|
go
|
func normalizeNodeNames(node node, report *Report) node {
if strings.Contains(node.name, "-") {
// TODO(crawford): Enable this message once the new validator hits stable.
//report.Info(node.line, fmt.Sprintf("%q uses '-' instead of '_'", node.name))
node.name = strings.Replace(node.name, "-", "_", -1)
}
for i := range node.children {
node.children[i] = normalizeNodeNames(node.children[i], report)
}
return node
}
|
[
"func",
"normalizeNodeNames",
"(",
"node",
"node",
",",
"report",
"*",
"Report",
")",
"node",
"{",
"if",
"strings",
".",
"Contains",
"(",
"node",
".",
"name",
",",
"\"",
"\"",
")",
"{",
"// TODO(crawford): Enable this message once the new validator hits stable.",
"//report.Info(node.line, fmt.Sprintf(\"%q uses '-' instead of '_'\", node.name))",
"node",
".",
"name",
"=",
"strings",
".",
"Replace",
"(",
"node",
".",
"name",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"node",
".",
"children",
"{",
"node",
".",
"children",
"[",
"i",
"]",
"=",
"normalizeNodeNames",
"(",
"node",
".",
"children",
"[",
"i",
"]",
",",
"report",
")",
"\n",
"}",
"\n",
"return",
"node",
"\n",
"}"
] |
// normalizeNodeNames replaces all occurences of '-' with '_' within key names
// and makes a note of each replacement in the report.
|
[
"normalizeNodeNames",
"replaces",
"all",
"occurences",
"of",
"-",
"with",
"_",
"within",
"key",
"names",
"and",
"makes",
"a",
"note",
"of",
"each",
"replacement",
"in",
"the",
"report",
"."
] |
f1f0405491dfd073bbf074f7e374c9ef85600691
|
https://github.com/coreos/coreos-cloudinit/blob/f1f0405491dfd073bbf074f7e374c9ef85600691/config/validate/validate.go#L154-L164
|
16,902 |
mitchellh/reflectwalk
|
reflectwalk.go
|
Walk
|
func Walk(data, walker interface{}) (err error) {
v := reflect.ValueOf(data)
ew, ok := walker.(EnterExitWalker)
if ok {
err = ew.Enter(WalkLoc)
}
if err == nil {
err = walk(v, walker)
}
if ok && err == nil {
err = ew.Exit(WalkLoc)
}
return
}
|
go
|
func Walk(data, walker interface{}) (err error) {
v := reflect.ValueOf(data)
ew, ok := walker.(EnterExitWalker)
if ok {
err = ew.Enter(WalkLoc)
}
if err == nil {
err = walk(v, walker)
}
if ok && err == nil {
err = ew.Exit(WalkLoc)
}
return
}
|
[
"func",
"Walk",
"(",
"data",
",",
"walker",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
"\n",
"ew",
",",
"ok",
":=",
"walker",
".",
"(",
"EnterExitWalker",
")",
"\n",
"if",
"ok",
"{",
"err",
"=",
"ew",
".",
"Enter",
"(",
"WalkLoc",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"walk",
"(",
"v",
",",
"walker",
")",
"\n",
"}",
"\n\n",
"if",
"ok",
"&&",
"err",
"==",
"nil",
"{",
"err",
"=",
"ew",
".",
"Exit",
"(",
"WalkLoc",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// Walk takes an arbitrary value and an interface and traverses the
// value, calling callbacks on the interface if they are supported.
// The interface should implement one or more of the walker interfaces
// in this package, such as PrimitiveWalker, StructWalker, etc.
|
[
"Walk",
"takes",
"an",
"arbitrary",
"value",
"and",
"an",
"interface",
"and",
"traverses",
"the",
"value",
"calling",
"callbacks",
"on",
"the",
"interface",
"if",
"they",
"are",
"supported",
".",
"The",
"interface",
"should",
"implement",
"one",
"or",
"more",
"of",
"the",
"walker",
"interfaces",
"in",
"this",
"package",
"such",
"as",
"PrimitiveWalker",
"StructWalker",
"etc",
"."
] |
3e2c75dfad4fbf904b58782a80fd595c760ad185
|
https://github.com/mitchellh/reflectwalk/blob/3e2c75dfad4fbf904b58782a80fd595c760ad185/reflectwalk.go#L84-L100
|
16,903 |
pires/go-proxyproto
|
header.go
|
EqualTo
|
func (header *Header) EqualTo(q *Header) bool {
if header == nil || q == nil {
return false
}
if header.Command.IsLocal() {
return true
}
return header.TransportProtocol == q.TransportProtocol &&
header.SourceAddress.String() == q.SourceAddress.String() &&
header.DestinationAddress.String() == q.DestinationAddress.String() &&
header.SourcePort == q.SourcePort &&
header.DestinationPort == q.DestinationPort
}
|
go
|
func (header *Header) EqualTo(q *Header) bool {
if header == nil || q == nil {
return false
}
if header.Command.IsLocal() {
return true
}
return header.TransportProtocol == q.TransportProtocol &&
header.SourceAddress.String() == q.SourceAddress.String() &&
header.DestinationAddress.String() == q.DestinationAddress.String() &&
header.SourcePort == q.SourcePort &&
header.DestinationPort == q.DestinationPort
}
|
[
"func",
"(",
"header",
"*",
"Header",
")",
"EqualTo",
"(",
"q",
"*",
"Header",
")",
"bool",
"{",
"if",
"header",
"==",
"nil",
"||",
"q",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"header",
".",
"Command",
".",
"IsLocal",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"header",
".",
"TransportProtocol",
"==",
"q",
".",
"TransportProtocol",
"&&",
"header",
".",
"SourceAddress",
".",
"String",
"(",
")",
"==",
"q",
".",
"SourceAddress",
".",
"String",
"(",
")",
"&&",
"header",
".",
"DestinationAddress",
".",
"String",
"(",
")",
"==",
"q",
".",
"DestinationAddress",
".",
"String",
"(",
")",
"&&",
"header",
".",
"SourcePort",
"==",
"q",
".",
"SourcePort",
"&&",
"header",
".",
"DestinationPort",
"==",
"q",
".",
"DestinationPort",
"\n",
"}"
] |
// EqualTo returns true if headers are equivalent, false otherwise.
|
[
"EqualTo",
"returns",
"true",
"if",
"headers",
"are",
"equivalent",
"false",
"otherwise",
"."
] |
4d51b51e3bfc23ac5f4384478ff64940f34a5d63
|
https://github.com/pires/go-proxyproto/blob/4d51b51e3bfc23ac5f4384478ff64940f34a5d63/header.go#L45-L57
|
16,904 |
pires/go-proxyproto
|
header.go
|
WriteTo
|
func (header *Header) WriteTo(w io.Writer) (int64, error) {
switch header.Version {
case 1:
return header.writeVersion1(w)
case 2:
return header.writeVersion2(w)
default:
return 0, ErrUnknownProxyProtocolVersion
}
}
|
go
|
func (header *Header) WriteTo(w io.Writer) (int64, error) {
switch header.Version {
case 1:
return header.writeVersion1(w)
case 2:
return header.writeVersion2(w)
default:
return 0, ErrUnknownProxyProtocolVersion
}
}
|
[
"func",
"(",
"header",
"*",
"Header",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"switch",
"header",
".",
"Version",
"{",
"case",
"1",
":",
"return",
"header",
".",
"writeVersion1",
"(",
"w",
")",
"\n",
"case",
"2",
":",
"return",
"header",
".",
"writeVersion2",
"(",
"w",
")",
"\n",
"default",
":",
"return",
"0",
",",
"ErrUnknownProxyProtocolVersion",
"\n",
"}",
"\n",
"}"
] |
// WriteTo renders a proxy protocol header in a format to write over the wire.
|
[
"WriteTo",
"renders",
"a",
"proxy",
"protocol",
"header",
"in",
"a",
"format",
"to",
"write",
"over",
"the",
"wire",
"."
] |
4d51b51e3bfc23ac5f4384478ff64940f34a5d63
|
https://github.com/pires/go-proxyproto/blob/4d51b51e3bfc23ac5f4384478ff64940f34a5d63/header.go#L60-L69
|
16,905 |
pires/go-proxyproto
|
header.go
|
Read
|
func Read(reader *bufio.Reader) (*Header, error) {
// In order to improve speed for small non-PROXYed packets, take a peek at the first byte alone.
if b1, err := reader.Peek(1); err == nil && (bytes.Equal(b1[:1], SIGV1[:1]) || bytes.Equal(b1[:1], SIGV2[:1])) {
if signature, err := reader.Peek(5); err == nil && bytes.Equal(signature[:5], SIGV1) {
return parseVersion1(reader)
} else if signature, err := reader.Peek(12); err == nil && bytes.Equal(signature[:12], SIGV2) {
return parseVersion2(reader)
}
}
return nil, ErrNoProxyProtocol
}
|
go
|
func Read(reader *bufio.Reader) (*Header, error) {
// In order to improve speed for small non-PROXYed packets, take a peek at the first byte alone.
if b1, err := reader.Peek(1); err == nil && (bytes.Equal(b1[:1], SIGV1[:1]) || bytes.Equal(b1[:1], SIGV2[:1])) {
if signature, err := reader.Peek(5); err == nil && bytes.Equal(signature[:5], SIGV1) {
return parseVersion1(reader)
} else if signature, err := reader.Peek(12); err == nil && bytes.Equal(signature[:12], SIGV2) {
return parseVersion2(reader)
}
}
return nil, ErrNoProxyProtocol
}
|
[
"func",
"Read",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
")",
"(",
"*",
"Header",
",",
"error",
")",
"{",
"// In order to improve speed for small non-PROXYed packets, take a peek at the first byte alone.",
"if",
"b1",
",",
"err",
":=",
"reader",
".",
"Peek",
"(",
"1",
")",
";",
"err",
"==",
"nil",
"&&",
"(",
"bytes",
".",
"Equal",
"(",
"b1",
"[",
":",
"1",
"]",
",",
"SIGV1",
"[",
":",
"1",
"]",
")",
"||",
"bytes",
".",
"Equal",
"(",
"b1",
"[",
":",
"1",
"]",
",",
"SIGV2",
"[",
":",
"1",
"]",
")",
")",
"{",
"if",
"signature",
",",
"err",
":=",
"reader",
".",
"Peek",
"(",
"5",
")",
";",
"err",
"==",
"nil",
"&&",
"bytes",
".",
"Equal",
"(",
"signature",
"[",
":",
"5",
"]",
",",
"SIGV1",
")",
"{",
"return",
"parseVersion1",
"(",
"reader",
")",
"\n",
"}",
"else",
"if",
"signature",
",",
"err",
":=",
"reader",
".",
"Peek",
"(",
"12",
")",
";",
"err",
"==",
"nil",
"&&",
"bytes",
".",
"Equal",
"(",
"signature",
"[",
":",
"12",
"]",
",",
"SIGV2",
")",
"{",
"return",
"parseVersion2",
"(",
"reader",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"ErrNoProxyProtocol",
"\n",
"}"
] |
// Read identifies the proxy protocol version and reads the remaining of
// the header, accordingly.
//
// If proxy protocol header signature is not present, the reader buffer remains untouched
// and is safe for reading outside of this code.
//
// If proxy protocol header signature is present but an error is raised while processing
// the remaining header, assume the reader buffer to be in a corrupt state.
// Also, this operation will block until enough bytes are available for peeking.
|
[
"Read",
"identifies",
"the",
"proxy",
"protocol",
"version",
"and",
"reads",
"the",
"remaining",
"of",
"the",
"header",
"accordingly",
".",
"If",
"proxy",
"protocol",
"header",
"signature",
"is",
"not",
"present",
"the",
"reader",
"buffer",
"remains",
"untouched",
"and",
"is",
"safe",
"for",
"reading",
"outside",
"of",
"this",
"code",
".",
"If",
"proxy",
"protocol",
"header",
"signature",
"is",
"present",
"but",
"an",
"error",
"is",
"raised",
"while",
"processing",
"the",
"remaining",
"header",
"assume",
"the",
"reader",
"buffer",
"to",
"be",
"in",
"a",
"corrupt",
"state",
".",
"Also",
"this",
"operation",
"will",
"block",
"until",
"enough",
"bytes",
"are",
"available",
"for",
"peeking",
"."
] |
4d51b51e3bfc23ac5f4384478ff64940f34a5d63
|
https://github.com/pires/go-proxyproto/blob/4d51b51e3bfc23ac5f4384478ff64940f34a5d63/header.go#L80-L91
|
16,906 |
pires/go-proxyproto
|
header.go
|
ReadTimeout
|
func ReadTimeout(reader *bufio.Reader, timeout time.Duration) (*Header, error) {
type header struct {
h *Header
e error
}
read := make(chan *header, 1)
go func() {
h := &header{}
h.h, h.e = Read(reader)
read <- h
}()
timer := time.NewTimer(timeout)
select {
case result := <-read:
timer.Stop()
return result.h, result.e
case <-timer.C:
return nil, ErrNoProxyProtocol
}
}
|
go
|
func ReadTimeout(reader *bufio.Reader, timeout time.Duration) (*Header, error) {
type header struct {
h *Header
e error
}
read := make(chan *header, 1)
go func() {
h := &header{}
h.h, h.e = Read(reader)
read <- h
}()
timer := time.NewTimer(timeout)
select {
case result := <-read:
timer.Stop()
return result.h, result.e
case <-timer.C:
return nil, ErrNoProxyProtocol
}
}
|
[
"func",
"ReadTimeout",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Header",
",",
"error",
")",
"{",
"type",
"header",
"struct",
"{",
"h",
"*",
"Header",
"\n",
"e",
"error",
"\n",
"}",
"\n",
"read",
":=",
"make",
"(",
"chan",
"*",
"header",
",",
"1",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"h",
":=",
"&",
"header",
"{",
"}",
"\n",
"h",
".",
"h",
",",
"h",
".",
"e",
"=",
"Read",
"(",
"reader",
")",
"\n",
"read",
"<-",
"h",
"\n",
"}",
"(",
")",
"\n\n",
"timer",
":=",
"time",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"select",
"{",
"case",
"result",
":=",
"<-",
"read",
":",
"timer",
".",
"Stop",
"(",
")",
"\n",
"return",
"result",
".",
"h",
",",
"result",
".",
"e",
"\n",
"case",
"<-",
"timer",
".",
"C",
":",
"return",
"nil",
",",
"ErrNoProxyProtocol",
"\n",
"}",
"\n",
"}"
] |
// ReadTimeout acts as Read but takes a timeout. If that timeout is reached, it's assumed
// there's no proxy protocol header.
|
[
"ReadTimeout",
"acts",
"as",
"Read",
"but",
"takes",
"a",
"timeout",
".",
"If",
"that",
"timeout",
"is",
"reached",
"it",
"s",
"assumed",
"there",
"s",
"no",
"proxy",
"protocol",
"header",
"."
] |
4d51b51e3bfc23ac5f4384478ff64940f34a5d63
|
https://github.com/pires/go-proxyproto/blob/4d51b51e3bfc23ac5f4384478ff64940f34a5d63/header.go#L95-L116
|
16,907 |
pixiv/go-libjpeg
|
rgb/rgb.go
|
NewImage
|
func NewImage(r image.Rectangle) *Image {
w, h := r.Dx(), r.Dy()
return &Image{Pix: make([]uint8, 3*w*h), Stride: 3 * w, Rect: r}
}
|
go
|
func NewImage(r image.Rectangle) *Image {
w, h := r.Dx(), r.Dy()
return &Image{Pix: make([]uint8, 3*w*h), Stride: 3 * w, Rect: r}
}
|
[
"func",
"NewImage",
"(",
"r",
"image",
".",
"Rectangle",
")",
"*",
"Image",
"{",
"w",
",",
"h",
":=",
"r",
".",
"Dx",
"(",
")",
",",
"r",
".",
"Dy",
"(",
")",
"\n",
"return",
"&",
"Image",
"{",
"Pix",
":",
"make",
"(",
"[",
"]",
"uint8",
",",
"3",
"*",
"w",
"*",
"h",
")",
",",
"Stride",
":",
"3",
"*",
"w",
",",
"Rect",
":",
"r",
"}",
"\n",
"}"
] |
// NewImage allocates and returns RGB image
|
[
"NewImage",
"allocates",
"and",
"returns",
"RGB",
"image"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/rgb/rgb.go#L21-L24
|
16,908 |
pixiv/go-libjpeg
|
rgb/rgb.go
|
At
|
func (p *Image) At(x, y int) color.Color {
return p.RGBAAt(x, y)
}
|
go
|
func (p *Image) At(x, y int) color.Color {
return p.RGBAAt(x, y)
}
|
[
"func",
"(",
"p",
"*",
"Image",
")",
"At",
"(",
"x",
",",
"y",
"int",
")",
"color",
".",
"Color",
"{",
"return",
"p",
".",
"RGBAAt",
"(",
"x",
",",
"y",
")",
"\n",
"}"
] |
// At implements image.Image.At
|
[
"At",
"implements",
"image",
".",
"Image",
".",
"At"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/rgb/rgb.go#L37-L39
|
16,909 |
pixiv/go-libjpeg
|
rgb/rgb.go
|
RGBA
|
func (c RGB) RGBA() (r, g, b, a uint32) {
r = uint32(c.R)
r |= r << 8
g = uint32(c.G)
g |= g << 8
b = uint32(c.B)
b |= b << 8
a = uint32(0xFFFF)
return
}
|
go
|
func (c RGB) RGBA() (r, g, b, a uint32) {
r = uint32(c.R)
r |= r << 8
g = uint32(c.G)
g |= g << 8
b = uint32(c.B)
b |= b << 8
a = uint32(0xFFFF)
return
}
|
[
"func",
"(",
"c",
"RGB",
")",
"RGBA",
"(",
")",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
"uint32",
")",
"{",
"r",
"=",
"uint32",
"(",
"c",
".",
"R",
")",
"\n",
"r",
"|=",
"r",
"<<",
"8",
"\n",
"g",
"=",
"uint32",
"(",
"c",
".",
"G",
")",
"\n",
"g",
"|=",
"g",
"<<",
"8",
"\n",
"b",
"=",
"uint32",
"(",
"c",
".",
"B",
")",
"\n",
"b",
"|=",
"b",
"<<",
"8",
"\n",
"a",
"=",
"uint32",
"(",
"0xFFFF",
")",
"\n",
"return",
"\n",
"}"
] |
// RGBA implements Color.RGBA
|
[
"RGBA",
"implements",
"Color",
".",
"RGBA"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/rgb/rgb.go#L67-L76
|
16,910 |
pixiv/go-libjpeg
|
jpeg/decompress.go
|
Decode
|
func Decode(r io.Reader, options *DecoderOptions) (dest image.Image, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
switch dinfo.num_components {
case 1:
if dinfo.jpeg_color_space != C.JCS_GRAYSCALE {
return nil, errors.New("Image has unsupported colorspace")
}
dest, err = decodeGray(dinfo)
case 3:
switch dinfo.jpeg_color_space {
case C.JCS_YCbCr:
dest, err = decodeYCbCr(dinfo)
case C.JCS_RGB:
dest, err = decodeRGB(dinfo)
default:
return nil, errors.New("Image has unsupported colorspace")
}
}
return
}
|
go
|
func Decode(r io.Reader, options *DecoderOptions) (dest image.Image, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
switch dinfo.num_components {
case 1:
if dinfo.jpeg_color_space != C.JCS_GRAYSCALE {
return nil, errors.New("Image has unsupported colorspace")
}
dest, err = decodeGray(dinfo)
case 3:
switch dinfo.jpeg_color_space {
case C.JCS_YCbCr:
dest, err = decodeYCbCr(dinfo)
case C.JCS_RGB:
dest, err = decodeRGB(dinfo)
default:
return nil, errors.New("Image has unsupported colorspace")
}
}
return
}
|
[
"func",
"Decode",
"(",
"r",
"io",
".",
"Reader",
",",
"options",
"*",
"DecoderOptions",
")",
"(",
"dest",
"image",
".",
"Image",
",",
"err",
"error",
")",
"{",
"dinfo",
":=",
"newDecompress",
"(",
"r",
")",
"\n",
"if",
"dinfo",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"destroyDecompress",
"(",
"dinfo",
")",
"\n\n",
"// Recover panic",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"r",
".",
"(",
"error",
")",
";",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"C",
".",
"jpeg_read_header",
"(",
"dinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"setupDecoderOptions",
"(",
"dinfo",
",",
"options",
")",
"\n\n",
"switch",
"dinfo",
".",
"num_components",
"{",
"case",
"1",
":",
"if",
"dinfo",
".",
"jpeg_color_space",
"!=",
"C",
".",
"JCS_GRAYSCALE",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"dest",
",",
"err",
"=",
"decodeGray",
"(",
"dinfo",
")",
"\n",
"case",
"3",
":",
"switch",
"dinfo",
".",
"jpeg_color_space",
"{",
"case",
"C",
".",
"JCS_YCbCr",
":",
"dest",
",",
"err",
"=",
"decodeYCbCr",
"(",
"dinfo",
")",
"\n",
"case",
"C",
".",
"JCS_RGB",
":",
"dest",
",",
"err",
"=",
"decodeRGB",
"(",
"dinfo",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Decode reads a JPEG data stream from r and returns decoded image as an image.Image.
// Output image has YCbCr colors or 8bit Grayscale.
|
[
"Decode",
"reads",
"a",
"JPEG",
"data",
"stream",
"from",
"r",
"and",
"returns",
"decoded",
"image",
"as",
"an",
"image",
".",
"Image",
".",
"Output",
"image",
"has",
"YCbCr",
"colors",
"or",
"8bit",
"Grayscale",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/decompress.go#L140-L176
|
16,911 |
pixiv/go-libjpeg
|
jpeg/decompress.go
|
DecodeIntoRGB
|
func DecodeIntoRGB(r io.Reader, options *DecoderOptions) (dest *rgb.Image, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
C.jpeg_calc_output_dimensions(dinfo)
dest = rgb.NewImage(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height)))
dinfo.out_color_space = C.JCS_RGB
readScanLines(dinfo, dest.Pix, dest.Stride)
return
}
|
go
|
func DecodeIntoRGB(r io.Reader, options *DecoderOptions) (dest *rgb.Image, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
C.jpeg_calc_output_dimensions(dinfo)
dest = rgb.NewImage(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height)))
dinfo.out_color_space = C.JCS_RGB
readScanLines(dinfo, dest.Pix, dest.Stride)
return
}
|
[
"func",
"DecodeIntoRGB",
"(",
"r",
"io",
".",
"Reader",
",",
"options",
"*",
"DecoderOptions",
")",
"(",
"dest",
"*",
"rgb",
".",
"Image",
",",
"err",
"error",
")",
"{",
"dinfo",
":=",
"newDecompress",
"(",
"r",
")",
"\n",
"if",
"dinfo",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"destroyDecompress",
"(",
"dinfo",
")",
"\n\n",
"// Recover panic",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"r",
".",
"(",
"error",
")",
";",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"C",
".",
"jpeg_read_header",
"(",
"dinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"setupDecoderOptions",
"(",
"dinfo",
",",
"options",
")",
"\n\n",
"C",
".",
"jpeg_calc_output_dimensions",
"(",
"dinfo",
")",
"\n",
"dest",
"=",
"rgb",
".",
"NewImage",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"int",
"(",
"dinfo",
".",
"output_width",
")",
",",
"int",
"(",
"dinfo",
".",
"output_height",
")",
")",
")",
"\n\n",
"dinfo",
".",
"out_color_space",
"=",
"C",
".",
"JCS_RGB",
"\n",
"readScanLines",
"(",
"dinfo",
",",
"dest",
".",
"Pix",
",",
"dest",
".",
"Stride",
")",
"\n",
"return",
"\n",
"}"
] |
// DecodeIntoRGB reads a JPEG data stream from r and returns decoded image as an rgb.Image with RGB colors.
|
[
"DecodeIntoRGB",
"reads",
"a",
"JPEG",
"data",
"stream",
"from",
"r",
"and",
"returns",
"decoded",
"image",
"as",
"an",
"rgb",
".",
"Image",
"with",
"RGB",
"colors",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/decompress.go#L269-L294
|
16,912 |
pixiv/go-libjpeg
|
jpeg/decompress.go
|
DecodeIntoRGBA
|
func DecodeIntoRGBA(r io.Reader, options *DecoderOptions) (dest *image.RGBA, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
C.jpeg_calc_output_dimensions(dinfo)
dest = image.NewRGBA(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height)))
colorSpace := getJCS_EXT_RGBA()
if colorSpace == C.JCS_UNKNOWN {
return nil, errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)")
}
dinfo.out_color_space = colorSpace
readScanLines(dinfo, dest.Pix, dest.Stride)
return
}
|
go
|
func DecodeIntoRGBA(r io.Reader, options *DecoderOptions) (dest *image.RGBA, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
return nil, errors.New("allocation failed")
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
setupDecoderOptions(dinfo, options)
C.jpeg_calc_output_dimensions(dinfo)
dest = image.NewRGBA(image.Rect(0, 0, int(dinfo.output_width), int(dinfo.output_height)))
colorSpace := getJCS_EXT_RGBA()
if colorSpace == C.JCS_UNKNOWN {
return nil, errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)")
}
dinfo.out_color_space = colorSpace
readScanLines(dinfo, dest.Pix, dest.Stride)
return
}
|
[
"func",
"DecodeIntoRGBA",
"(",
"r",
"io",
".",
"Reader",
",",
"options",
"*",
"DecoderOptions",
")",
"(",
"dest",
"*",
"image",
".",
"RGBA",
",",
"err",
"error",
")",
"{",
"dinfo",
":=",
"newDecompress",
"(",
"r",
")",
"\n",
"if",
"dinfo",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"destroyDecompress",
"(",
"dinfo",
")",
"\n\n",
"// Recover panic",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"r",
".",
"(",
"error",
")",
";",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"C",
".",
"jpeg_read_header",
"(",
"dinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"setupDecoderOptions",
"(",
"dinfo",
",",
"options",
")",
"\n\n",
"C",
".",
"jpeg_calc_output_dimensions",
"(",
"dinfo",
")",
"\n",
"dest",
"=",
"image",
".",
"NewRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"int",
"(",
"dinfo",
".",
"output_width",
")",
",",
"int",
"(",
"dinfo",
".",
"output_height",
")",
")",
")",
"\n\n",
"colorSpace",
":=",
"getJCS_EXT_RGBA",
"(",
")",
"\n",
"if",
"colorSpace",
"==",
"C",
".",
"JCS_UNKNOWN",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"dinfo",
".",
"out_color_space",
"=",
"colorSpace",
"\n",
"readScanLines",
"(",
"dinfo",
",",
"dest",
".",
"Pix",
",",
"dest",
".",
"Stride",
")",
"\n",
"return",
"\n",
"}"
] |
// DecodeIntoRGBA reads a JPEG data stream from r and returns decoded image as an image.RGBA with RGBA colors.
// This function only works with libjpeg-turbo, not libjpeg.
|
[
"DecodeIntoRGBA",
"reads",
"a",
"JPEG",
"data",
"stream",
"from",
"r",
"and",
"returns",
"decoded",
"image",
"as",
"an",
"image",
".",
"RGBA",
"with",
"RGBA",
"colors",
".",
"This",
"function",
"only",
"works",
"with",
"libjpeg",
"-",
"turbo",
"not",
"libjpeg",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/decompress.go#L298-L328
|
16,913 |
pixiv/go-libjpeg
|
jpeg/decompress.go
|
DecodeConfig
|
func DecodeConfig(r io.Reader) (config image.Config, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
err = errors.New("allocation failed")
return
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
config = image.Config{
ColorModel: color.YCbCrModel,
Width: int(dinfo.image_width),
Height: int(dinfo.image_height),
}
return
}
|
go
|
func DecodeConfig(r io.Reader) (config image.Config, err error) {
dinfo := newDecompress(r)
if dinfo == nil {
err = errors.New("allocation failed")
return
}
defer destroyDecompress(dinfo)
// Recover panic
defer func() {
if r := recover(); r != nil {
if _, ok := r.(error); !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
C.jpeg_read_header(dinfo, C.TRUE)
config = image.Config{
ColorModel: color.YCbCrModel,
Width: int(dinfo.image_width),
Height: int(dinfo.image_height),
}
return
}
|
[
"func",
"DecodeConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"config",
"image",
".",
"Config",
",",
"err",
"error",
")",
"{",
"dinfo",
":=",
"newDecompress",
"(",
"r",
")",
"\n",
"if",
"dinfo",
"==",
"nil",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"destroyDecompress",
"(",
"dinfo",
")",
"\n\n",
"// Recover panic",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"r",
".",
"(",
"error",
")",
";",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"C",
".",
"jpeg_read_header",
"(",
"dinfo",
",",
"C",
".",
"TRUE",
")",
"\n\n",
"config",
"=",
"image",
".",
"Config",
"{",
"ColorModel",
":",
"color",
".",
"YCbCrModel",
",",
"Width",
":",
"int",
"(",
"dinfo",
".",
"image_width",
")",
",",
"Height",
":",
"int",
"(",
"dinfo",
".",
"image_height",
")",
",",
"}",
"\n",
"return",
"\n",
"}"
] |
// DecodeConfig returns the color model and dimensions of a JPEG image without decoding the entire image.
|
[
"DecodeConfig",
"returns",
"the",
"color",
"model",
"and",
"dimensions",
"of",
"a",
"JPEG",
"image",
"without",
"decoding",
"the",
"entire",
"image",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/decompress.go#L340-L365
|
16,914 |
pixiv/go-libjpeg
|
jpeg/decompress.go
|
NewGrayAligned
|
func NewGrayAligned(r image.Rectangle) *image.Gray {
w, h := r.Dx(), r.Dy()
// TODO: check the padding size to minimize memory allocation.
stride := pad(w, alignSize) + alignSize
ph := pad(h, alignSize) + alignSize
pix := make([]uint8, stride*ph)
return &image.Gray{
Pix: pix,
Stride: stride,
Rect: r,
}
}
|
go
|
func NewGrayAligned(r image.Rectangle) *image.Gray {
w, h := r.Dx(), r.Dy()
// TODO: check the padding size to minimize memory allocation.
stride := pad(w, alignSize) + alignSize
ph := pad(h, alignSize) + alignSize
pix := make([]uint8, stride*ph)
return &image.Gray{
Pix: pix,
Stride: stride,
Rect: r,
}
}
|
[
"func",
"NewGrayAligned",
"(",
"r",
"image",
".",
"Rectangle",
")",
"*",
"image",
".",
"Gray",
"{",
"w",
",",
"h",
":=",
"r",
".",
"Dx",
"(",
")",
",",
"r",
".",
"Dy",
"(",
")",
"\n\n",
"// TODO: check the padding size to minimize memory allocation.",
"stride",
":=",
"pad",
"(",
"w",
",",
"alignSize",
")",
"+",
"alignSize",
"\n",
"ph",
":=",
"pad",
"(",
"h",
",",
"alignSize",
")",
"+",
"alignSize",
"\n\n",
"pix",
":=",
"make",
"(",
"[",
"]",
"uint8",
",",
"stride",
"*",
"ph",
")",
"\n",
"return",
"&",
"image",
".",
"Gray",
"{",
"Pix",
":",
"pix",
",",
"Stride",
":",
"stride",
",",
"Rect",
":",
"r",
",",
"}",
"\n",
"}"
] |
// NewGrayAligned Allocates Grey image with padding.
// This func add an extra padding to cover overflow from decoding image.
|
[
"NewGrayAligned",
"Allocates",
"Grey",
"image",
"with",
"padding",
".",
"This",
"func",
"add",
"an",
"extra",
"padding",
"to",
"cover",
"overflow",
"from",
"decoding",
"image",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/decompress.go#L442-L455
|
16,915 |
pixiv/go-libjpeg
|
jpeg/compress.go
|
Encode
|
func Encode(w io.Writer, src image.Image, opt *EncoderOptions) (err error) {
// Recover panic
defer func() {
if r := recover(); r != nil {
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
cinfo := C.new_compress()
defer C.destroy_compress(cinfo)
dstManager := makeDestinationManager(w, cinfo)
defer releaseDestinationManager(dstManager)
switch s := src.(type) {
case *image.YCbCr:
err = encodeYCbCr(cinfo, s, opt)
case *image.Gray:
err = encodeGray(cinfo, s, opt)
case *image.RGBA:
err = encodeRGBA(cinfo, s, opt)
default:
return errors.New("unsupported image type")
}
return
}
|
go
|
func Encode(w io.Writer, src image.Image, opt *EncoderOptions) (err error) {
// Recover panic
defer func() {
if r := recover(); r != nil {
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("JPEG error: %v", r)
}
}
}()
cinfo := C.new_compress()
defer C.destroy_compress(cinfo)
dstManager := makeDestinationManager(w, cinfo)
defer releaseDestinationManager(dstManager)
switch s := src.(type) {
case *image.YCbCr:
err = encodeYCbCr(cinfo, s, opt)
case *image.Gray:
err = encodeGray(cinfo, s, opt)
case *image.RGBA:
err = encodeRGBA(cinfo, s, opt)
default:
return errors.New("unsupported image type")
}
return
}
|
[
"func",
"Encode",
"(",
"w",
"io",
".",
"Writer",
",",
"src",
"image",
".",
"Image",
",",
"opt",
"*",
"EncoderOptions",
")",
"(",
"err",
"error",
")",
"{",
"// Recover panic",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"var",
"ok",
"bool",
"\n",
"err",
",",
"ok",
"=",
"r",
".",
"(",
"error",
")",
"\n",
"if",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"cinfo",
":=",
"C",
".",
"new_compress",
"(",
")",
"\n",
"defer",
"C",
".",
"destroy_compress",
"(",
"cinfo",
")",
"\n\n",
"dstManager",
":=",
"makeDestinationManager",
"(",
"w",
",",
"cinfo",
")",
"\n",
"defer",
"releaseDestinationManager",
"(",
"dstManager",
")",
"\n\n",
"switch",
"s",
":=",
"src",
".",
"(",
"type",
")",
"{",
"case",
"*",
"image",
".",
"YCbCr",
":",
"err",
"=",
"encodeYCbCr",
"(",
"cinfo",
",",
"s",
",",
"opt",
")",
"\n",
"case",
"*",
"image",
".",
"Gray",
":",
"err",
"=",
"encodeGray",
"(",
"cinfo",
",",
"s",
",",
"opt",
")",
"\n",
"case",
"*",
"image",
".",
"RGBA",
":",
"err",
"=",
"encodeRGBA",
"(",
"cinfo",
",",
"s",
",",
"opt",
")",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// Encode encodes src image and writes into w as JPEG format data.
|
[
"Encode",
"encodes",
"src",
"image",
"and",
"writes",
"into",
"w",
"as",
"JPEG",
"format",
"data",
"."
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/compress.go#L103-L133
|
16,916 |
pixiv/go-libjpeg
|
jpeg/compress.go
|
encodeYCbCr
|
func encodeYCbCr(cinfo *C.struct_jpeg_compress_struct, src *image.YCbCr, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 3
cinfo.in_color_space = C.JCS_YCbCr
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
compInfo := (*[3]C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info))
colorVDiv := 1
switch src.SubsampleRatio {
case image.YCbCrSubsampleRatio444:
// 1x1,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 1
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
case image.YCbCrSubsampleRatio440:
// 1x2,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 2
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
colorVDiv = 2
case image.YCbCrSubsampleRatio422:
// 2x1,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 1
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
case image.YCbCrSubsampleRatio420:
// 2x2,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 2
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
colorVDiv = 2
}
// libjpeg raw data in is in planar format, which avoids unnecessary
// planar->packed->planar conversions.
cinfo.raw_data_in = C.TRUE
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_ycbcr(
cinfo,
C.JSAMPROW(unsafe.Pointer(&src.Y[0])),
C.JSAMPROW(unsafe.Pointer(&src.Cb[0])),
C.JSAMPROW(unsafe.Pointer(&src.Cr[0])),
C.int(src.YStride),
C.int(src.CStride),
C.int(colorVDiv),
)
C.jpeg_finish_compress(cinfo)
return
}
|
go
|
func encodeYCbCr(cinfo *C.struct_jpeg_compress_struct, src *image.YCbCr, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 3
cinfo.in_color_space = C.JCS_YCbCr
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
compInfo := (*[3]C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info))
colorVDiv := 1
switch src.SubsampleRatio {
case image.YCbCrSubsampleRatio444:
// 1x1,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 1
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
case image.YCbCrSubsampleRatio440:
// 1x2,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 2
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
colorVDiv = 2
case image.YCbCrSubsampleRatio422:
// 2x1,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 1
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
case image.YCbCrSubsampleRatio420:
// 2x2,1x1,1x1
compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 2, 2
compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
colorVDiv = 2
}
// libjpeg raw data in is in planar format, which avoids unnecessary
// planar->packed->planar conversions.
cinfo.raw_data_in = C.TRUE
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_ycbcr(
cinfo,
C.JSAMPROW(unsafe.Pointer(&src.Y[0])),
C.JSAMPROW(unsafe.Pointer(&src.Cb[0])),
C.JSAMPROW(unsafe.Pointer(&src.Cr[0])),
C.int(src.YStride),
C.int(src.CStride),
C.int(colorVDiv),
)
C.jpeg_finish_compress(cinfo)
return
}
|
[
"func",
"encodeYCbCr",
"(",
"cinfo",
"*",
"C",
".",
"struct_jpeg_compress_struct",
",",
"src",
"*",
"image",
".",
"YCbCr",
",",
"p",
"*",
"EncoderOptions",
")",
"(",
"err",
"error",
")",
"{",
"// Set up compression parameters",
"cinfo",
".",
"image_width",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
")",
"\n",
"cinfo",
".",
"image_height",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
")",
"\n",
"cinfo",
".",
"input_components",
"=",
"3",
"\n",
"cinfo",
".",
"in_color_space",
"=",
"C",
".",
"JCS_YCbCr",
"\n\n",
"C",
".",
"jpeg_set_defaults",
"(",
"cinfo",
")",
"\n",
"setupEncoderOptions",
"(",
"cinfo",
",",
"p",
")",
"\n\n",
"compInfo",
":=",
"(",
"*",
"[",
"3",
"]",
"C",
".",
"jpeg_component_info",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"cinfo",
".",
"comp_info",
")",
")",
"\n",
"colorVDiv",
":=",
"1",
"\n",
"switch",
"src",
".",
"SubsampleRatio",
"{",
"case",
"image",
".",
"YCbCrSubsampleRatio444",
":",
"// 1x1,1x1,1x1",
"compInfo",
"[",
"Y",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Y",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"compInfo",
"[",
"Cb",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cb",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"compInfo",
"[",
"Cr",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cr",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"case",
"image",
".",
"YCbCrSubsampleRatio440",
":",
"// 1x2,1x1,1x1",
"compInfo",
"[",
"Y",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Y",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"2",
"\n",
"compInfo",
"[",
"Cb",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cb",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"compInfo",
"[",
"Cr",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cr",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"colorVDiv",
"=",
"2",
"\n",
"case",
"image",
".",
"YCbCrSubsampleRatio422",
":",
"// 2x1,1x1,1x1",
"compInfo",
"[",
"Y",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Y",
"]",
".",
"v_samp_factor",
"=",
"2",
",",
"1",
"\n",
"compInfo",
"[",
"Cb",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cb",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"compInfo",
"[",
"Cr",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cr",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"case",
"image",
".",
"YCbCrSubsampleRatio420",
":",
"// 2x2,1x1,1x1",
"compInfo",
"[",
"Y",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Y",
"]",
".",
"v_samp_factor",
"=",
"2",
",",
"2",
"\n",
"compInfo",
"[",
"Cb",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cb",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"compInfo",
"[",
"Cr",
"]",
".",
"h_samp_factor",
",",
"compInfo",
"[",
"Cr",
"]",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n",
"colorVDiv",
"=",
"2",
"\n",
"}",
"\n\n",
"// libjpeg raw data in is in planar format, which avoids unnecessary",
"// planar->packed->planar conversions.",
"cinfo",
".",
"raw_data_in",
"=",
"C",
".",
"TRUE",
"\n\n",
"// Start compression",
"C",
".",
"jpeg_start_compress",
"(",
"cinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"C",
".",
"encode_ycbcr",
"(",
"cinfo",
",",
"C",
".",
"JSAMPROW",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
".",
"Y",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"JSAMPROW",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
".",
"Cb",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"JSAMPROW",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
".",
"Cr",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"int",
"(",
"src",
".",
"YStride",
")",
",",
"C",
".",
"int",
"(",
"src",
".",
"CStride",
")",
",",
"C",
".",
"int",
"(",
"colorVDiv",
")",
",",
")",
"\n",
"C",
".",
"jpeg_finish_compress",
"(",
"cinfo",
")",
"\n",
"return",
"\n",
"}"
] |
// encode image.YCbCr
|
[
"encode",
"image",
".",
"YCbCr"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/compress.go#L136-L190
|
16,917 |
pixiv/go-libjpeg
|
jpeg/compress.go
|
encodeRGBA
|
func encodeRGBA(cinfo *C.struct_jpeg_compress_struct, src *image.RGBA, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 4
cinfo.in_color_space = getJCS_EXT_RGBA()
if cinfo.in_color_space == C.JCS_UNKNOWN {
return errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)")
}
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_rgba(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride))
C.jpeg_finish_compress(cinfo)
return
}
|
go
|
func encodeRGBA(cinfo *C.struct_jpeg_compress_struct, src *image.RGBA, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 4
cinfo.in_color_space = getJCS_EXT_RGBA()
if cinfo.in_color_space == C.JCS_UNKNOWN {
return errors.New("JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)")
}
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_rgba(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride))
C.jpeg_finish_compress(cinfo)
return
}
|
[
"func",
"encodeRGBA",
"(",
"cinfo",
"*",
"C",
".",
"struct_jpeg_compress_struct",
",",
"src",
"*",
"image",
".",
"RGBA",
",",
"p",
"*",
"EncoderOptions",
")",
"(",
"err",
"error",
")",
"{",
"// Set up compression parameters",
"cinfo",
".",
"image_width",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
")",
"\n",
"cinfo",
".",
"image_height",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
")",
"\n",
"cinfo",
".",
"input_components",
"=",
"4",
"\n",
"cinfo",
".",
"in_color_space",
"=",
"getJCS_EXT_RGBA",
"(",
")",
"\n",
"if",
"cinfo",
".",
"in_color_space",
"==",
"C",
".",
"JCS_UNKNOWN",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"C",
".",
"jpeg_set_defaults",
"(",
"cinfo",
")",
"\n",
"setupEncoderOptions",
"(",
"cinfo",
",",
"p",
")",
"\n\n",
"// Start compression",
"C",
".",
"jpeg_start_compress",
"(",
"cinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"C",
".",
"encode_rgba",
"(",
"cinfo",
",",
"C",
".",
"JSAMPROW",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
".",
"Pix",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"int",
"(",
"src",
".",
"Stride",
")",
")",
"\n",
"C",
".",
"jpeg_finish_compress",
"(",
"cinfo",
")",
"\n",
"return",
"\n",
"}"
] |
// encode image.RGBA
|
[
"encode",
"image",
".",
"RGBA"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/compress.go#L193-L211
|
16,918 |
pixiv/go-libjpeg
|
jpeg/compress.go
|
encodeGray
|
func encodeGray(cinfo *C.struct_jpeg_compress_struct, src *image.Gray, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 1
cinfo.in_color_space = C.JCS_GRAYSCALE
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
compInfo := (*C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info))
compInfo.h_samp_factor, compInfo.v_samp_factor = 1, 1
// libjpeg raw data in is in planar format, which avoids unnecessary
// planar->packed->planar conversions.
cinfo.raw_data_in = C.TRUE
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_gray(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride))
C.jpeg_finish_compress(cinfo)
return
}
|
go
|
func encodeGray(cinfo *C.struct_jpeg_compress_struct, src *image.Gray, p *EncoderOptions) (err error) {
// Set up compression parameters
cinfo.image_width = C.JDIMENSION(src.Bounds().Dx())
cinfo.image_height = C.JDIMENSION(src.Bounds().Dy())
cinfo.input_components = 1
cinfo.in_color_space = C.JCS_GRAYSCALE
C.jpeg_set_defaults(cinfo)
setupEncoderOptions(cinfo, p)
compInfo := (*C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info))
compInfo.h_samp_factor, compInfo.v_samp_factor = 1, 1
// libjpeg raw data in is in planar format, which avoids unnecessary
// planar->packed->planar conversions.
cinfo.raw_data_in = C.TRUE
// Start compression
C.jpeg_start_compress(cinfo, C.TRUE)
C.encode_gray(cinfo, C.JSAMPROW(unsafe.Pointer(&src.Pix[0])), C.int(src.Stride))
C.jpeg_finish_compress(cinfo)
return
}
|
[
"func",
"encodeGray",
"(",
"cinfo",
"*",
"C",
".",
"struct_jpeg_compress_struct",
",",
"src",
"*",
"image",
".",
"Gray",
",",
"p",
"*",
"EncoderOptions",
")",
"(",
"err",
"error",
")",
"{",
"// Set up compression parameters",
"cinfo",
".",
"image_width",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dx",
"(",
")",
")",
"\n",
"cinfo",
".",
"image_height",
"=",
"C",
".",
"JDIMENSION",
"(",
"src",
".",
"Bounds",
"(",
")",
".",
"Dy",
"(",
")",
")",
"\n",
"cinfo",
".",
"input_components",
"=",
"1",
"\n",
"cinfo",
".",
"in_color_space",
"=",
"C",
".",
"JCS_GRAYSCALE",
"\n\n",
"C",
".",
"jpeg_set_defaults",
"(",
"cinfo",
")",
"\n",
"setupEncoderOptions",
"(",
"cinfo",
",",
"p",
")",
"\n\n",
"compInfo",
":=",
"(",
"*",
"C",
".",
"jpeg_component_info",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"cinfo",
".",
"comp_info",
")",
")",
"\n",
"compInfo",
".",
"h_samp_factor",
",",
"compInfo",
".",
"v_samp_factor",
"=",
"1",
",",
"1",
"\n\n",
"// libjpeg raw data in is in planar format, which avoids unnecessary",
"// planar->packed->planar conversions.",
"cinfo",
".",
"raw_data_in",
"=",
"C",
".",
"TRUE",
"\n\n",
"// Start compression",
"C",
".",
"jpeg_start_compress",
"(",
"cinfo",
",",
"C",
".",
"TRUE",
")",
"\n",
"C",
".",
"encode_gray",
"(",
"cinfo",
",",
"C",
".",
"JSAMPROW",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
".",
"Pix",
"[",
"0",
"]",
")",
")",
",",
"C",
".",
"int",
"(",
"src",
".",
"Stride",
")",
")",
"\n",
"C",
".",
"jpeg_finish_compress",
"(",
"cinfo",
")",
"\n",
"return",
"\n",
"}"
] |
// encode image.Gray
|
[
"encode",
"image",
".",
"Gray"
] |
8a5e68b6ebaa424cd3916c4d1309b618318e9367
|
https://github.com/pixiv/go-libjpeg/blob/8a5e68b6ebaa424cd3916c4d1309b618318e9367/jpeg/compress.go#L214-L236
|
16,919 |
gambol99/go-marathon
|
residency.go
|
SetTaskLostBehavior
|
func (r *Residency) SetTaskLostBehavior(behavior TaskLostBehaviorType) *Residency {
r.TaskLostBehavior = behavior
return r
}
|
go
|
func (r *Residency) SetTaskLostBehavior(behavior TaskLostBehaviorType) *Residency {
r.TaskLostBehavior = behavior
return r
}
|
[
"func",
"(",
"r",
"*",
"Residency",
")",
"SetTaskLostBehavior",
"(",
"behavior",
"TaskLostBehaviorType",
")",
"*",
"Residency",
"{",
"r",
".",
"TaskLostBehavior",
"=",
"behavior",
"\n",
"return",
"r",
"\n",
"}"
] |
// SetTaskLostBehavior sets the residency behavior
|
[
"SetTaskLostBehavior",
"sets",
"the",
"residency",
"behavior"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/residency.go#L39-L42
|
16,920 |
gambol99/go-marathon
|
residency.go
|
SetRelaunchEscalationTimeout
|
func (r *Residency) SetRelaunchEscalationTimeout(timeout time.Duration) *Residency {
r.RelaunchEscalationTimeoutSeconds = int(timeout.Seconds())
return r
}
|
go
|
func (r *Residency) SetRelaunchEscalationTimeout(timeout time.Duration) *Residency {
r.RelaunchEscalationTimeoutSeconds = int(timeout.Seconds())
return r
}
|
[
"func",
"(",
"r",
"*",
"Residency",
")",
"SetRelaunchEscalationTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Residency",
"{",
"r",
".",
"RelaunchEscalationTimeoutSeconds",
"=",
"int",
"(",
"timeout",
".",
"Seconds",
"(",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// SetRelaunchEscalationTimeout sets the residency relaunch escalation timeout with seconds precision
|
[
"SetRelaunchEscalationTimeout",
"sets",
"the",
"residency",
"relaunch",
"escalation",
"timeout",
"with",
"seconds",
"precision"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/residency.go#L45-L48
|
16,921 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetBackoff
|
func (p *PodBackoff) SetBackoff(backoffSeconds int) *PodBackoff {
p.Backoff = &backoffSeconds
return p
}
|
go
|
func (p *PodBackoff) SetBackoff(backoffSeconds int) *PodBackoff {
p.Backoff = &backoffSeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodBackoff",
")",
"SetBackoff",
"(",
"backoffSeconds",
"int",
")",
"*",
"PodBackoff",
"{",
"p",
".",
"Backoff",
"=",
"&",
"backoffSeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetBackoff sets the base backoff interval for failed pod launches, in seconds
|
[
"SetBackoff",
"sets",
"the",
"base",
"backoff",
"interval",
"for",
"failed",
"pod",
"launches",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L90-L93
|
16,922 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetBackoffFactor
|
func (p *PodBackoff) SetBackoffFactor(backoffFactor float64) *PodBackoff {
p.BackoffFactor = &backoffFactor
return p
}
|
go
|
func (p *PodBackoff) SetBackoffFactor(backoffFactor float64) *PodBackoff {
p.BackoffFactor = &backoffFactor
return p
}
|
[
"func",
"(",
"p",
"*",
"PodBackoff",
")",
"SetBackoffFactor",
"(",
"backoffFactor",
"float64",
")",
"*",
"PodBackoff",
"{",
"p",
".",
"BackoffFactor",
"=",
"&",
"backoffFactor",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetBackoffFactor sets the backoff interval growth factor for failed pod launches
|
[
"SetBackoffFactor",
"sets",
"the",
"backoff",
"interval",
"growth",
"factor",
"for",
"failed",
"pod",
"launches"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L96-L99
|
16,923 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetMaxLaunchDelay
|
func (p *PodBackoff) SetMaxLaunchDelay(maxLaunchDelaySeconds int) *PodBackoff {
p.MaxLaunchDelay = &maxLaunchDelaySeconds
return p
}
|
go
|
func (p *PodBackoff) SetMaxLaunchDelay(maxLaunchDelaySeconds int) *PodBackoff {
p.MaxLaunchDelay = &maxLaunchDelaySeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodBackoff",
")",
"SetMaxLaunchDelay",
"(",
"maxLaunchDelaySeconds",
"int",
")",
"*",
"PodBackoff",
"{",
"p",
".",
"MaxLaunchDelay",
"=",
"&",
"maxLaunchDelaySeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetMaxLaunchDelay sets the maximum backoff interval for failed pod launches, in seconds
|
[
"SetMaxLaunchDelay",
"sets",
"the",
"maximum",
"backoff",
"interval",
"for",
"failed",
"pod",
"launches",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L102-L105
|
16,924 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetMinimumHealthCapacity
|
func (p *PodUpgrade) SetMinimumHealthCapacity(capacity float64) *PodUpgrade {
p.MinimumHealthCapacity = &capacity
return p
}
|
go
|
func (p *PodUpgrade) SetMinimumHealthCapacity(capacity float64) *PodUpgrade {
p.MinimumHealthCapacity = &capacity
return p
}
|
[
"func",
"(",
"p",
"*",
"PodUpgrade",
")",
"SetMinimumHealthCapacity",
"(",
"capacity",
"float64",
")",
"*",
"PodUpgrade",
"{",
"p",
".",
"MinimumHealthCapacity",
"=",
"&",
"capacity",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetMinimumHealthCapacity sets the minimum amount of pod instances for healthy operation, expressed as a fraction of instance count
|
[
"SetMinimumHealthCapacity",
"sets",
"the",
"minimum",
"amount",
"of",
"pod",
"instances",
"for",
"healthy",
"operation",
"expressed",
"as",
"a",
"fraction",
"of",
"instance",
"count"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L108-L111
|
16,925 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetMaximumOverCapacity
|
func (p *PodUpgrade) SetMaximumOverCapacity(capacity float64) *PodUpgrade {
p.MaximumOverCapacity = &capacity
return p
}
|
go
|
func (p *PodUpgrade) SetMaximumOverCapacity(capacity float64) *PodUpgrade {
p.MaximumOverCapacity = &capacity
return p
}
|
[
"func",
"(",
"p",
"*",
"PodUpgrade",
")",
"SetMaximumOverCapacity",
"(",
"capacity",
"float64",
")",
"*",
"PodUpgrade",
"{",
"p",
".",
"MaximumOverCapacity",
"=",
"&",
"capacity",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetMaximumOverCapacity sets the maximum amount of pod instances above the instance count, expressed as a fraction of instance count
|
[
"SetMaximumOverCapacity",
"sets",
"the",
"maximum",
"amount",
"of",
"pod",
"instances",
"above",
"the",
"instance",
"count",
"expressed",
"as",
"a",
"fraction",
"of",
"instance",
"count"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L114-L117
|
16,926 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetBackoff
|
func (p *PodSchedulingPolicy) SetBackoff(backoff *PodBackoff) *PodSchedulingPolicy {
p.Backoff = backoff
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetBackoff(backoff *PodBackoff) *PodSchedulingPolicy {
p.Backoff = backoff
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetBackoff",
"(",
"backoff",
"*",
"PodBackoff",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"Backoff",
"=",
"backoff",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetBackoff sets the pod's backoff settings
|
[
"SetBackoff",
"sets",
"the",
"pod",
"s",
"backoff",
"settings"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L120-L123
|
16,927 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetUpgrade
|
func (p *PodSchedulingPolicy) SetUpgrade(upgrade *PodUpgrade) *PodSchedulingPolicy {
p.Upgrade = upgrade
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetUpgrade(upgrade *PodUpgrade) *PodSchedulingPolicy {
p.Upgrade = upgrade
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetUpgrade",
"(",
"upgrade",
"*",
"PodUpgrade",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"Upgrade",
"=",
"upgrade",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetUpgrade sets the pod's upgrade settings
|
[
"SetUpgrade",
"sets",
"the",
"pod",
"s",
"upgrade",
"settings"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L126-L129
|
16,928 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetPlacement
|
func (p *PodSchedulingPolicy) SetPlacement(placement *PodPlacement) *PodSchedulingPolicy {
p.Placement = placement
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetPlacement(placement *PodPlacement) *PodSchedulingPolicy {
p.Placement = placement
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetPlacement",
"(",
"placement",
"*",
"PodPlacement",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"Placement",
"=",
"placement",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetPlacement sets the pod's placement settings
|
[
"SetPlacement",
"sets",
"the",
"pod",
"s",
"placement",
"settings"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L132-L135
|
16,929 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetKillSelection
|
func (p *PodSchedulingPolicy) SetKillSelection(killSelection string) *PodSchedulingPolicy {
p.KillSelection = killSelection
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetKillSelection(killSelection string) *PodSchedulingPolicy {
p.KillSelection = killSelection
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetKillSelection",
"(",
"killSelection",
"string",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"KillSelection",
"=",
"killSelection",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetKillSelection sets the pod's kill selection criteria when terminating pod instances
|
[
"SetKillSelection",
"sets",
"the",
"pod",
"s",
"kill",
"selection",
"criteria",
"when",
"terminating",
"pod",
"instances"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L138-L141
|
16,930 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetUnreachableStrategy
|
func (p *PodSchedulingPolicy) SetUnreachableStrategy(strategy EnabledUnreachableStrategy) *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
EnabledUnreachableStrategy: strategy,
}
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetUnreachableStrategy(strategy EnabledUnreachableStrategy) *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
EnabledUnreachableStrategy: strategy,
}
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetUnreachableStrategy",
"(",
"strategy",
"EnabledUnreachableStrategy",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"UnreachableStrategy",
"=",
"&",
"UnreachableStrategy",
"{",
"EnabledUnreachableStrategy",
":",
"strategy",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetUnreachableStrategy sets the pod's unreachable strategy for lost instances
|
[
"SetUnreachableStrategy",
"sets",
"the",
"pod",
"s",
"unreachable",
"strategy",
"for",
"lost",
"instances"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L144-L149
|
16,931 |
gambol99/go-marathon
|
pod_scheduling.go
|
SetUnreachableStrategyDisabled
|
func (p *PodSchedulingPolicy) SetUnreachableStrategyDisabled() *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
AbsenceReason: UnreachableStrategyAbsenceReasonDisabled,
}
return p
}
|
go
|
func (p *PodSchedulingPolicy) SetUnreachableStrategyDisabled() *PodSchedulingPolicy {
p.UnreachableStrategy = &UnreachableStrategy{
AbsenceReason: UnreachableStrategyAbsenceReasonDisabled,
}
return p
}
|
[
"func",
"(",
"p",
"*",
"PodSchedulingPolicy",
")",
"SetUnreachableStrategyDisabled",
"(",
")",
"*",
"PodSchedulingPolicy",
"{",
"p",
".",
"UnreachableStrategy",
"=",
"&",
"UnreachableStrategy",
"{",
"AbsenceReason",
":",
"UnreachableStrategyAbsenceReasonDisabled",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetUnreachableStrategyDisabled disables the pod's unreachable strategy
|
[
"SetUnreachableStrategyDisabled",
"disables",
"the",
"pod",
"s",
"unreachable",
"strategy"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_scheduling.go#L152-L157
|
16,932 |
gambol99/go-marathon
|
unreachable_strategy.go
|
UnmarshalJSON
|
func (us *UnreachableStrategy) UnmarshalJSON(b []byte) error {
var u unreachableStrategy
var errEnabledUS, errNonEnabledUS error
if errEnabledUS = json.Unmarshal(b, &u); errEnabledUS == nil {
*us = UnreachableStrategy(u)
return nil
}
if errNonEnabledUS = json.Unmarshal(b, &us.AbsenceReason); errNonEnabledUS == nil {
return nil
}
return fmt.Errorf("failed to unmarshal unreachable strategy: unmarshaling into enabled returned error '%s'; unmarshaling into non-enabled returned error '%s'", errEnabledUS, errNonEnabledUS)
}
|
go
|
func (us *UnreachableStrategy) UnmarshalJSON(b []byte) error {
var u unreachableStrategy
var errEnabledUS, errNonEnabledUS error
if errEnabledUS = json.Unmarshal(b, &u); errEnabledUS == nil {
*us = UnreachableStrategy(u)
return nil
}
if errNonEnabledUS = json.Unmarshal(b, &us.AbsenceReason); errNonEnabledUS == nil {
return nil
}
return fmt.Errorf("failed to unmarshal unreachable strategy: unmarshaling into enabled returned error '%s'; unmarshaling into non-enabled returned error '%s'", errEnabledUS, errNonEnabledUS)
}
|
[
"func",
"(",
"us",
"*",
"UnreachableStrategy",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"u",
"unreachableStrategy",
"\n",
"var",
"errEnabledUS",
",",
"errNonEnabledUS",
"error",
"\n",
"if",
"errEnabledUS",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"u",
")",
";",
"errEnabledUS",
"==",
"nil",
"{",
"*",
"us",
"=",
"UnreachableStrategy",
"(",
"u",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"errNonEnabledUS",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"us",
".",
"AbsenceReason",
")",
";",
"errNonEnabledUS",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errEnabledUS",
",",
"errNonEnabledUS",
")",
"\n",
"}"
] |
// UnmarshalJSON unmarshals the given JSON into an UnreachableStrategy. It
// populates parameters for present strategies, and otherwise only sets the
// absence reason.
|
[
"UnmarshalJSON",
"unmarshals",
"the",
"given",
"JSON",
"into",
"an",
"UnreachableStrategy",
".",
"It",
"populates",
"parameters",
"for",
"present",
"strategies",
"and",
"otherwise",
"only",
"sets",
"the",
"absence",
"reason",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/unreachable_strategy.go#L44-L57
|
16,933 |
gambol99/go-marathon
|
unreachable_strategy.go
|
MarshalJSON
|
func (us *UnreachableStrategy) MarshalJSON() ([]byte, error) {
if us.AbsenceReason == "" {
return json.Marshal(us.EnabledUnreachableStrategy)
}
return json.Marshal(us.AbsenceReason)
}
|
go
|
func (us *UnreachableStrategy) MarshalJSON() ([]byte, error) {
if us.AbsenceReason == "" {
return json.Marshal(us.EnabledUnreachableStrategy)
}
return json.Marshal(us.AbsenceReason)
}
|
[
"func",
"(",
"us",
"*",
"UnreachableStrategy",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"us",
".",
"AbsenceReason",
"==",
"\"",
"\"",
"{",
"return",
"json",
".",
"Marshal",
"(",
"us",
".",
"EnabledUnreachableStrategy",
")",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"us",
".",
"AbsenceReason",
")",
"\n",
"}"
] |
// MarshalJSON marshals the unreachable strategy.
|
[
"MarshalJSON",
"marshals",
"the",
"unreachable",
"strategy",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/unreachable_strategy.go#L60-L66
|
16,934 |
gambol99/go-marathon
|
unreachable_strategy.go
|
SetInactiveAfterSeconds
|
func (us *UnreachableStrategy) SetInactiveAfterSeconds(cap float64) *UnreachableStrategy {
us.InactiveAfterSeconds = &cap
return us
}
|
go
|
func (us *UnreachableStrategy) SetInactiveAfterSeconds(cap float64) *UnreachableStrategy {
us.InactiveAfterSeconds = &cap
return us
}
|
[
"func",
"(",
"us",
"*",
"UnreachableStrategy",
")",
"SetInactiveAfterSeconds",
"(",
"cap",
"float64",
")",
"*",
"UnreachableStrategy",
"{",
"us",
".",
"InactiveAfterSeconds",
"=",
"&",
"cap",
"\n",
"return",
"us",
"\n",
"}"
] |
// SetInactiveAfterSeconds sets the period after which instance will be marked as inactive.
|
[
"SetInactiveAfterSeconds",
"sets",
"the",
"period",
"after",
"which",
"instance",
"will",
"be",
"marked",
"as",
"inactive",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/unreachable_strategy.go#L69-L72
|
16,935 |
gambol99/go-marathon
|
unreachable_strategy.go
|
SetExpungeAfterSeconds
|
func (us *UnreachableStrategy) SetExpungeAfterSeconds(cap float64) *UnreachableStrategy {
us.ExpungeAfterSeconds = &cap
return us
}
|
go
|
func (us *UnreachableStrategy) SetExpungeAfterSeconds(cap float64) *UnreachableStrategy {
us.ExpungeAfterSeconds = &cap
return us
}
|
[
"func",
"(",
"us",
"*",
"UnreachableStrategy",
")",
"SetExpungeAfterSeconds",
"(",
"cap",
"float64",
")",
"*",
"UnreachableStrategy",
"{",
"us",
".",
"ExpungeAfterSeconds",
"=",
"&",
"cap",
"\n",
"return",
"us",
"\n",
"}"
] |
// SetExpungeAfterSeconds sets the period after which instance will be expunged.
|
[
"SetExpungeAfterSeconds",
"sets",
"the",
"period",
"after",
"which",
"instance",
"will",
"be",
"expunged",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/unreachable_strategy.go#L75-L78
|
16,936 |
gambol99/go-marathon
|
health.go
|
SetCommand
|
func (h *HealthCheck) SetCommand(c Command) *HealthCheck {
h.Command = &c
return h
}
|
go
|
func (h *HealthCheck) SetCommand(c Command) *HealthCheck {
h.Command = &c
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetCommand",
"(",
"c",
"Command",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"Command",
"=",
"&",
"c",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetCommand sets the given command on the health check.
|
[
"SetCommand",
"sets",
"the",
"given",
"command",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L83-L86
|
16,937 |
gambol99/go-marathon
|
health.go
|
SetPortIndex
|
func (h *HealthCheck) SetPortIndex(i int) *HealthCheck {
h.PortIndex = &i
return h
}
|
go
|
func (h *HealthCheck) SetPortIndex(i int) *HealthCheck {
h.PortIndex = &i
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetPortIndex",
"(",
"i",
"int",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"PortIndex",
"=",
"&",
"i",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetPortIndex sets the given port index on the health check.
|
[
"SetPortIndex",
"sets",
"the",
"given",
"port",
"index",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L89-L92
|
16,938 |
gambol99/go-marathon
|
health.go
|
SetPort
|
func (h *HealthCheck) SetPort(i int) *HealthCheck {
h.Port = &i
return h
}
|
go
|
func (h *HealthCheck) SetPort(i int) *HealthCheck {
h.Port = &i
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetPort",
"(",
"i",
"int",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"Port",
"=",
"&",
"i",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetPort sets the given port on the health check.
|
[
"SetPort",
"sets",
"the",
"given",
"port",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L95-L98
|
16,939 |
gambol99/go-marathon
|
health.go
|
SetPath
|
func (h *HealthCheck) SetPath(p string) *HealthCheck {
h.Path = &p
return h
}
|
go
|
func (h *HealthCheck) SetPath(p string) *HealthCheck {
h.Path = &p
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetPath",
"(",
"p",
"string",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"Path",
"=",
"&",
"p",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetPath sets the given path on the health check.
|
[
"SetPath",
"sets",
"the",
"given",
"path",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L101-L104
|
16,940 |
gambol99/go-marathon
|
health.go
|
SetMaxConsecutiveFailures
|
func (h *HealthCheck) SetMaxConsecutiveFailures(i int) *HealthCheck {
h.MaxConsecutiveFailures = &i
return h
}
|
go
|
func (h *HealthCheck) SetMaxConsecutiveFailures(i int) *HealthCheck {
h.MaxConsecutiveFailures = &i
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetMaxConsecutiveFailures",
"(",
"i",
"int",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"MaxConsecutiveFailures",
"=",
"&",
"i",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetMaxConsecutiveFailures sets the maximum consecutive failures on the health check.
|
[
"SetMaxConsecutiveFailures",
"sets",
"the",
"maximum",
"consecutive",
"failures",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L107-L110
|
16,941 |
gambol99/go-marathon
|
health.go
|
SetIgnoreHTTP1xx
|
func (h *HealthCheck) SetIgnoreHTTP1xx(ignore bool) *HealthCheck {
h.IgnoreHTTP1xx = &ignore
return h
}
|
go
|
func (h *HealthCheck) SetIgnoreHTTP1xx(ignore bool) *HealthCheck {
h.IgnoreHTTP1xx = &ignore
return h
}
|
[
"func",
"(",
"h",
"*",
"HealthCheck",
")",
"SetIgnoreHTTP1xx",
"(",
"ignore",
"bool",
")",
"*",
"HealthCheck",
"{",
"h",
".",
"IgnoreHTTP1xx",
"=",
"&",
"ignore",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetIgnoreHTTP1xx sets ignore http 1xx on the health check.
|
[
"SetIgnoreHTTP1xx",
"sets",
"ignore",
"http",
"1xx",
"on",
"the",
"health",
"check",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L113-L116
|
16,942 |
gambol99/go-marathon
|
health.go
|
NewDefaultHealthCheck
|
func NewDefaultHealthCheck() *HealthCheck {
portIndex := 0
path := ""
maxConsecutiveFailures := 3
return &HealthCheck{
Protocol: "HTTP",
Path: &path,
PortIndex: &portIndex,
MaxConsecutiveFailures: &maxConsecutiveFailures,
GracePeriodSeconds: 30,
IntervalSeconds: 10,
TimeoutSeconds: 5,
}
}
|
go
|
func NewDefaultHealthCheck() *HealthCheck {
portIndex := 0
path := ""
maxConsecutiveFailures := 3
return &HealthCheck{
Protocol: "HTTP",
Path: &path,
PortIndex: &portIndex,
MaxConsecutiveFailures: &maxConsecutiveFailures,
GracePeriodSeconds: 30,
IntervalSeconds: 10,
TimeoutSeconds: 5,
}
}
|
[
"func",
"NewDefaultHealthCheck",
"(",
")",
"*",
"HealthCheck",
"{",
"portIndex",
":=",
"0",
"\n",
"path",
":=",
"\"",
"\"",
"\n",
"maxConsecutiveFailures",
":=",
"3",
"\n\n",
"return",
"&",
"HealthCheck",
"{",
"Protocol",
":",
"\"",
"\"",
",",
"Path",
":",
"&",
"path",
",",
"PortIndex",
":",
"&",
"portIndex",
",",
"MaxConsecutiveFailures",
":",
"&",
"maxConsecutiveFailures",
",",
"GracePeriodSeconds",
":",
"30",
",",
"IntervalSeconds",
":",
"10",
",",
"TimeoutSeconds",
":",
"5",
",",
"}",
"\n",
"}"
] |
// NewDefaultHealthCheck creates a default application health check
|
[
"NewDefaultHealthCheck",
"creates",
"a",
"default",
"application",
"health",
"check"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L119-L133
|
16,943 |
gambol99/go-marathon
|
health.go
|
SetGracePeriod
|
func (p *PodHealthCheck) SetGracePeriod(gracePeriodSeconds int) *PodHealthCheck {
p.GracePeriodSeconds = &gracePeriodSeconds
return p
}
|
go
|
func (p *PodHealthCheck) SetGracePeriod(gracePeriodSeconds int) *PodHealthCheck {
p.GracePeriodSeconds = &gracePeriodSeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodHealthCheck",
")",
"SetGracePeriod",
"(",
"gracePeriodSeconds",
"int",
")",
"*",
"PodHealthCheck",
"{",
"p",
".",
"GracePeriodSeconds",
"=",
"&",
"gracePeriodSeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetGracePeriod sets the health check initial grace period, in seconds
|
[
"SetGracePeriod",
"sets",
"the",
"health",
"check",
"initial",
"grace",
"period",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L179-L182
|
16,944 |
gambol99/go-marathon
|
health.go
|
SetInterval
|
func (p *PodHealthCheck) SetInterval(intervalSeconds int) *PodHealthCheck {
p.IntervalSeconds = &intervalSeconds
return p
}
|
go
|
func (p *PodHealthCheck) SetInterval(intervalSeconds int) *PodHealthCheck {
p.IntervalSeconds = &intervalSeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodHealthCheck",
")",
"SetInterval",
"(",
"intervalSeconds",
"int",
")",
"*",
"PodHealthCheck",
"{",
"p",
".",
"IntervalSeconds",
"=",
"&",
"intervalSeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetInterval sets the health check polling interval, in seconds
|
[
"SetInterval",
"sets",
"the",
"health",
"check",
"polling",
"interval",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L185-L188
|
16,945 |
gambol99/go-marathon
|
health.go
|
SetMaxConsecutiveFailures
|
func (p *PodHealthCheck) SetMaxConsecutiveFailures(maxFailures int) *PodHealthCheck {
p.MaxConsecutiveFailures = &maxFailures
return p
}
|
go
|
func (p *PodHealthCheck) SetMaxConsecutiveFailures(maxFailures int) *PodHealthCheck {
p.MaxConsecutiveFailures = &maxFailures
return p
}
|
[
"func",
"(",
"p",
"*",
"PodHealthCheck",
")",
"SetMaxConsecutiveFailures",
"(",
"maxFailures",
"int",
")",
"*",
"PodHealthCheck",
"{",
"p",
".",
"MaxConsecutiveFailures",
"=",
"&",
"maxFailures",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetMaxConsecutiveFailures sets the maximum consecutive failures on the health check
|
[
"SetMaxConsecutiveFailures",
"sets",
"the",
"maximum",
"consecutive",
"failures",
"on",
"the",
"health",
"check"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L191-L194
|
16,946 |
gambol99/go-marathon
|
health.go
|
SetTimeout
|
func (p *PodHealthCheck) SetTimeout(timeoutSeconds int) *PodHealthCheck {
p.TimeoutSeconds = &timeoutSeconds
return p
}
|
go
|
func (p *PodHealthCheck) SetTimeout(timeoutSeconds int) *PodHealthCheck {
p.TimeoutSeconds = &timeoutSeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodHealthCheck",
")",
"SetTimeout",
"(",
"timeoutSeconds",
"int",
")",
"*",
"PodHealthCheck",
"{",
"p",
".",
"TimeoutSeconds",
"=",
"&",
"timeoutSeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetTimeout sets the length of time the health check will await a result, in seconds
|
[
"SetTimeout",
"sets",
"the",
"length",
"of",
"time",
"the",
"health",
"check",
"will",
"await",
"a",
"result",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L197-L200
|
16,947 |
gambol99/go-marathon
|
health.go
|
SetDelay
|
func (p *PodHealthCheck) SetDelay(delaySeconds int) *PodHealthCheck {
p.DelaySeconds = &delaySeconds
return p
}
|
go
|
func (p *PodHealthCheck) SetDelay(delaySeconds int) *PodHealthCheck {
p.DelaySeconds = &delaySeconds
return p
}
|
[
"func",
"(",
"p",
"*",
"PodHealthCheck",
")",
"SetDelay",
"(",
"delaySeconds",
"int",
")",
"*",
"PodHealthCheck",
"{",
"p",
".",
"DelaySeconds",
"=",
"&",
"delaySeconds",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetDelay sets the length of time a pod will delay running health checks on initial launch, in seconds
|
[
"SetDelay",
"sets",
"the",
"length",
"of",
"time",
"a",
"pod",
"will",
"delay",
"running",
"health",
"checks",
"on",
"initial",
"launch",
"in",
"seconds"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L203-L206
|
16,948 |
gambol99/go-marathon
|
health.go
|
SetPath
|
func (h *HTTPHealthCheck) SetPath(path string) *HTTPHealthCheck {
h.Path = path
return h
}
|
go
|
func (h *HTTPHealthCheck) SetPath(path string) *HTTPHealthCheck {
h.Path = path
return h
}
|
[
"func",
"(",
"h",
"*",
"HTTPHealthCheck",
")",
"SetPath",
"(",
"path",
"string",
")",
"*",
"HTTPHealthCheck",
"{",
"h",
".",
"Path",
"=",
"path",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetPath sets the HTTP path of the pod health check endpoint
|
[
"SetPath",
"sets",
"the",
"HTTP",
"path",
"of",
"the",
"pod",
"health",
"check",
"endpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L215-L218
|
16,949 |
gambol99/go-marathon
|
health.go
|
SetScheme
|
func (h *HTTPHealthCheck) SetScheme(scheme string) *HTTPHealthCheck {
h.Scheme = scheme
return h
}
|
go
|
func (h *HTTPHealthCheck) SetScheme(scheme string) *HTTPHealthCheck {
h.Scheme = scheme
return h
}
|
[
"func",
"(",
"h",
"*",
"HTTPHealthCheck",
")",
"SetScheme",
"(",
"scheme",
"string",
")",
"*",
"HTTPHealthCheck",
"{",
"h",
".",
"Scheme",
"=",
"scheme",
"\n",
"return",
"h",
"\n",
"}"
] |
// SetScheme sets the HTTP scheme of the pod health check endpoint
|
[
"SetScheme",
"sets",
"the",
"HTTP",
"scheme",
"of",
"the",
"pod",
"health",
"check",
"endpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L221-L224
|
16,950 |
gambol99/go-marathon
|
health.go
|
SetCommand
|
func (c *CommandHealthCheck) SetCommand(p PodCommand) *CommandHealthCheck {
c.Command = p
return c
}
|
go
|
func (c *CommandHealthCheck) SetCommand(p PodCommand) *CommandHealthCheck {
c.Command = p
return c
}
|
[
"func",
"(",
"c",
"*",
"CommandHealthCheck",
")",
"SetCommand",
"(",
"p",
"PodCommand",
")",
"*",
"CommandHealthCheck",
"{",
"c",
".",
"Command",
"=",
"p",
"\n",
"return",
"c",
"\n",
"}"
] |
// SetCommand sets a CommandHealthCheck's underlying PodCommand
|
[
"SetCommand",
"sets",
"a",
"CommandHealthCheck",
"s",
"underlying",
"PodCommand"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/health.go#L233-L236
|
16,951 |
gambol99/go-marathon
|
pod.go
|
NewPod
|
func NewPod() *Pod {
return &Pod{
Labels: map[string]string{},
Env: map[string]string{},
Containers: []*PodContainer{},
Secrets: map[string]Secret{},
Volumes: []*PodVolume{},
Networks: []*PodNetwork{},
}
}
|
go
|
func NewPod() *Pod {
return &Pod{
Labels: map[string]string{},
Env: map[string]string{},
Containers: []*PodContainer{},
Secrets: map[string]Secret{},
Volumes: []*PodVolume{},
Networks: []*PodNetwork{},
}
}
|
[
"func",
"NewPod",
"(",
")",
"*",
"Pod",
"{",
"return",
"&",
"Pod",
"{",
"Labels",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"Env",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"Containers",
":",
"[",
"]",
"*",
"PodContainer",
"{",
"}",
",",
"Secrets",
":",
"map",
"[",
"string",
"]",
"Secret",
"{",
"}",
",",
"Volumes",
":",
"[",
"]",
"*",
"PodVolume",
"{",
"}",
",",
"Networks",
":",
"[",
"]",
"*",
"PodNetwork",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewPod create an empty pod
|
[
"NewPod",
"create",
"an",
"empty",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L49-L58
|
16,952 |
gambol99/go-marathon
|
pod.go
|
EmptyLabels
|
func (p *Pod) EmptyLabels() *Pod {
p.Labels = make(map[string]string)
return p
}
|
go
|
func (p *Pod) EmptyLabels() *Pod {
p.Labels = make(map[string]string)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"EmptyLabels",
"(",
")",
"*",
"Pod",
"{",
"p",
".",
"Labels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// EmptyLabels empties the labels in a pod
|
[
"EmptyLabels",
"empties",
"the",
"labels",
"in",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L73-L76
|
16,953 |
gambol99/go-marathon
|
pod.go
|
AddLabel
|
func (p *Pod) AddLabel(key, value string) *Pod {
p.Labels[key] = value
return p
}
|
go
|
func (p *Pod) AddLabel(key, value string) *Pod {
p.Labels[key] = value
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"AddLabel",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Pod",
"{",
"p",
".",
"Labels",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"p",
"\n",
"}"
] |
// AddLabel adds a label to a pod
|
[
"AddLabel",
"adds",
"a",
"label",
"to",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L79-L82
|
16,954 |
gambol99/go-marathon
|
pod.go
|
SetLabels
|
func (p *Pod) SetLabels(labels map[string]string) *Pod {
p.Labels = labels
return p
}
|
go
|
func (p *Pod) SetLabels(labels map[string]string) *Pod {
p.Labels = labels
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"SetLabels",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Pod",
"{",
"p",
".",
"Labels",
"=",
"labels",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetLabels sets the labels for a pod
|
[
"SetLabels",
"sets",
"the",
"labels",
"for",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L85-L88
|
16,955 |
gambol99/go-marathon
|
pod.go
|
EmptyEnvs
|
func (p *Pod) EmptyEnvs() *Pod {
p.Env = make(map[string]string)
return p
}
|
go
|
func (p *Pod) EmptyEnvs() *Pod {
p.Env = make(map[string]string)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"EmptyEnvs",
"(",
")",
"*",
"Pod",
"{",
"p",
".",
"Env",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// EmptyEnvs empties the environment variables for a pod
|
[
"EmptyEnvs",
"empties",
"the",
"environment",
"variables",
"for",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L91-L94
|
16,956 |
gambol99/go-marathon
|
pod.go
|
AddContainer
|
func (p *Pod) AddContainer(container *PodContainer) *Pod {
p.Containers = append(p.Containers, container)
return p
}
|
go
|
func (p *Pod) AddContainer(container *PodContainer) *Pod {
p.Containers = append(p.Containers, container)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"AddContainer",
"(",
"container",
"*",
"PodContainer",
")",
"*",
"Pod",
"{",
"p",
".",
"Containers",
"=",
"append",
"(",
"p",
".",
"Containers",
",",
"container",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// AddContainer adds a container to a pod
|
[
"AddContainer",
"adds",
"a",
"container",
"to",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L118-L121
|
16,957 |
gambol99/go-marathon
|
pod.go
|
EmptySecrets
|
func (p *Pod) EmptySecrets() *Pod {
p.Secrets = make(map[string]Secret)
return p
}
|
go
|
func (p *Pod) EmptySecrets() *Pod {
p.Secrets = make(map[string]Secret)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"EmptySecrets",
"(",
")",
"*",
"Pod",
"{",
"p",
".",
"Secrets",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Secret",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// EmptySecrets empties the secret sources in a pod
|
[
"EmptySecrets",
"empties",
"the",
"secret",
"sources",
"in",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L124-L127
|
16,958 |
gambol99/go-marathon
|
pod.go
|
GetSecretSource
|
func (p *Pod) GetSecretSource(name string) (string, error) {
if val, ok := p.Secrets[name]; ok {
return val.Source, nil
}
return "", fmt.Errorf("secret does not exist")
}
|
go
|
func (p *Pod) GetSecretSource(name string) (string, error) {
if val, ok := p.Secrets[name]; ok {
return val.Source, nil
}
return "", fmt.Errorf("secret does not exist")
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"GetSecretSource",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"p",
".",
"Secrets",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"val",
".",
"Source",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// GetSecretSource gets the source of the named secret
|
[
"GetSecretSource",
"gets",
"the",
"source",
"of",
"the",
"named",
"secret"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L130-L135
|
16,959 |
gambol99/go-marathon
|
pod.go
|
AddSecret
|
func (p *Pod) AddSecret(envVar, secretName, sourceName string) *Pod {
if p.Secrets == nil {
p = p.EmptySecrets()
}
p.Secrets[secretName] = Secret{EnvVar: envVar, Source: sourceName}
return p
}
|
go
|
func (p *Pod) AddSecret(envVar, secretName, sourceName string) *Pod {
if p.Secrets == nil {
p = p.EmptySecrets()
}
p.Secrets[secretName] = Secret{EnvVar: envVar, Source: sourceName}
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"AddSecret",
"(",
"envVar",
",",
"secretName",
",",
"sourceName",
"string",
")",
"*",
"Pod",
"{",
"if",
"p",
".",
"Secrets",
"==",
"nil",
"{",
"p",
"=",
"p",
".",
"EmptySecrets",
"(",
")",
"\n",
"}",
"\n",
"p",
".",
"Secrets",
"[",
"secretName",
"]",
"=",
"Secret",
"{",
"EnvVar",
":",
"envVar",
",",
"Source",
":",
"sourceName",
"}",
"\n",
"return",
"p",
"\n",
"}"
] |
// AddSecret adds the secret to the pod
|
[
"AddSecret",
"adds",
"the",
"secret",
"to",
"the",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L138-L144
|
16,960 |
gambol99/go-marathon
|
pod.go
|
AddVolume
|
func (p *Pod) AddVolume(vol *PodVolume) *Pod {
p.Volumes = append(p.Volumes, vol)
return p
}
|
go
|
func (p *Pod) AddVolume(vol *PodVolume) *Pod {
p.Volumes = append(p.Volumes, vol)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"AddVolume",
"(",
"vol",
"*",
"PodVolume",
")",
"*",
"Pod",
"{",
"p",
".",
"Volumes",
"=",
"append",
"(",
"p",
".",
"Volumes",
",",
"vol",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// AddVolume adds a volume to a pod
|
[
"AddVolume",
"adds",
"a",
"volume",
"to",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L147-L150
|
16,961 |
gambol99/go-marathon
|
pod.go
|
AddNetwork
|
func (p *Pod) AddNetwork(net *PodNetwork) *Pod {
p.Networks = append(p.Networks, net)
return p
}
|
go
|
func (p *Pod) AddNetwork(net *PodNetwork) *Pod {
p.Networks = append(p.Networks, net)
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"AddNetwork",
"(",
"net",
"*",
"PodNetwork",
")",
"*",
"Pod",
"{",
"p",
".",
"Networks",
"=",
"append",
"(",
"p",
".",
"Networks",
",",
"net",
")",
"\n",
"return",
"p",
"\n",
"}"
] |
// AddNetwork adds a PodNetwork to a pod
|
[
"AddNetwork",
"adds",
"a",
"PodNetwork",
"to",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L153-L156
|
16,962 |
gambol99/go-marathon
|
pod.go
|
Count
|
func (p *Pod) Count(count int) *Pod {
p.Scaling = &PodScalingPolicy{
Kind: "fixed",
Instances: count,
}
return p
}
|
go
|
func (p *Pod) Count(count int) *Pod {
p.Scaling = &PodScalingPolicy{
Kind: "fixed",
Instances: count,
}
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"Count",
"(",
"count",
"int",
")",
"*",
"Pod",
"{",
"p",
".",
"Scaling",
"=",
"&",
"PodScalingPolicy",
"{",
"Kind",
":",
"\"",
"\"",
",",
"Instances",
":",
"count",
",",
"}",
"\n",
"return",
"p",
"\n",
"}"
] |
// Count sets the count of the pod
|
[
"Count",
"sets",
"the",
"count",
"of",
"the",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L159-L165
|
16,963 |
gambol99/go-marathon
|
pod.go
|
SetPodSchedulingPolicy
|
func (p *Pod) SetPodSchedulingPolicy(policy *PodSchedulingPolicy) *Pod {
p.Scheduling = policy
return p
}
|
go
|
func (p *Pod) SetPodSchedulingPolicy(policy *PodSchedulingPolicy) *Pod {
p.Scheduling = policy
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"SetPodSchedulingPolicy",
"(",
"policy",
"*",
"PodSchedulingPolicy",
")",
"*",
"Pod",
"{",
"p",
".",
"Scheduling",
"=",
"policy",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetPodSchedulingPolicy sets the PodSchedulingPolicy of a pod
|
[
"SetPodSchedulingPolicy",
"sets",
"the",
"PodSchedulingPolicy",
"of",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L168-L171
|
16,964 |
gambol99/go-marathon
|
pod.go
|
SetExecutorResources
|
func (p *Pod) SetExecutorResources(resources *ExecutorResources) *Pod {
p.ExecutorResources = resources
return p
}
|
go
|
func (p *Pod) SetExecutorResources(resources *ExecutorResources) *Pod {
p.ExecutorResources = resources
return p
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"SetExecutorResources",
"(",
"resources",
"*",
"ExecutorResources",
")",
"*",
"Pod",
"{",
"p",
".",
"ExecutorResources",
"=",
"resources",
"\n",
"return",
"p",
"\n",
"}"
] |
// SetExecutorResources sets the resources for the pod executor
|
[
"SetExecutorResources",
"sets",
"the",
"resources",
"for",
"the",
"pod",
"executor"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L174-L177
|
16,965 |
gambol99/go-marathon
|
pod.go
|
SupportsPods
|
func (r *marathonClient) SupportsPods() (bool, error) {
if err := r.apiHead(marathonAPIPods, nil); err != nil {
// If we get a 404 we can return a strict false, otherwise it could be
// a valid error
if apiErr, ok := err.(*APIError); ok && apiErr.ErrCode == ErrCodeNotFound {
return false, nil
}
return false, err
}
return true, nil
}
|
go
|
func (r *marathonClient) SupportsPods() (bool, error) {
if err := r.apiHead(marathonAPIPods, nil); err != nil {
// If we get a 404 we can return a strict false, otherwise it could be
// a valid error
if apiErr, ok := err.(*APIError); ok && apiErr.ErrCode == ErrCodeNotFound {
return false, nil
}
return false, err
}
return true, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"SupportsPods",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"err",
":=",
"r",
".",
"apiHead",
"(",
"marathonAPIPods",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"// If we get a 404 we can return a strict false, otherwise it could be",
"// a valid error",
"if",
"apiErr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"APIError",
")",
";",
"ok",
"&&",
"apiErr",
".",
"ErrCode",
"==",
"ErrCodeNotFound",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] |
// SupportsPods determines if this version of marathon supports pods
// If HEAD returns 200 it does
|
[
"SupportsPods",
"determines",
"if",
"this",
"version",
"of",
"marathon",
"supports",
"pods",
"If",
"HEAD",
"returns",
"200",
"it",
"does"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L181-L192
|
16,966 |
gambol99/go-marathon
|
pod.go
|
Pod
|
func (r *marathonClient) Pod(name string) (*Pod, error) {
uri := buildPodURI(name)
result := new(Pod)
if err := r.apiGet(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) Pod(name string) (*Pod, error) {
uri := buildPodURI(name)
result := new(Pod)
if err := r.apiGet(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"Pod",
"(",
"name",
"string",
")",
"(",
"*",
"Pod",
",",
"error",
")",
"{",
"uri",
":=",
"buildPodURI",
"(",
"name",
")",
"\n",
"result",
":=",
"new",
"(",
"Pod",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiGet",
"(",
"uri",
",",
"nil",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// Pod gets a pod object from marathon by name
|
[
"Pod",
"gets",
"a",
"pod",
"object",
"from",
"marathon",
"by",
"name"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L195-L203
|
16,967 |
gambol99/go-marathon
|
pod.go
|
Pods
|
func (r *marathonClient) Pods() ([]Pod, error) {
var result []Pod
if err := r.apiGet(marathonAPIPods, nil, &result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) Pods() ([]Pod, error) {
var result []Pod
if err := r.apiGet(marathonAPIPods, nil, &result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"Pods",
"(",
")",
"(",
"[",
"]",
"Pod",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"Pod",
"\n",
"if",
"err",
":=",
"r",
".",
"apiGet",
"(",
"marathonAPIPods",
",",
"nil",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// Pods gets all pods from marathon
|
[
"Pods",
"gets",
"all",
"pods",
"from",
"marathon"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L206-L213
|
16,968 |
gambol99/go-marathon
|
pod.go
|
CreatePod
|
func (r *marathonClient) CreatePod(pod *Pod) (*Pod, error) {
result := new(Pod)
if err := r.apiPost(marathonAPIPods, &pod, result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) CreatePod(pod *Pod) (*Pod, error) {
result := new(Pod)
if err := r.apiPost(marathonAPIPods, &pod, result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"CreatePod",
"(",
"pod",
"*",
"Pod",
")",
"(",
"*",
"Pod",
",",
"error",
")",
"{",
"result",
":=",
"new",
"(",
"Pod",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiPost",
"(",
"marathonAPIPods",
",",
"&",
"pod",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// CreatePod creates a new pod in Marathon
|
[
"CreatePod",
"creates",
"a",
"new",
"pod",
"in",
"Marathon"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L216-L223
|
16,969 |
gambol99/go-marathon
|
pod.go
|
DeletePod
|
func (r *marathonClient) DeletePod(name string, force bool) (*DeploymentID, error) {
uri := fmt.Sprintf("%s?force=%v", buildPodURI(name), force)
deployID := new(DeploymentID)
if err := r.apiDelete(uri, nil, deployID); err != nil {
return nil, err
}
return deployID, nil
}
|
go
|
func (r *marathonClient) DeletePod(name string, force bool) (*DeploymentID, error) {
uri := fmt.Sprintf("%s?force=%v", buildPodURI(name), force)
deployID := new(DeploymentID)
if err := r.apiDelete(uri, nil, deployID); err != nil {
return nil, err
}
return deployID, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"DeletePod",
"(",
"name",
"string",
",",
"force",
"bool",
")",
"(",
"*",
"DeploymentID",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"buildPodURI",
"(",
"name",
")",
",",
"force",
")",
"\n\n",
"deployID",
":=",
"new",
"(",
"DeploymentID",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiDelete",
"(",
"uri",
",",
"nil",
",",
"deployID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"deployID",
",",
"nil",
"\n",
"}"
] |
// DeletePod deletes a pod from marathon
|
[
"DeletePod",
"deletes",
"a",
"pod",
"from",
"marathon"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L226-L235
|
16,970 |
gambol99/go-marathon
|
pod.go
|
UpdatePod
|
func (r *marathonClient) UpdatePod(pod *Pod, force bool) (*Pod, error) {
uri := fmt.Sprintf("%s?force=%v", buildPodURI(pod.ID), force)
result := new(Pod)
if err := r.apiPut(uri, pod, result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) UpdatePod(pod *Pod, force bool) (*Pod, error) {
uri := fmt.Sprintf("%s?force=%v", buildPodURI(pod.ID), force)
result := new(Pod)
if err := r.apiPut(uri, pod, result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"UpdatePod",
"(",
"pod",
"*",
"Pod",
",",
"force",
"bool",
")",
"(",
"*",
"Pod",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"buildPodURI",
"(",
"pod",
".",
"ID",
")",
",",
"force",
")",
"\n",
"result",
":=",
"new",
"(",
"Pod",
")",
"\n\n",
"if",
"err",
":=",
"r",
".",
"apiPut",
"(",
"uri",
",",
"pod",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// UpdatePod creates a new pod in Marathon
|
[
"UpdatePod",
"creates",
"a",
"new",
"pod",
"in",
"Marathon"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L238-L247
|
16,971 |
gambol99/go-marathon
|
pod.go
|
PodVersions
|
func (r *marathonClient) PodVersions(name string) ([]string, error) {
uri := buildPodVersionURI(name)
var result []string
if err := r.apiGet(uri, nil, &result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) PodVersions(name string) ([]string, error) {
uri := buildPodVersionURI(name)
var result []string
if err := r.apiGet(uri, nil, &result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"PodVersions",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"uri",
":=",
"buildPodVersionURI",
"(",
"name",
")",
"\n",
"var",
"result",
"[",
"]",
"string",
"\n",
"if",
"err",
":=",
"r",
".",
"apiGet",
"(",
"uri",
",",
"nil",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// PodVersions gets all the deployed versions of a pod
|
[
"PodVersions",
"gets",
"all",
"the",
"deployed",
"versions",
"of",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L250-L258
|
16,972 |
gambol99/go-marathon
|
pod.go
|
PodByVersion
|
func (r *marathonClient) PodByVersion(name, version string) (*Pod, error) {
uri := fmt.Sprintf("%s/%s", buildPodVersionURI(name), version)
result := new(Pod)
if err := r.apiGet(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) PodByVersion(name, version string) (*Pod, error) {
uri := fmt.Sprintf("%s/%s", buildPodVersionURI(name), version)
result := new(Pod)
if err := r.apiGet(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"PodByVersion",
"(",
"name",
",",
"version",
"string",
")",
"(",
"*",
"Pod",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"buildPodVersionURI",
"(",
"name",
")",
",",
"version",
")",
"\n",
"result",
":=",
"new",
"(",
"Pod",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiGet",
"(",
"uri",
",",
"nil",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// PodByVersion gets a pod by a version identifier
|
[
"PodByVersion",
"gets",
"a",
"pod",
"by",
"a",
"version",
"identifier"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod.go#L261-L269
|
16,973 |
gambol99/go-marathon
|
docker.go
|
SetPersistentVolume
|
func (v *Volume) SetPersistentVolume() *PersistentVolume {
ev := &PersistentVolume{}
v.Persistent = ev
return ev
}
|
go
|
func (v *Volume) SetPersistentVolume() *PersistentVolume {
ev := &PersistentVolume{}
v.Persistent = ev
return ev
}
|
[
"func",
"(",
"v",
"*",
"Volume",
")",
"SetPersistentVolume",
"(",
")",
"*",
"PersistentVolume",
"{",
"ev",
":=",
"&",
"PersistentVolume",
"{",
"}",
"\n",
"v",
".",
"Persistent",
"=",
"ev",
"\n",
"return",
"ev",
"\n",
"}"
] |
// SetPersistentVolume defines persistent properties for volume
|
[
"SetPersistentVolume",
"defines",
"persistent",
"properties",
"for",
"volume"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/docker.go#L169-L173
|
16,974 |
gambol99/go-marathon
|
docker.go
|
NewDockerContainer
|
func NewDockerContainer() *Container {
container := &Container{}
container.Type = "DOCKER"
container.Docker = &Docker{}
return container
}
|
go
|
func NewDockerContainer() *Container {
container := &Container{}
container.Type = "DOCKER"
container.Docker = &Docker{}
return container
}
|
[
"func",
"NewDockerContainer",
"(",
")",
"*",
"Container",
"{",
"container",
":=",
"&",
"Container",
"{",
"}",
"\n",
"container",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"container",
".",
"Docker",
"=",
"&",
"Docker",
"{",
"}",
"\n\n",
"return",
"container",
"\n",
"}"
] |
// NewDockerContainer creates a default docker container for you
|
[
"NewDockerContainer",
"creates",
"a",
"default",
"docker",
"container",
"for",
"you"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/docker.go#L219-L225
|
16,975 |
gambol99/go-marathon
|
upgrade_strategy.go
|
SetMinimumHealthCapacity
|
func (us *UpgradeStrategy) SetMinimumHealthCapacity(cap float64) *UpgradeStrategy {
us.MinimumHealthCapacity = &cap
return us
}
|
go
|
func (us *UpgradeStrategy) SetMinimumHealthCapacity(cap float64) *UpgradeStrategy {
us.MinimumHealthCapacity = &cap
return us
}
|
[
"func",
"(",
"us",
"*",
"UpgradeStrategy",
")",
"SetMinimumHealthCapacity",
"(",
"cap",
"float64",
")",
"*",
"UpgradeStrategy",
"{",
"us",
".",
"MinimumHealthCapacity",
"=",
"&",
"cap",
"\n",
"return",
"us",
"\n",
"}"
] |
// SetMinimumHealthCapacity sets the minimum health capacity.
|
[
"SetMinimumHealthCapacity",
"sets",
"the",
"minimum",
"health",
"capacity",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/upgrade_strategy.go#L26-L29
|
16,976 |
gambol99/go-marathon
|
upgrade_strategy.go
|
SetMaximumOverCapacity
|
func (us *UpgradeStrategy) SetMaximumOverCapacity(cap float64) *UpgradeStrategy {
us.MaximumOverCapacity = &cap
return us
}
|
go
|
func (us *UpgradeStrategy) SetMaximumOverCapacity(cap float64) *UpgradeStrategy {
us.MaximumOverCapacity = &cap
return us
}
|
[
"func",
"(",
"us",
"*",
"UpgradeStrategy",
")",
"SetMaximumOverCapacity",
"(",
"cap",
"float64",
")",
"*",
"UpgradeStrategy",
"{",
"us",
".",
"MaximumOverCapacity",
"=",
"&",
"cap",
"\n",
"return",
"us",
"\n",
"}"
] |
// SetMaximumOverCapacity sets the maximum over capacity.
|
[
"SetMaximumOverCapacity",
"sets",
"the",
"maximum",
"over",
"capacity",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/upgrade_strategy.go#L32-L35
|
16,977 |
gambol99/go-marathon
|
subscription.go
|
Subscriptions
|
func (r *marathonClient) Subscriptions() (*Subscriptions, error) {
subscriptions := new(Subscriptions)
if err := r.apiGet(marathonAPISubscription, nil, subscriptions); err != nil {
return nil, err
}
return subscriptions, nil
}
|
go
|
func (r *marathonClient) Subscriptions() (*Subscriptions, error) {
subscriptions := new(Subscriptions)
if err := r.apiGet(marathonAPISubscription, nil, subscriptions); err != nil {
return nil, err
}
return subscriptions, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"Subscriptions",
"(",
")",
"(",
"*",
"Subscriptions",
",",
"error",
")",
"{",
"subscriptions",
":=",
"new",
"(",
"Subscriptions",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiGet",
"(",
"marathonAPISubscription",
",",
"nil",
",",
"subscriptions",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"subscriptions",
",",
"nil",
"\n",
"}"
] |
// Subscriptions retrieves a list of registered subscriptions
|
[
"Subscriptions",
"retrieves",
"a",
"list",
"of",
"registered",
"subscriptions"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/subscription.go#L38-L45
|
16,978 |
gambol99/go-marathon
|
subscription.go
|
SubscriptionURL
|
func (r *marathonClient) SubscriptionURL() string {
if r.config.CallbackURL != "" {
return fmt.Sprintf("%s%s", r.config.CallbackURL, defaultEventsURL)
}
return fmt.Sprintf("http://%s:%d%s", r.ipAddress, r.config.EventsPort, defaultEventsURL)
}
|
go
|
func (r *marathonClient) SubscriptionURL() string {
if r.config.CallbackURL != "" {
return fmt.Sprintf("%s%s", r.config.CallbackURL, defaultEventsURL)
}
return fmt.Sprintf("http://%s:%d%s", r.ipAddress, r.config.EventsPort, defaultEventsURL)
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"SubscriptionURL",
"(",
")",
"string",
"{",
"if",
"r",
".",
"config",
".",
"CallbackURL",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"config",
".",
"CallbackURL",
",",
"defaultEventsURL",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"ipAddress",
",",
"r",
".",
"config",
".",
"EventsPort",
",",
"defaultEventsURL",
")",
"\n",
"}"
] |
// SubscriptionURL retrieves the subscription callback URL used when registering
|
[
"SubscriptionURL",
"retrieves",
"the",
"subscription",
"callback",
"URL",
"used",
"when",
"registering"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/subscription.go#L92-L98
|
16,979 |
gambol99/go-marathon
|
subscription.go
|
registerSubscription
|
func (r *marathonClient) registerSubscription() error {
switch r.config.EventsTransport {
case EventsTransportCallback:
return r.registerCallbackSubscription()
case EventsTransportSSE:
return r.registerSSESubscription()
default:
return fmt.Errorf("the events transport: %d is not supported", r.config.EventsTransport)
}
}
|
go
|
func (r *marathonClient) registerSubscription() error {
switch r.config.EventsTransport {
case EventsTransportCallback:
return r.registerCallbackSubscription()
case EventsTransportSSE:
return r.registerSSESubscription()
default:
return fmt.Errorf("the events transport: %d is not supported", r.config.EventsTransport)
}
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"registerSubscription",
"(",
")",
"error",
"{",
"switch",
"r",
".",
"config",
".",
"EventsTransport",
"{",
"case",
"EventsTransportCallback",
":",
"return",
"r",
".",
"registerCallbackSubscription",
"(",
")",
"\n",
"case",
"EventsTransportSSE",
":",
"return",
"r",
".",
"registerSSESubscription",
"(",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"config",
".",
"EventsTransport",
")",
"\n",
"}",
"\n",
"}"
] |
// registerSubscription registers ourselves with Marathon to receive events from configured transport facility
|
[
"registerSubscription",
"registers",
"ourselves",
"with",
"Marathon",
"to",
"receive",
"events",
"from",
"configured",
"transport",
"facility"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/subscription.go#L101-L110
|
16,980 |
gambol99/go-marathon
|
subscription.go
|
registerSSESubscription
|
func (r *marathonClient) registerSSESubscription() error {
if r.subscribedToSSE {
return nil
}
if r.config.HTTPSSEClient.Timeout != 0 {
return fmt.Errorf(
"global timeout must not be set for SSE connections (found %s) -- remove global timeout from HTTP client or provide separate SSE HTTP client without global timeout",
r.config.HTTPSSEClient.Timeout,
)
}
go func() {
for {
stream, err := r.connectToSSE()
if err != nil {
r.debugLog("Error connecting SSE subscription: %s", err)
<-time.After(5 * time.Second)
continue
}
err = r.listenToSSE(stream)
stream.Close()
r.debugLog("Error on SSE subscription: %s", err)
}
}()
r.subscribedToSSE = true
return nil
}
|
go
|
func (r *marathonClient) registerSSESubscription() error {
if r.subscribedToSSE {
return nil
}
if r.config.HTTPSSEClient.Timeout != 0 {
return fmt.Errorf(
"global timeout must not be set for SSE connections (found %s) -- remove global timeout from HTTP client or provide separate SSE HTTP client without global timeout",
r.config.HTTPSSEClient.Timeout,
)
}
go func() {
for {
stream, err := r.connectToSSE()
if err != nil {
r.debugLog("Error connecting SSE subscription: %s", err)
<-time.After(5 * time.Second)
continue
}
err = r.listenToSSE(stream)
stream.Close()
r.debugLog("Error on SSE subscription: %s", err)
}
}()
r.subscribedToSSE = true
return nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"registerSSESubscription",
"(",
")",
"error",
"{",
"if",
"r",
".",
"subscribedToSSE",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"config",
".",
"HTTPSSEClient",
".",
"Timeout",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"config",
".",
"HTTPSSEClient",
".",
"Timeout",
",",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"stream",
",",
"err",
":=",
"r",
".",
"connectToSSE",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"debugLog",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"<-",
"time",
".",
"After",
"(",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"r",
".",
"listenToSSE",
"(",
"stream",
")",
"\n",
"stream",
".",
"Close",
"(",
")",
"\n",
"r",
".",
"debugLog",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"r",
".",
"subscribedToSSE",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// registerSSESubscription starts a go routine that continuously tries to
// connect to the SSE stream and to process the received events. To establish
// the connection it tries the active cluster members until no more member is
// active. When this happens it will retry to get a connection every 5 seconds.
|
[
"registerSSESubscription",
"starts",
"a",
"go",
"routine",
"that",
"continuously",
"tries",
"to",
"connect",
"to",
"the",
"SSE",
"stream",
"and",
"to",
"process",
"the",
"received",
"events",
".",
"To",
"establish",
"the",
"connection",
"it",
"tries",
"the",
"active",
"cluster",
"members",
"until",
"no",
"more",
"member",
"is",
"active",
".",
"When",
"this",
"happens",
"it",
"will",
"retry",
"to",
"get",
"a",
"connection",
"every",
"5",
"seconds",
"."
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/subscription.go#L169-L197
|
16,981 |
gambol99/go-marathon
|
queue.go
|
Queue
|
func (r *marathonClient) Queue() (*Queue, error) {
var queue *Queue
err := r.apiGet(marathonAPIQueue, nil, &queue)
if err != nil {
return nil, err
}
return queue, nil
}
|
go
|
func (r *marathonClient) Queue() (*Queue, error) {
var queue *Queue
err := r.apiGet(marathonAPIQueue, nil, &queue)
if err != nil {
return nil, err
}
return queue, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"Queue",
"(",
")",
"(",
"*",
"Queue",
",",
"error",
")",
"{",
"var",
"queue",
"*",
"Queue",
"\n",
"err",
":=",
"r",
".",
"apiGet",
"(",
"marathonAPIQueue",
",",
"nil",
",",
"&",
"queue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"queue",
",",
"nil",
"\n",
"}"
] |
// Queue retrieves content of the marathon launch queue
|
[
"Queue",
"retrieves",
"content",
"of",
"the",
"marathon",
"launch",
"queue"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/queue.go#L42-L49
|
16,982 |
gambol99/go-marathon
|
cluster.go
|
newCluster
|
func newCluster(client *httpClient, marathonURL string, isDCOS bool) (*cluster, error) {
// step: extract and basic validate the endpoints
var members []*member
var defaultProto string
for _, endpoint := range strings.Split(marathonURL, ",") {
// step: check for nothing
if endpoint == "" {
return nil, newInvalidEndpointError("endpoint is blank")
}
// step: prepend scheme if missing on (non-initial) endpoint.
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
if defaultProto == "" {
return nil, newInvalidEndpointError("missing scheme on (first) endpoint")
}
endpoint = fmt.Sprintf("%s://%s", defaultProto, endpoint)
}
// step: parse the url
u, err := url.Parse(endpoint)
if err != nil {
return nil, newInvalidEndpointError("invalid endpoint '%s': %s", endpoint, err)
}
if defaultProto == "" {
defaultProto = u.Scheme
}
// step: check for empty hosts
if u.Host == "" {
return nil, newInvalidEndpointError("endpoint: %s must have a host", endpoint)
}
// step: if DCOS is set and no path is given, set the default DCOS path.
// done in order to maintain compatibility with automatic addition of the
// default DCOS path.
if isDCOS && strings.TrimLeft(u.Path, "/") == "" {
u.Path = defaultDCOSPath
}
// step: create a new node for this endpoint
members = append(members, &member{endpoint: u.String()})
}
return &cluster{
client: client,
members: members,
healthCheckInterval: 5 * time.Second,
}, nil
}
|
go
|
func newCluster(client *httpClient, marathonURL string, isDCOS bool) (*cluster, error) {
// step: extract and basic validate the endpoints
var members []*member
var defaultProto string
for _, endpoint := range strings.Split(marathonURL, ",") {
// step: check for nothing
if endpoint == "" {
return nil, newInvalidEndpointError("endpoint is blank")
}
// step: prepend scheme if missing on (non-initial) endpoint.
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
if defaultProto == "" {
return nil, newInvalidEndpointError("missing scheme on (first) endpoint")
}
endpoint = fmt.Sprintf("%s://%s", defaultProto, endpoint)
}
// step: parse the url
u, err := url.Parse(endpoint)
if err != nil {
return nil, newInvalidEndpointError("invalid endpoint '%s': %s", endpoint, err)
}
if defaultProto == "" {
defaultProto = u.Scheme
}
// step: check for empty hosts
if u.Host == "" {
return nil, newInvalidEndpointError("endpoint: %s must have a host", endpoint)
}
// step: if DCOS is set and no path is given, set the default DCOS path.
// done in order to maintain compatibility with automatic addition of the
// default DCOS path.
if isDCOS && strings.TrimLeft(u.Path, "/") == "" {
u.Path = defaultDCOSPath
}
// step: create a new node for this endpoint
members = append(members, &member{endpoint: u.String()})
}
return &cluster{
client: client,
members: members,
healthCheckInterval: 5 * time.Second,
}, nil
}
|
[
"func",
"newCluster",
"(",
"client",
"*",
"httpClient",
",",
"marathonURL",
"string",
",",
"isDCOS",
"bool",
")",
"(",
"*",
"cluster",
",",
"error",
")",
"{",
"// step: extract and basic validate the endpoints",
"var",
"members",
"[",
"]",
"*",
"member",
"\n",
"var",
"defaultProto",
"string",
"\n\n",
"for",
"_",
",",
"endpoint",
":=",
"range",
"strings",
".",
"Split",
"(",
"marathonURL",
",",
"\"",
"\"",
")",
"{",
"// step: check for nothing",
"if",
"endpoint",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"newInvalidEndpointError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// step: prepend scheme if missing on (non-initial) endpoint.",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"endpoint",
",",
"\"",
"\"",
")",
"&&",
"!",
"strings",
".",
"HasPrefix",
"(",
"endpoint",
",",
"\"",
"\"",
")",
"{",
"if",
"defaultProto",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"newInvalidEndpointError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"endpoint",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"defaultProto",
",",
"endpoint",
")",
"\n",
"}",
"\n",
"// step: parse the url",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"newInvalidEndpointError",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"defaultProto",
"==",
"\"",
"\"",
"{",
"defaultProto",
"=",
"u",
".",
"Scheme",
"\n",
"}",
"\n\n",
"// step: check for empty hosts",
"if",
"u",
".",
"Host",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"newInvalidEndpointError",
"(",
"\"",
"\"",
",",
"endpoint",
")",
"\n",
"}",
"\n\n",
"// step: if DCOS is set and no path is given, set the default DCOS path.",
"// done in order to maintain compatibility with automatic addition of the",
"// default DCOS path.",
"if",
"isDCOS",
"&&",
"strings",
".",
"TrimLeft",
"(",
"u",
".",
"Path",
",",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"u",
".",
"Path",
"=",
"defaultDCOSPath",
"\n",
"}",
"\n\n",
"// step: create a new node for this endpoint",
"members",
"=",
"append",
"(",
"members",
",",
"&",
"member",
"{",
"endpoint",
":",
"u",
".",
"String",
"(",
")",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"cluster",
"{",
"client",
":",
"client",
",",
"members",
":",
"members",
",",
"healthCheckInterval",
":",
"5",
"*",
"time",
".",
"Second",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newCluster returns a new marathon cluster
|
[
"newCluster",
"returns",
"a",
"new",
"marathon",
"cluster"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L56-L104
|
16,983 |
gambol99/go-marathon
|
cluster.go
|
getMember
|
func (c *cluster) getMember() (string, error) {
c.RLock()
defer c.RUnlock()
for _, n := range c.members {
if n.status == memberStatusUp {
return n.endpoint, nil
}
}
return "", ErrMarathonDown
}
|
go
|
func (c *cluster) getMember() (string, error) {
c.RLock()
defer c.RUnlock()
for _, n := range c.members {
if n.status == memberStatusUp {
return n.endpoint, nil
}
}
return "", ErrMarathonDown
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"getMember",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"members",
"{",
"if",
"n",
".",
"status",
"==",
"memberStatusUp",
"{",
"return",
"n",
".",
"endpoint",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"ErrMarathonDown",
"\n",
"}"
] |
// retrieve the current member, i.e. the current endpoint in use
|
[
"retrieve",
"the",
"current",
"member",
"i",
".",
"e",
".",
"the",
"current",
"endpoint",
"in",
"use"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L107-L117
|
16,984 |
gambol99/go-marathon
|
cluster.go
|
markDown
|
func (c *cluster) markDown(endpoint string) {
c.Lock()
defer c.Unlock()
for _, n := range c.members {
// step: check if this is the node and it's marked as up - The double checking on the
// nodes status ensures the multiple calls don't create multiple checks
if n.status == memberStatusUp && n.endpoint == endpoint {
n.status = memberStatusDown
go c.healthCheckNode(n)
break
}
}
}
|
go
|
func (c *cluster) markDown(endpoint string) {
c.Lock()
defer c.Unlock()
for _, n := range c.members {
// step: check if this is the node and it's marked as up - The double checking on the
// nodes status ensures the multiple calls don't create multiple checks
if n.status == memberStatusUp && n.endpoint == endpoint {
n.status = memberStatusDown
go c.healthCheckNode(n)
break
}
}
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"markDown",
"(",
"endpoint",
"string",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"members",
"{",
"// step: check if this is the node and it's marked as up - The double checking on the",
"// nodes status ensures the multiple calls don't create multiple checks",
"if",
"n",
".",
"status",
"==",
"memberStatusUp",
"&&",
"n",
".",
"endpoint",
"==",
"endpoint",
"{",
"n",
".",
"status",
"=",
"memberStatusDown",
"\n",
"go",
"c",
".",
"healthCheckNode",
"(",
"n",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// markDown marks down the current endpoint
|
[
"markDown",
"marks",
"down",
"the",
"current",
"endpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L120-L132
|
16,985 |
gambol99/go-marathon
|
cluster.go
|
healthCheckNode
|
func (c *cluster) healthCheckNode(node *member) {
// step: wait for the node to become active ... we are assuming a /ping is enough here
ticker := time.NewTicker(c.healthCheckInterval)
defer ticker.Stop()
for range ticker.C {
req, err := c.client.buildMarathonRequest("GET", node.endpoint, "ping", nil)
if err == nil {
res, err := c.client.Do(req)
if err == nil && res.StatusCode == 200 {
// step: mark the node as active again
c.Lock()
node.status = memberStatusUp
c.Unlock()
break
}
}
}
}
|
go
|
func (c *cluster) healthCheckNode(node *member) {
// step: wait for the node to become active ... we are assuming a /ping is enough here
ticker := time.NewTicker(c.healthCheckInterval)
defer ticker.Stop()
for range ticker.C {
req, err := c.client.buildMarathonRequest("GET", node.endpoint, "ping", nil)
if err == nil {
res, err := c.client.Do(req)
if err == nil && res.StatusCode == 200 {
// step: mark the node as active again
c.Lock()
node.status = memberStatusUp
c.Unlock()
break
}
}
}
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"healthCheckNode",
"(",
"node",
"*",
"member",
")",
"{",
"// step: wait for the node to become active ... we are assuming a /ping is enough here",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"c",
".",
"healthCheckInterval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"for",
"range",
"ticker",
".",
"C",
"{",
"req",
",",
"err",
":=",
"c",
".",
"client",
".",
"buildMarathonRequest",
"(",
"\"",
"\"",
",",
"node",
".",
"endpoint",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"res",
",",
"err",
":=",
"c",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"res",
".",
"StatusCode",
"==",
"200",
"{",
"// step: mark the node as active again",
"c",
".",
"Lock",
"(",
")",
"\n",
"node",
".",
"status",
"=",
"memberStatusUp",
"\n",
"c",
".",
"Unlock",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// healthCheckNode performs a health check on the node and when active updates the status
|
[
"healthCheckNode",
"performs",
"a",
"health",
"check",
"on",
"the",
"node",
"and",
"when",
"active",
"updates",
"the",
"status"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L135-L152
|
16,986 |
gambol99/go-marathon
|
cluster.go
|
membersList
|
func (c *cluster) membersList(status memberStatus) []string {
c.RLock()
defer c.RUnlock()
var list []string
for _, m := range c.members {
if m.status == status {
list = append(list, m.endpoint)
}
}
return list
}
|
go
|
func (c *cluster) membersList(status memberStatus) []string {
c.RLock()
defer c.RUnlock()
var list []string
for _, m := range c.members {
if m.status == status {
list = append(list, m.endpoint)
}
}
return list
}
|
[
"func",
"(",
"c",
"*",
"cluster",
")",
"membersList",
"(",
"status",
"memberStatus",
")",
"[",
"]",
"string",
"{",
"c",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"list",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"c",
".",
"members",
"{",
"if",
"m",
".",
"status",
"==",
"status",
"{",
"list",
"=",
"append",
"(",
"list",
",",
"m",
".",
"endpoint",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"list",
"\n",
"}"
] |
// memberList returns a list of members of a specified status
|
[
"memberList",
"returns",
"a",
"list",
"of",
"members",
"of",
"a",
"specified",
"status"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L165-L176
|
16,987 |
gambol99/go-marathon
|
cluster.go
|
String
|
func (m member) String() string {
status := "UP"
if m.status == memberStatusDown {
status = "DOWN"
}
return fmt.Sprintf("member: %s:%s", m.endpoint, status)
}
|
go
|
func (m member) String() string {
status := "UP"
if m.status == memberStatusDown {
status = "DOWN"
}
return fmt.Sprintf("member: %s:%s", m.endpoint, status)
}
|
[
"func",
"(",
"m",
"member",
")",
"String",
"(",
")",
"string",
"{",
"status",
":=",
"\"",
"\"",
"\n",
"if",
"m",
".",
"status",
"==",
"memberStatusDown",
"{",
"status",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"m",
".",
"endpoint",
",",
"status",
")",
"\n",
"}"
] |
// String returns a string representation
|
[
"String",
"returns",
"a",
"string",
"representation"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/cluster.go#L184-L191
|
16,988 |
gambol99/go-marathon
|
network.go
|
NewPodNetwork
|
func NewPodNetwork(name string) *PodNetwork {
return &PodNetwork{
Name: name,
Labels: map[string]string{},
}
}
|
go
|
func NewPodNetwork(name string) *PodNetwork {
return &PodNetwork{
Name: name,
Labels: map[string]string{},
}
}
|
[
"func",
"NewPodNetwork",
"(",
"name",
"string",
")",
"*",
"PodNetwork",
"{",
"return",
"&",
"PodNetwork",
"{",
"Name",
":",
"name",
",",
"Labels",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewPodNetwork creates an empty PodNetwork
|
[
"NewPodNetwork",
"creates",
"an",
"empty",
"PodNetwork"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L45-L50
|
16,989 |
gambol99/go-marathon
|
network.go
|
NewContainerPodNetwork
|
func NewContainerPodNetwork(name string) *PodNetwork {
pn := NewPodNetwork(name)
return pn.SetMode(ContainerNetworkMode)
}
|
go
|
func NewContainerPodNetwork(name string) *PodNetwork {
pn := NewPodNetwork(name)
return pn.SetMode(ContainerNetworkMode)
}
|
[
"func",
"NewContainerPodNetwork",
"(",
"name",
"string",
")",
"*",
"PodNetwork",
"{",
"pn",
":=",
"NewPodNetwork",
"(",
"name",
")",
"\n",
"return",
"pn",
".",
"SetMode",
"(",
"ContainerNetworkMode",
")",
"\n",
"}"
] |
// NewContainerPodNetwork creates a PodNetwork for a container
|
[
"NewContainerPodNetwork",
"creates",
"a",
"PodNetwork",
"for",
"a",
"container"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L67-L70
|
16,990 |
gambol99/go-marathon
|
network.go
|
SetName
|
func (n *PodNetwork) SetName(name string) *PodNetwork {
n.Name = name
return n
}
|
go
|
func (n *PodNetwork) SetName(name string) *PodNetwork {
n.Name = name
return n
}
|
[
"func",
"(",
"n",
"*",
"PodNetwork",
")",
"SetName",
"(",
"name",
"string",
")",
"*",
"PodNetwork",
"{",
"n",
".",
"Name",
"=",
"name",
"\n",
"return",
"n",
"\n",
"}"
] |
// SetName sets the name of a PodNetwork
|
[
"SetName",
"sets",
"the",
"name",
"of",
"a",
"PodNetwork"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L79-L82
|
16,991 |
gambol99/go-marathon
|
network.go
|
SetMode
|
func (n *PodNetwork) SetMode(mode PodNetworkMode) *PodNetwork {
n.Mode = mode
return n
}
|
go
|
func (n *PodNetwork) SetMode(mode PodNetworkMode) *PodNetwork {
n.Mode = mode
return n
}
|
[
"func",
"(",
"n",
"*",
"PodNetwork",
")",
"SetMode",
"(",
"mode",
"PodNetworkMode",
")",
"*",
"PodNetwork",
"{",
"n",
".",
"Mode",
"=",
"mode",
"\n",
"return",
"n",
"\n",
"}"
] |
// SetMode sets the mode of a PodNetwork
|
[
"SetMode",
"sets",
"the",
"mode",
"of",
"a",
"PodNetwork"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L85-L88
|
16,992 |
gambol99/go-marathon
|
network.go
|
Label
|
func (n *PodNetwork) Label(key, value string) *PodNetwork {
n.Labels[key] = value
return n
}
|
go
|
func (n *PodNetwork) Label(key, value string) *PodNetwork {
n.Labels[key] = value
return n
}
|
[
"func",
"(",
"n",
"*",
"PodNetwork",
")",
"Label",
"(",
"key",
",",
"value",
"string",
")",
"*",
"PodNetwork",
"{",
"n",
".",
"Labels",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"n",
"\n",
"}"
] |
// Label sets a label of a PodNetwork
|
[
"Label",
"sets",
"a",
"label",
"of",
"a",
"PodNetwork"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L91-L94
|
16,993 |
gambol99/go-marathon
|
network.go
|
SetName
|
func (e *PodEndpoint) SetName(name string) *PodEndpoint {
e.Name = name
return e
}
|
go
|
func (e *PodEndpoint) SetName(name string) *PodEndpoint {
e.Name = name
return e
}
|
[
"func",
"(",
"e",
"*",
"PodEndpoint",
")",
"SetName",
"(",
"name",
"string",
")",
"*",
"PodEndpoint",
"{",
"e",
".",
"Name",
"=",
"name",
"\n",
"return",
"e",
"\n",
"}"
] |
// SetName sets the name for a PodEndpoint
|
[
"SetName",
"sets",
"the",
"name",
"for",
"a",
"PodEndpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L97-L100
|
16,994 |
gambol99/go-marathon
|
network.go
|
SetContainerPort
|
func (e *PodEndpoint) SetContainerPort(port int) *PodEndpoint {
e.ContainerPort = port
return e
}
|
go
|
func (e *PodEndpoint) SetContainerPort(port int) *PodEndpoint {
e.ContainerPort = port
return e
}
|
[
"func",
"(",
"e",
"*",
"PodEndpoint",
")",
"SetContainerPort",
"(",
"port",
"int",
")",
"*",
"PodEndpoint",
"{",
"e",
".",
"ContainerPort",
"=",
"port",
"\n",
"return",
"e",
"\n",
"}"
] |
// SetContainerPort sets the container port for a PodEndpoint
|
[
"SetContainerPort",
"sets",
"the",
"container",
"port",
"for",
"a",
"PodEndpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L103-L106
|
16,995 |
gambol99/go-marathon
|
network.go
|
SetHostPort
|
func (e *PodEndpoint) SetHostPort(port int) *PodEndpoint {
e.HostPort = port
return e
}
|
go
|
func (e *PodEndpoint) SetHostPort(port int) *PodEndpoint {
e.HostPort = port
return e
}
|
[
"func",
"(",
"e",
"*",
"PodEndpoint",
")",
"SetHostPort",
"(",
"port",
"int",
")",
"*",
"PodEndpoint",
"{",
"e",
".",
"HostPort",
"=",
"port",
"\n",
"return",
"e",
"\n",
"}"
] |
// SetHostPort sets the host port for a PodEndpoint
|
[
"SetHostPort",
"sets",
"the",
"host",
"port",
"for",
"a",
"PodEndpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L109-L112
|
16,996 |
gambol99/go-marathon
|
network.go
|
AddProtocol
|
func (e *PodEndpoint) AddProtocol(protocol string) *PodEndpoint {
e.Protocol = append(e.Protocol, protocol)
return e
}
|
go
|
func (e *PodEndpoint) AddProtocol(protocol string) *PodEndpoint {
e.Protocol = append(e.Protocol, protocol)
return e
}
|
[
"func",
"(",
"e",
"*",
"PodEndpoint",
")",
"AddProtocol",
"(",
"protocol",
"string",
")",
"*",
"PodEndpoint",
"{",
"e",
".",
"Protocol",
"=",
"append",
"(",
"e",
".",
"Protocol",
",",
"protocol",
")",
"\n",
"return",
"e",
"\n",
"}"
] |
// AddProtocol appends a protocol for a PodEndpoint
|
[
"AddProtocol",
"appends",
"a",
"protocol",
"for",
"a",
"PodEndpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L115-L118
|
16,997 |
gambol99/go-marathon
|
network.go
|
Label
|
func (e *PodEndpoint) Label(key, value string) *PodEndpoint {
e.Labels[key] = value
return e
}
|
go
|
func (e *PodEndpoint) Label(key, value string) *PodEndpoint {
e.Labels[key] = value
return e
}
|
[
"func",
"(",
"e",
"*",
"PodEndpoint",
")",
"Label",
"(",
"key",
",",
"value",
"string",
")",
"*",
"PodEndpoint",
"{",
"e",
".",
"Labels",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"e",
"\n",
"}"
] |
// Label sets a label for a PodEndpoint
|
[
"Label",
"sets",
"a",
"label",
"for",
"a",
"PodEndpoint"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/network.go#L121-L124
|
16,998 |
gambol99/go-marathon
|
pod_instance.go
|
DeletePodInstances
|
func (r *marathonClient) DeletePodInstances(name string, instances []string) ([]*PodInstance, error) {
uri := buildPodInstancesURI(name)
var result []*PodInstance
if err := r.apiDelete(uri, instances, &result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) DeletePodInstances(name string, instances []string) ([]*PodInstance, error) {
uri := buildPodInstancesURI(name)
var result []*PodInstance
if err := r.apiDelete(uri, instances, &result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"DeletePodInstances",
"(",
"name",
"string",
",",
"instances",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"PodInstance",
",",
"error",
")",
"{",
"uri",
":=",
"buildPodInstancesURI",
"(",
"name",
")",
"\n",
"var",
"result",
"[",
"]",
"*",
"PodInstance",
"\n",
"if",
"err",
":=",
"r",
".",
"apiDelete",
"(",
"uri",
",",
"instances",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// DeletePodInstances deletes all instances of the named pod
|
[
"DeletePodInstances",
"deletes",
"all",
"instances",
"of",
"the",
"named",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_instance.go#L82-L90
|
16,999 |
gambol99/go-marathon
|
pod_instance.go
|
DeletePodInstance
|
func (r *marathonClient) DeletePodInstance(name, instance string) (*PodInstance, error) {
uri := fmt.Sprintf("%s/%s", buildPodInstancesURI(name), instance)
result := new(PodInstance)
if err := r.apiDelete(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func (r *marathonClient) DeletePodInstance(name, instance string) (*PodInstance, error) {
uri := fmt.Sprintf("%s/%s", buildPodInstancesURI(name), instance)
result := new(PodInstance)
if err := r.apiDelete(uri, nil, result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"(",
"r",
"*",
"marathonClient",
")",
"DeletePodInstance",
"(",
"name",
",",
"instance",
"string",
")",
"(",
"*",
"PodInstance",
",",
"error",
")",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"buildPodInstancesURI",
"(",
"name",
")",
",",
"instance",
")",
"\n",
"result",
":=",
"new",
"(",
"PodInstance",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"apiDelete",
"(",
"uri",
",",
"nil",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// DeletePodInstance deletes a specific instance of a pod
|
[
"DeletePodInstance",
"deletes",
"a",
"specific",
"instance",
"of",
"a",
"pod"
] |
80365667fd5354cd063520a8ca8f53dfad6e6c81
|
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_instance.go#L93-L101
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.