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
17,000
gambol99/go-marathon
pod_status.go
PodStatus
func (r *marathonClient) PodStatus(name string) (*PodStatus, error) { var podStatus PodStatus if err := r.apiGet(buildPodStatusURI(name), nil, &podStatus); err != nil { return nil, err } return &podStatus, nil }
go
func (r *marathonClient) PodStatus(name string) (*PodStatus, error) { var podStatus PodStatus if err := r.apiGet(buildPodStatusURI(name), nil, &podStatus); err != nil { return nil, err } return &podStatus, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "PodStatus", "(", "name", "string", ")", "(", "*", "PodStatus", ",", "error", ")", "{", "var", "podStatus", "PodStatus", "\n\n", "if", "err", ":=", "r", ".", "apiGet", "(", "buildPodStatusURI", "(", "name", ")", ",", "nil", ",", "&", "podStatus", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "podStatus", ",", "nil", "\n", "}" ]
// PodStatus retrieves the pod configuration from marathon
[ "PodStatus", "retrieves", "the", "pod", "configuration", "from", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_status.go#L68-L76
17,001
gambol99/go-marathon
pod_status.go
PodStatuses
func (r *marathonClient) PodStatuses() ([]*PodStatus, error) { var podStatuses []*PodStatus if err := r.apiGet(buildPodStatusURI(""), nil, &podStatuses); err != nil { return nil, err } return podStatuses, nil }
go
func (r *marathonClient) PodStatuses() ([]*PodStatus, error) { var podStatuses []*PodStatus if err := r.apiGet(buildPodStatusURI(""), nil, &podStatuses); err != nil { return nil, err } return podStatuses, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "PodStatuses", "(", ")", "(", "[", "]", "*", "PodStatus", ",", "error", ")", "{", "var", "podStatuses", "[", "]", "*", "PodStatus", "\n\n", "if", "err", ":=", "r", ".", "apiGet", "(", "buildPodStatusURI", "(", "\"", "\"", ")", ",", "nil", ",", "&", "podStatuses", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "podStatuses", ",", "nil", "\n", "}" ]
// PodStatuses retrieves all pod configuration from marathon
[ "PodStatuses", "retrieves", "all", "pod", "configuration", "from", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_status.go#L79-L87
17,002
gambol99/go-marathon
pod_status.go
WaitOnPod
func (r *marathonClient) WaitOnPod(name string, timeout time.Duration) error { return r.wait(name, timeout, r.PodIsRunning) }
go
func (r *marathonClient) WaitOnPod(name string, timeout time.Duration) error { return r.wait(name, timeout, r.PodIsRunning) }
[ "func", "(", "r", "*", "marathonClient", ")", "WaitOnPod", "(", "name", "string", ",", "timeout", "time", ".", "Duration", ")", "error", "{", "return", "r", ".", "wait", "(", "name", ",", "timeout", ",", "r", ".", "PodIsRunning", ")", "\n", "}" ]
// WaitOnPod blocks until a pod to be deployed
[ "WaitOnPod", "blocks", "until", "a", "pod", "to", "be", "deployed" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_status.go#L90-L92
17,003
gambol99/go-marathon
pod_status.go
PodIsRunning
func (r *marathonClient) PodIsRunning(name string) bool { podStatus, err := r.PodStatus(name) if apiErr, ok := err.(*APIError); ok && apiErr.ErrCode == ErrCodeNotFound { return false } if err == nil && podStatus.Status == PodStateStable { return true } return false }
go
func (r *marathonClient) PodIsRunning(name string) bool { podStatus, err := r.PodStatus(name) if apiErr, ok := err.(*APIError); ok && apiErr.ErrCode == ErrCodeNotFound { return false } if err == nil && podStatus.Status == PodStateStable { return true } return false }
[ "func", "(", "r", "*", "marathonClient", ")", "PodIsRunning", "(", "name", "string", ")", "bool", "{", "podStatus", ",", "err", ":=", "r", ".", "PodStatus", "(", "name", ")", "\n", "if", "apiErr", ",", "ok", ":=", "err", ".", "(", "*", "APIError", ")", ";", "ok", "&&", "apiErr", ".", "ErrCode", "==", "ErrCodeNotFound", "{", "return", "false", "\n", "}", "\n", "if", "err", "==", "nil", "&&", "podStatus", ".", "Status", "==", "PodStateStable", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// PodIsRunning returns whether the pod is stably running
[ "PodIsRunning", "returns", "whether", "the", "pod", "is", "stably", "running" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_status.go#L95-L104
17,004
gambol99/go-marathon
readiness.go
SetName
func (rc *ReadinessCheck) SetName(name string) *ReadinessCheck { rc.Name = &name return rc }
go
func (rc *ReadinessCheck) SetName(name string) *ReadinessCheck { rc.Name = &name return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetName", "(", "name", "string", ")", "*", "ReadinessCheck", "{", "rc", ".", "Name", "=", "&", "name", "\n", "return", "rc", "\n", "}" ]
// SetName sets the name on the readiness check.
[ "SetName", "sets", "the", "name", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L34-L37
17,005
gambol99/go-marathon
readiness.go
SetProtocol
func (rc *ReadinessCheck) SetProtocol(proto string) *ReadinessCheck { rc.Protocol = proto return rc }
go
func (rc *ReadinessCheck) SetProtocol(proto string) *ReadinessCheck { rc.Protocol = proto return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetProtocol", "(", "proto", "string", ")", "*", "ReadinessCheck", "{", "rc", ".", "Protocol", "=", "proto", "\n", "return", "rc", "\n", "}" ]
// SetProtocol sets the protocol on the readiness check.
[ "SetProtocol", "sets", "the", "protocol", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L40-L43
17,006
gambol99/go-marathon
readiness.go
SetPath
func (rc *ReadinessCheck) SetPath(p string) *ReadinessCheck { rc.Path = p return rc }
go
func (rc *ReadinessCheck) SetPath(p string) *ReadinessCheck { rc.Path = p return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetPath", "(", "p", "string", ")", "*", "ReadinessCheck", "{", "rc", ".", "Path", "=", "p", "\n", "return", "rc", "\n", "}" ]
// SetPath sets the path on the readiness check.
[ "SetPath", "sets", "the", "path", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L46-L49
17,007
gambol99/go-marathon
readiness.go
SetPortName
func (rc *ReadinessCheck) SetPortName(name string) *ReadinessCheck { rc.PortName = name return rc }
go
func (rc *ReadinessCheck) SetPortName(name string) *ReadinessCheck { rc.PortName = name return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetPortName", "(", "name", "string", ")", "*", "ReadinessCheck", "{", "rc", ".", "PortName", "=", "name", "\n", "return", "rc", "\n", "}" ]
// SetPortName sets the port name on the readiness check.
[ "SetPortName", "sets", "the", "port", "name", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L52-L55
17,008
gambol99/go-marathon
readiness.go
SetInterval
func (rc *ReadinessCheck) SetInterval(interval time.Duration) *ReadinessCheck { secs := int(interval.Seconds()) rc.IntervalSeconds = secs return rc }
go
func (rc *ReadinessCheck) SetInterval(interval time.Duration) *ReadinessCheck { secs := int(interval.Seconds()) rc.IntervalSeconds = secs return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetInterval", "(", "interval", "time", ".", "Duration", ")", "*", "ReadinessCheck", "{", "secs", ":=", "int", "(", "interval", ".", "Seconds", "(", ")", ")", "\n", "rc", ".", "IntervalSeconds", "=", "secs", "\n", "return", "rc", "\n", "}" ]
// SetInterval sets the interval on the readiness check.
[ "SetInterval", "sets", "the", "interval", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L58-L62
17,009
gambol99/go-marathon
readiness.go
SetTimeout
func (rc *ReadinessCheck) SetTimeout(timeout time.Duration) *ReadinessCheck { secs := int(timeout.Seconds()) rc.TimeoutSeconds = secs return rc }
go
func (rc *ReadinessCheck) SetTimeout(timeout time.Duration) *ReadinessCheck { secs := int(timeout.Seconds()) rc.TimeoutSeconds = secs return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetTimeout", "(", "timeout", "time", ".", "Duration", ")", "*", "ReadinessCheck", "{", "secs", ":=", "int", "(", "timeout", ".", "Seconds", "(", ")", ")", "\n", "rc", ".", "TimeoutSeconds", "=", "secs", "\n", "return", "rc", "\n", "}" ]
// SetTimeout sets the timeout on the readiness check.
[ "SetTimeout", "sets", "the", "timeout", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L65-L69
17,010
gambol99/go-marathon
readiness.go
SetHTTPStatusCodesForReady
func (rc *ReadinessCheck) SetHTTPStatusCodesForReady(codes []int) *ReadinessCheck { rc.HTTPStatusCodesForReady = &codes return rc }
go
func (rc *ReadinessCheck) SetHTTPStatusCodesForReady(codes []int) *ReadinessCheck { rc.HTTPStatusCodesForReady = &codes return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetHTTPStatusCodesForReady", "(", "codes", "[", "]", "int", ")", "*", "ReadinessCheck", "{", "rc", ".", "HTTPStatusCodesForReady", "=", "&", "codes", "\n", "return", "rc", "\n", "}" ]
// SetHTTPStatusCodesForReady sets the HTTP status codes for ready on the // readiness check.
[ "SetHTTPStatusCodesForReady", "sets", "the", "HTTP", "status", "codes", "for", "ready", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L73-L76
17,011
gambol99/go-marathon
readiness.go
SetPreserveLastResponse
func (rc *ReadinessCheck) SetPreserveLastResponse(preserve bool) *ReadinessCheck { rc.PreserveLastResponse = &preserve return rc }
go
func (rc *ReadinessCheck) SetPreserveLastResponse(preserve bool) *ReadinessCheck { rc.PreserveLastResponse = &preserve return rc }
[ "func", "(", "rc", "*", "ReadinessCheck", ")", "SetPreserveLastResponse", "(", "preserve", "bool", ")", "*", "ReadinessCheck", "{", "rc", ".", "PreserveLastResponse", "=", "&", "preserve", "\n", "return", "rc", "\n", "}" ]
// SetPreserveLastResponse sets the preserve last response flag on the // readiness check.
[ "SetPreserveLastResponse", "sets", "the", "preserve", "last", "response", "flag", "on", "the", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/readiness.go#L80-L83
17,012
gambol99/go-marathon
deployment.go
Deployments
func (r *marathonClient) Deployments() ([]*Deployment, error) { var deployments []*Deployment err := r.apiGet(marathonAPIDeployments, nil, &deployments) if err != nil { return nil, err } // Allows loading of deployment steps from the Marathon v1.X API // Implements a fix for issue https://github.com/gambol99/go-marathon/issues/153 for _, deployment := range deployments { // Unmarshal pre-v1.X step if err := json.Unmarshal(deployment.XXStepsRaw, &deployment.Steps); err != nil { deployment.Steps = make([][]*DeploymentStep, 0) var steps []*StepActions // Unmarshal v1.X Marathon step if err := json.Unmarshal(deployment.XXStepsRaw, &steps); err != nil { return nil, err } for stepIndex, step := range steps { deployment.Steps = append(deployment.Steps, make([]*DeploymentStep, len(step.Actions))) for actionIndex, action := range step.Actions { var stepAction string if action.Type != "" { stepAction = action.Type } else { stepAction = action.Action } deployment.Steps[stepIndex][actionIndex] = &DeploymentStep{ Action: stepAction, App: action.App, } } } } } return deployments, nil }
go
func (r *marathonClient) Deployments() ([]*Deployment, error) { var deployments []*Deployment err := r.apiGet(marathonAPIDeployments, nil, &deployments) if err != nil { return nil, err } // Allows loading of deployment steps from the Marathon v1.X API // Implements a fix for issue https://github.com/gambol99/go-marathon/issues/153 for _, deployment := range deployments { // Unmarshal pre-v1.X step if err := json.Unmarshal(deployment.XXStepsRaw, &deployment.Steps); err != nil { deployment.Steps = make([][]*DeploymentStep, 0) var steps []*StepActions // Unmarshal v1.X Marathon step if err := json.Unmarshal(deployment.XXStepsRaw, &steps); err != nil { return nil, err } for stepIndex, step := range steps { deployment.Steps = append(deployment.Steps, make([]*DeploymentStep, len(step.Actions))) for actionIndex, action := range step.Actions { var stepAction string if action.Type != "" { stepAction = action.Type } else { stepAction = action.Action } deployment.Steps[stepIndex][actionIndex] = &DeploymentStep{ Action: stepAction, App: action.App, } } } } } return deployments, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "Deployments", "(", ")", "(", "[", "]", "*", "Deployment", ",", "error", ")", "{", "var", "deployments", "[", "]", "*", "Deployment", "\n", "err", ":=", "r", ".", "apiGet", "(", "marathonAPIDeployments", ",", "nil", ",", "&", "deployments", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Allows loading of deployment steps from the Marathon v1.X API", "// Implements a fix for issue https://github.com/gambol99/go-marathon/issues/153", "for", "_", ",", "deployment", ":=", "range", "deployments", "{", "// Unmarshal pre-v1.X step", "if", "err", ":=", "json", ".", "Unmarshal", "(", "deployment", ".", "XXStepsRaw", ",", "&", "deployment", ".", "Steps", ")", ";", "err", "!=", "nil", "{", "deployment", ".", "Steps", "=", "make", "(", "[", "]", "[", "]", "*", "DeploymentStep", ",", "0", ")", "\n", "var", "steps", "[", "]", "*", "StepActions", "\n", "// Unmarshal v1.X Marathon step", "if", "err", ":=", "json", ".", "Unmarshal", "(", "deployment", ".", "XXStepsRaw", ",", "&", "steps", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "stepIndex", ",", "step", ":=", "range", "steps", "{", "deployment", ".", "Steps", "=", "append", "(", "deployment", ".", "Steps", ",", "make", "(", "[", "]", "*", "DeploymentStep", ",", "len", "(", "step", ".", "Actions", ")", ")", ")", "\n", "for", "actionIndex", ",", "action", ":=", "range", "step", ".", "Actions", "{", "var", "stepAction", "string", "\n", "if", "action", ".", "Type", "!=", "\"", "\"", "{", "stepAction", "=", "action", ".", "Type", "\n", "}", "else", "{", "stepAction", "=", "action", ".", "Action", "\n", "}", "\n", "deployment", ".", "Steps", "[", "stepIndex", "]", "[", "actionIndex", "]", "=", "&", "DeploymentStep", "{", "Action", ":", "stepAction", ",", "App", ":", "action", ".", "App", ",", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "deployments", ",", "nil", "\n", "}" ]
// Deployments retrieves a list of current deployments
[ "Deployments", "retrieves", "a", "list", "of", "current", "deployments" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/deployment.go#L70-L105
17,013
gambol99/go-marathon
volume.go
NewPodVolume
func NewPodVolume(name, path string) *PodVolume { return &PodVolume{ Name: name, Host: path, } }
go
func NewPodVolume(name, path string) *PodVolume { return &PodVolume{ Name: name, Host: path, } }
[ "func", "NewPodVolume", "(", "name", ",", "path", "string", ")", "*", "PodVolume", "{", "return", "&", "PodVolume", "{", "Name", ":", "name", ",", "Host", ":", "path", ",", "}", "\n", "}" ]
// NewPodVolume creates a new PodVolume
[ "NewPodVolume", "creates", "a", "new", "PodVolume" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/volume.go#L34-L39
17,014
gambol99/go-marathon
volume.go
NewPodVolumeMount
func NewPodVolumeMount(name, mount string) *PodVolumeMount { return &PodVolumeMount{ Name: name, MountPath: mount, } }
go
func NewPodVolumeMount(name, mount string) *PodVolumeMount { return &PodVolumeMount{ Name: name, MountPath: mount, } }
[ "func", "NewPodVolumeMount", "(", "name", ",", "mount", "string", ")", "*", "PodVolumeMount", "{", "return", "&", "PodVolumeMount", "{", "Name", ":", "name", ",", "MountPath", ":", "mount", ",", "}", "\n", "}" ]
// NewPodVolumeMount creates a new PodVolumeMount
[ "NewPodVolumeMount", "creates", "a", "new", "PodVolumeMount" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/volume.go#L42-L47
17,015
gambol99/go-marathon
volume.go
SetPersistentVolume
func (pv *PodVolume) SetPersistentVolume(p *PersistentVolume) *PodVolume { pv.Persistent = p return pv }
go
func (pv *PodVolume) SetPersistentVolume(p *PersistentVolume) *PodVolume { pv.Persistent = p return pv }
[ "func", "(", "pv", "*", "PodVolume", ")", "SetPersistentVolume", "(", "p", "*", "PersistentVolume", ")", "*", "PodVolume", "{", "pv", ".", "Persistent", "=", "p", "\n", "return", "pv", "\n", "}" ]
// SetPersistentVolume sets the persistence settings of a PodVolume
[ "SetPersistentVolume", "sets", "the", "persistence", "settings", "of", "a", "PodVolume" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/volume.go#L50-L53
17,016
gambol99/go-marathon
info.go
Info
func (r *marathonClient) Info() (*Info, error) { info := new(Info) if err := r.apiGet(marathonAPIInfo, nil, info); err != nil { return nil, err } return info, nil }
go
func (r *marathonClient) Info() (*Info, error) { info := new(Info) if err := r.apiGet(marathonAPIInfo, nil, info); err != nil { return nil, err } return info, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "Info", "(", ")", "(", "*", "Info", ",", "error", ")", "{", "info", ":=", "new", "(", "Info", ")", "\n", "if", "err", ":=", "r", ".", "apiGet", "(", "marathonAPIInfo", ",", "nil", ",", "info", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "info", ",", "nil", "\n", "}" ]
// Info retrieves the info stats from marathon
[ "Info", "retrieves", "the", "info", "stats", "from", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/info.go#L68-L75
17,017
gambol99/go-marathon
info.go
Leader
func (r *marathonClient) Leader() (string, error) { var leader struct { Leader string `json:"leader"` } if err := r.apiGet(marathonAPILeader, nil, &leader); err != nil { return "", err } return leader.Leader, nil }
go
func (r *marathonClient) Leader() (string, error) { var leader struct { Leader string `json:"leader"` } if err := r.apiGet(marathonAPILeader, nil, &leader); err != nil { return "", err } return leader.Leader, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "Leader", "(", ")", "(", "string", ",", "error", ")", "{", "var", "leader", "struct", "{", "Leader", "string", "`json:\"leader\"`", "\n", "}", "\n", "if", "err", ":=", "r", ".", "apiGet", "(", "marathonAPILeader", ",", "nil", ",", "&", "leader", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "leader", ".", "Leader", ",", "nil", "\n", "}" ]
// Leader retrieves the current marathon leader node
[ "Leader", "retrieves", "the", "current", "marathon", "leader", "node" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/info.go#L78-L87
17,018
gambol99/go-marathon
info.go
AbdicateLeader
func (r *marathonClient) AbdicateLeader() (string, error) { var message struct { Message string `json:"message"` } if err := r.apiDelete(marathonAPILeader, nil, &message); err != nil { return "", err } return message.Message, nil }
go
func (r *marathonClient) AbdicateLeader() (string, error) { var message struct { Message string `json:"message"` } if err := r.apiDelete(marathonAPILeader, nil, &message); err != nil { return "", err } return message.Message, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "AbdicateLeader", "(", ")", "(", "string", ",", "error", ")", "{", "var", "message", "struct", "{", "Message", "string", "`json:\"message\"`", "\n", "}", "\n\n", "if", "err", ":=", "r", ".", "apiDelete", "(", "marathonAPILeader", ",", "nil", ",", "&", "message", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "message", ".", "Message", ",", "nil", "\n", "}" ]
// AbdicateLeader abdicates the marathon leadership
[ "AbdicateLeader", "abdicates", "the", "marathon", "leadership" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/info.go#L90-L100
17,019
gambol99/go-marathon
pod_container_image.go
SetKind
func (i *PodContainerImage) SetKind(typ ImageType) *PodContainerImage { i.Kind = typ return i }
go
func (i *PodContainerImage) SetKind(typ ImageType) *PodContainerImage { i.Kind = typ return i }
[ "func", "(", "i", "*", "PodContainerImage", ")", "SetKind", "(", "typ", "ImageType", ")", "*", "PodContainerImage", "{", "i", ".", "Kind", "=", "typ", "\n", "return", "i", "\n", "}" ]
// SetKind sets the Kind of the image
[ "SetKind", "sets", "the", "Kind", "of", "the", "image" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container_image.go#L43-L46
17,020
gambol99/go-marathon
pod_container_image.go
SetID
func (i *PodContainerImage) SetID(id string) *PodContainerImage { i.ID = id return i }
go
func (i *PodContainerImage) SetID(id string) *PodContainerImage { i.ID = id return i }
[ "func", "(", "i", "*", "PodContainerImage", ")", "SetID", "(", "id", "string", ")", "*", "PodContainerImage", "{", "i", ".", "ID", "=", "id", "\n", "return", "i", "\n", "}" ]
// SetID sets the ID of the image
[ "SetID", "sets", "the", "ID", "of", "the", "image" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container_image.go#L49-L52
17,021
gambol99/go-marathon
group.go
Groups
func (r *marathonClient) Groups() (*Groups, error) { groups := new(Groups) if err := r.apiGet(marathonAPIGroups, "", groups); err != nil { return nil, err } return groups, nil }
go
func (r *marathonClient) Groups() (*Groups, error) { groups := new(Groups) if err := r.apiGet(marathonAPIGroups, "", groups); err != nil { return nil, err } return groups, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "Groups", "(", ")", "(", "*", "Groups", ",", "error", ")", "{", "groups", ":=", "new", "(", "Groups", ")", "\n", "if", "err", ":=", "r", ".", "apiGet", "(", "marathonAPIGroups", ",", "\"", "\"", ",", "groups", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "groups", ",", "nil", "\n", "}" ]
// Groups retrieves a list of all the groups from marathon
[ "Groups", "retrieves", "a", "list", "of", "all", "the", "groups", "from", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/group.go#L88-L94
17,022
gambol99/go-marathon
client.go
buildAPIRequest
func (r *marathonClient) buildAPIRequest(method, path string, reader io.Reader) (request *http.Request, member string, err error) { // Grab a member from the cluster member, err = r.hosts.getMember() if err != nil { return nil, "", ErrMarathonDown } // Build the HTTP request to Marathon request, err = r.client.buildMarathonJSONRequest(method, member, path, reader) if err != nil { return nil, member, newRequestError{err} } return request, member, nil }
go
func (r *marathonClient) buildAPIRequest(method, path string, reader io.Reader) (request *http.Request, member string, err error) { // Grab a member from the cluster member, err = r.hosts.getMember() if err != nil { return nil, "", ErrMarathonDown } // Build the HTTP request to Marathon request, err = r.client.buildMarathonJSONRequest(method, member, path, reader) if err != nil { return nil, member, newRequestError{err} } return request, member, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "buildAPIRequest", "(", "method", ",", "path", "string", ",", "reader", "io", ".", "Reader", ")", "(", "request", "*", "http", ".", "Request", ",", "member", "string", ",", "err", "error", ")", "{", "// Grab a member from the cluster", "member", ",", "err", "=", "r", ".", "hosts", ".", "getMember", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "\"", "\"", ",", "ErrMarathonDown", "\n", "}", "\n\n", "// Build the HTTP request to Marathon", "request", ",", "err", "=", "r", ".", "client", ".", "buildMarathonJSONRequest", "(", "method", ",", "member", ",", "path", ",", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "member", ",", "newRequestError", "{", "err", "}", "\n", "}", "\n", "return", "request", ",", "member", ",", "nil", "\n", "}" ]
// buildAPIRequest creates a default API request. // It fails when there is no available member in the cluster anymore or when the request can not be built.
[ "buildAPIRequest", "creates", "a", "default", "API", "request", ".", "It", "fails", "when", "there", "is", "no", "available", "member", "in", "the", "cluster", "anymore", "or", "when", "the", "request", "can", "not", "be", "built", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/client.go#L429-L442
17,023
gambol99/go-marathon
client.go
oneLogLine
func oneLogLine(in []byte) []byte { return bytes.Replace(oneLogLineRegex.ReplaceAll(in, nil), []byte("\n"), []byte("\\n "), -1) }
go
func oneLogLine(in []byte) []byte { return bytes.Replace(oneLogLineRegex.ReplaceAll(in, nil), []byte("\n"), []byte("\\n "), -1) }
[ "func", "oneLogLine", "(", "in", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "bytes", ".", "Replace", "(", "oneLogLineRegex", ".", "ReplaceAll", "(", "in", ",", "nil", ")", ",", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ",", "[", "]", "byte", "(", "\"", "\\\\", "\"", ")", ",", "-", "1", ")", "\n", "}" ]
// oneLogLine removes indentation at the beginning of each line and // escapes new line characters.
[ "oneLogLine", "removes", "indentation", "at", "the", "beginning", "of", "each", "line", "and", "escapes", "new", "line", "characters", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/client.go#L492-L494
17,024
gambol99/go-marathon
application.go
SetIPAddressPerTask
func (r *Application) SetIPAddressPerTask(ipAddressPerTask IPAddressPerTask) *Application { r.Ports = make([]int, 0) r.EmptyPortDefinitions() r.IPAddressPerTask = &ipAddressPerTask return r }
go
func (r *Application) SetIPAddressPerTask(ipAddressPerTask IPAddressPerTask) *Application { r.Ports = make([]int, 0) r.EmptyPortDefinitions() r.IPAddressPerTask = &ipAddressPerTask return r }
[ "func", "(", "r", "*", "Application", ")", "SetIPAddressPerTask", "(", "ipAddressPerTask", "IPAddressPerTask", ")", "*", "Application", "{", "r", ".", "Ports", "=", "make", "(", "[", "]", "int", ",", "0", ")", "\n", "r", ".", "EmptyPortDefinitions", "(", ")", "\n", "r", ".", "IPAddressPerTask", "=", "&", "ipAddressPerTask", "\n\n", "return", "r", "\n", "}" ]
// SetIPAddressPerTask defines that the application will have a IP address defines by a external agent. // This configuration is not allowed to be used with Port or PortDefinitions. Thus, the implementation // clears both.
[ "SetIPAddressPerTask", "defines", "that", "the", "application", "will", "have", "a", "IP", "address", "defines", "by", "a", "external", "agent", ".", "This", "configuration", "is", "not", "allowed", "to", "be", "used", "with", "Port", "or", "PortDefinitions", ".", "Thus", "the", "implementation", "clears", "both", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L168-L174
17,025
gambol99/go-marathon
application.go
Command
func (r *Application) Command(cmd string) *Application { r.Cmd = &cmd return r }
go
func (r *Application) Command(cmd string) *Application { r.Cmd = &cmd return r }
[ "func", "(", "r", "*", "Application", ")", "Command", "(", "cmd", "string", ")", "*", "Application", "{", "r", ".", "Cmd", "=", "&", "cmd", "\n", "return", "r", "\n", "}" ]
// Command sets the cmd of the application
[ "Command", "sets", "the", "cmd", "of", "the", "application" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L190-L193
17,026
gambol99/go-marathon
application.go
AllTaskRunning
func (r *Application) AllTaskRunning() bool { if r.Instances == nil || *r.Instances == 0 { return true } if r.Tasks == nil { return false } if r.TasksRunning == *r.Instances { return true } return false }
go
func (r *Application) AllTaskRunning() bool { if r.Instances == nil || *r.Instances == 0 { return true } if r.Tasks == nil { return false } if r.TasksRunning == *r.Instances { return true } return false }
[ "func", "(", "r", "*", "Application", ")", "AllTaskRunning", "(", ")", "bool", "{", "if", "r", ".", "Instances", "==", "nil", "||", "*", "r", ".", "Instances", "==", "0", "{", "return", "true", "\n", "}", "\n", "if", "r", ".", "Tasks", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "TasksRunning", "==", "*", "r", ".", "Instances", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// AllTaskRunning checks to see if all the application tasks are running, i.e. the instances is equal // to the number of running tasks
[ "AllTaskRunning", "checks", "to", "see", "if", "all", "the", "application", "tasks", "are", "running", "i", ".", "e", ".", "the", "instances", "is", "equal", "to", "the", "number", "of", "running", "tasks" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L228-L239
17,027
gambol99/go-marathon
application.go
AddPortDefinition
func (r *Application) AddPortDefinition(portDefinition PortDefinition) *Application { if r.PortDefinitions == nil { r.EmptyPortDefinitions() } portDefinitions := *r.PortDefinitions portDefinitions = append(portDefinitions, portDefinition) r.PortDefinitions = &portDefinitions return r }
go
func (r *Application) AddPortDefinition(portDefinition PortDefinition) *Application { if r.PortDefinitions == nil { r.EmptyPortDefinitions() } portDefinitions := *r.PortDefinitions portDefinitions = append(portDefinitions, portDefinition) r.PortDefinitions = &portDefinitions return r }
[ "func", "(", "r", "*", "Application", ")", "AddPortDefinition", "(", "portDefinition", "PortDefinition", ")", "*", "Application", "{", "if", "r", ".", "PortDefinitions", "==", "nil", "{", "r", ".", "EmptyPortDefinitions", "(", ")", "\n", "}", "\n\n", "portDefinitions", ":=", "*", "r", ".", "PortDefinitions", "\n", "portDefinitions", "=", "append", "(", "portDefinitions", ",", "portDefinition", ")", "\n", "r", ".", "PortDefinitions", "=", "&", "portDefinitions", "\n", "return", "r", "\n", "}" ]
// AddPortDefinition adds a port definition. Port definitions are used to define ports that // should be considered part of a resource. They are necessary when you are using HOST // networking and no port mappings are specified.
[ "AddPortDefinition", "adds", "a", "port", "definition", ".", "Port", "definitions", "are", "used", "to", "define", "ports", "that", "should", "be", "considered", "part", "of", "a", "resource", ".", "They", "are", "necessary", "when", "you", "are", "using", "HOST", "networking", "and", "no", "port", "mappings", "are", "specified", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L265-L274
17,028
gambol99/go-marathon
application.go
SetExecutor
func (r *Application) SetExecutor(executor string) *Application { r.Executor = &executor return r }
go
func (r *Application) SetExecutor(executor string) *Application { r.Executor = &executor return r }
[ "func", "(", "r", "*", "Application", ")", "SetExecutor", "(", "executor", "string", ")", "*", "Application", "{", "r", ".", "Executor", "=", "&", "executor", "\n\n", "return", "r", "\n", "}" ]
// SetExecutor sets the executor
[ "SetExecutor", "sets", "the", "executor" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L414-L418
17,029
gambol99/go-marathon
application.go
AddHealthCheck
func (r *Application) AddHealthCheck(healthCheck HealthCheck) *Application { if r.HealthChecks == nil { r.EmptyHealthChecks() } healthChecks := *r.HealthChecks healthChecks = append(healthChecks, healthCheck) r.HealthChecks = &healthChecks return r }
go
func (r *Application) AddHealthCheck(healthCheck HealthCheck) *Application { if r.HealthChecks == nil { r.EmptyHealthChecks() } healthChecks := *r.HealthChecks healthChecks = append(healthChecks, healthCheck) r.HealthChecks = &healthChecks return r }
[ "func", "(", "r", "*", "Application", ")", "AddHealthCheck", "(", "healthCheck", "HealthCheck", ")", "*", "Application", "{", "if", "r", ".", "HealthChecks", "==", "nil", "{", "r", ".", "EmptyHealthChecks", "(", ")", "\n", "}", "\n\n", "healthChecks", ":=", "*", "r", ".", "HealthChecks", "\n", "healthChecks", "=", "append", "(", "healthChecks", ",", "healthCheck", ")", "\n", "r", ".", "HealthChecks", "=", "&", "healthChecks", "\n\n", "return", "r", "\n", "}" ]
// AddHealthCheck adds a health check // healthCheck the health check that should be added
[ "AddHealthCheck", "adds", "a", "health", "check", "healthCheck", "the", "health", "check", "that", "should", "be", "added" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L422-L432
17,030
gambol99/go-marathon
application.go
HasHealthChecks
func (r *Application) HasHealthChecks() bool { return r.HealthChecks != nil && len(*r.HealthChecks) > 0 }
go
func (r *Application) HasHealthChecks() bool { return r.HealthChecks != nil && len(*r.HealthChecks) > 0 }
[ "func", "(", "r", "*", "Application", ")", "HasHealthChecks", "(", ")", "bool", "{", "return", "r", ".", "HealthChecks", "!=", "nil", "&&", "len", "(", "*", "r", ".", "HealthChecks", ")", ">", "0", "\n", "}" ]
// HasHealthChecks is a helper method, used to check if an application has health checks
[ "HasHealthChecks", "is", "a", "helper", "method", "used", "to", "check", "if", "an", "application", "has", "health", "checks" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L444-L446
17,031
gambol99/go-marathon
application.go
AddReadinessCheck
func (r *Application) AddReadinessCheck(readinessCheck ReadinessCheck) *Application { if r.ReadinessChecks == nil { r.EmptyReadinessChecks() } readinessChecks := *r.ReadinessChecks readinessChecks = append(readinessChecks, readinessCheck) r.ReadinessChecks = &readinessChecks return r }
go
func (r *Application) AddReadinessCheck(readinessCheck ReadinessCheck) *Application { if r.ReadinessChecks == nil { r.EmptyReadinessChecks() } readinessChecks := *r.ReadinessChecks readinessChecks = append(readinessChecks, readinessCheck) r.ReadinessChecks = &readinessChecks return r }
[ "func", "(", "r", "*", "Application", ")", "AddReadinessCheck", "(", "readinessCheck", "ReadinessCheck", ")", "*", "Application", "{", "if", "r", ".", "ReadinessChecks", "==", "nil", "{", "r", ".", "EmptyReadinessChecks", "(", ")", "\n", "}", "\n\n", "readinessChecks", ":=", "*", "r", ".", "ReadinessChecks", "\n", "readinessChecks", "=", "append", "(", "readinessChecks", ",", "readinessCheck", ")", "\n", "r", ".", "ReadinessChecks", "=", "&", "readinessChecks", "\n\n", "return", "r", "\n", "}" ]
// AddReadinessCheck adds a readiness check.
[ "AddReadinessCheck", "adds", "a", "readiness", "check", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L449-L459
17,032
gambol99/go-marathon
application.go
DeploymentIDs
func (r *Application) DeploymentIDs() []*DeploymentID { var deployments []*DeploymentID if r.Deployments == nil { return deployments } // step: extract the deployment id from the result for _, deploy := range r.Deployments { if id, found := deploy["id"]; found { deployment := &DeploymentID{ Version: r.Version, DeploymentID: id, } deployments = append(deployments, deployment) } } return deployments }
go
func (r *Application) DeploymentIDs() []*DeploymentID { var deployments []*DeploymentID if r.Deployments == nil { return deployments } // step: extract the deployment id from the result for _, deploy := range r.Deployments { if id, found := deploy["id"]; found { deployment := &DeploymentID{ Version: r.Version, DeploymentID: id, } deployments = append(deployments, deployment) } } return deployments }
[ "func", "(", "r", "*", "Application", ")", "DeploymentIDs", "(", ")", "[", "]", "*", "DeploymentID", "{", "var", "deployments", "[", "]", "*", "DeploymentID", "\n\n", "if", "r", ".", "Deployments", "==", "nil", "{", "return", "deployments", "\n", "}", "\n\n", "// step: extract the deployment id from the result", "for", "_", ",", "deploy", ":=", "range", "r", ".", "Deployments", "{", "if", "id", ",", "found", ":=", "deploy", "[", "\"", "\"", "]", ";", "found", "{", "deployment", ":=", "&", "DeploymentID", "{", "Version", ":", "r", ".", "Version", ",", "DeploymentID", ":", "id", ",", "}", "\n", "deployments", "=", "append", "(", "deployments", ",", "deployment", ")", "\n", "}", "\n", "}", "\n\n", "return", "deployments", "\n", "}" ]
// DeploymentIDs retrieves the application deployments IDs
[ "DeploymentIDs", "retrieves", "the", "application", "deployments", "IDs" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L469-L488
17,033
gambol99/go-marathon
application.go
SetUpgradeStrategy
func (r *Application) SetUpgradeStrategy(us UpgradeStrategy) *Application { r.UpgradeStrategy = &us return r }
go
func (r *Application) SetUpgradeStrategy(us UpgradeStrategy) *Application { r.UpgradeStrategy = &us return r }
[ "func", "(", "r", "*", "Application", ")", "SetUpgradeStrategy", "(", "us", "UpgradeStrategy", ")", "*", "Application", "{", "r", ".", "UpgradeStrategy", "=", "&", "us", "\n", "return", "r", "\n", "}" ]
// SetUpgradeStrategy sets the upgrade strategy.
[ "SetUpgradeStrategy", "sets", "the", "upgrade", "strategy", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L588-L591
17,034
gambol99/go-marathon
application.go
SetUnreachableStrategy
func (r *Application) SetUnreachableStrategy(us UnreachableStrategy) *Application { r.UnreachableStrategy = &us return r }
go
func (r *Application) SetUnreachableStrategy(us UnreachableStrategy) *Application { r.UnreachableStrategy = &us return r }
[ "func", "(", "r", "*", "Application", ")", "SetUnreachableStrategy", "(", "us", "UnreachableStrategy", ")", "*", "Application", "{", "r", ".", "UnreachableStrategy", "=", "&", "us", "\n", "return", "r", "\n", "}" ]
// SetUnreachableStrategy sets the unreachable strategy.
[ "SetUnreachableStrategy", "sets", "the", "unreachable", "strategy", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L602-L605
17,035
gambol99/go-marathon
application.go
SetResidency
func (r *Application) SetResidency(whenLost TaskLostBehaviorType) *Application { r.Residency = &Residency{ TaskLostBehavior: whenLost, } return r }
go
func (r *Application) SetResidency(whenLost TaskLostBehaviorType) *Application { r.Residency = &Residency{ TaskLostBehavior: whenLost, } return r }
[ "func", "(", "r", "*", "Application", ")", "SetResidency", "(", "whenLost", "TaskLostBehaviorType", ")", "*", "Application", "{", "r", ".", "Residency", "=", "&", "Residency", "{", "TaskLostBehavior", ":", "whenLost", ",", "}", "\n", "return", "r", "\n", "}" ]
// SetResidency sets behavior for resident applications, an application is resident when // it has local persistent volumes set
[ "SetResidency", "sets", "behavior", "for", "resident", "applications", "an", "application", "is", "resident", "when", "it", "has", "local", "persistent", "volumes", "set" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L617-L622
17,036
gambol99/go-marathon
application.go
String
func (r *Application) String() string { s, err := json.MarshalIndent(r, "", " ") if err != nil { return fmt.Sprintf(`{"error": "error decoding type into json: %s"}`, err) } return string(s) }
go
func (r *Application) String() string { s, err := json.MarshalIndent(r, "", " ") if err != nil { return fmt.Sprintf(`{"error": "error decoding type into json: %s"}`, err) } return string(s) }
[ "func", "(", "r", "*", "Application", ")", "String", "(", ")", "string", "{", "s", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "r", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Sprintf", "(", "`{\"error\": \"error decoding type into json: %s\"}`", ",", "err", ")", "\n", "}", "\n\n", "return", "string", "(", "s", ")", "\n", "}" ]
// String returns the json representation of this application
[ "String", "returns", "the", "json", "representation", "of", "this", "application" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L633-L640
17,037
gambol99/go-marathon
application.go
Applications
func (r *marathonClient) Applications(v url.Values) (*Applications, error) { query := v.Encode() if query != "" { query = "?" + query } applications := new(Applications) err := r.apiGet(marathonAPIApps+query, nil, applications) if err != nil { return nil, err } return applications, nil }
go
func (r *marathonClient) Applications(v url.Values) (*Applications, error) { query := v.Encode() if query != "" { query = "?" + query } applications := new(Applications) err := r.apiGet(marathonAPIApps+query, nil, applications) if err != nil { return nil, err } return applications, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "Applications", "(", "v", "url", ".", "Values", ")", "(", "*", "Applications", ",", "error", ")", "{", "query", ":=", "v", ".", "Encode", "(", ")", "\n", "if", "query", "!=", "\"", "\"", "{", "query", "=", "\"", "\"", "+", "query", "\n", "}", "\n\n", "applications", ":=", "new", "(", "Applications", ")", "\n", "err", ":=", "r", ".", "apiGet", "(", "marathonAPIApps", "+", "query", ",", "nil", ",", "applications", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "applications", ",", "nil", "\n", "}" ]
// Applications retrieves an array of all the applications which are running in marathon
[ "Applications", "retrieves", "an", "array", "of", "all", "the", "applications", "which", "are", "running", "in", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L643-L656
17,038
gambol99/go-marathon
application.go
ListApplications
func (r *marathonClient) ListApplications(v url.Values) ([]string, error) { applications, err := r.Applications(v) if err != nil { return nil, err } var list []string for _, application := range applications.Apps { list = append(list, application.ID) } return list, nil }
go
func (r *marathonClient) ListApplications(v url.Values) ([]string, error) { applications, err := r.Applications(v) if err != nil { return nil, err } var list []string for _, application := range applications.Apps { list = append(list, application.ID) } return list, nil }
[ "func", "(", "r", "*", "marathonClient", ")", "ListApplications", "(", "v", "url", ".", "Values", ")", "(", "[", "]", "string", ",", "error", ")", "{", "applications", ",", "err", ":=", "r", ".", "Applications", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "list", "[", "]", "string", "\n", "for", "_", ",", "application", ":=", "range", "applications", ".", "Apps", "{", "list", "=", "append", "(", "list", ",", "application", ".", "ID", ")", "\n", "}", "\n\n", "return", "list", ",", "nil", "\n", "}" ]
// ListApplications retrieves an array of the application names currently running in marathon
[ "ListApplications", "retrieves", "an", "array", "of", "the", "application", "names", "currently", "running", "in", "marathon" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L659-L670
17,039
gambol99/go-marathon
application.go
SetNetwork
func (r *Application) SetNetwork(name string, mode PodNetworkMode) *Application { if r.Networks == nil { r.EmptyNetworks() } network := PodNetwork{Name: name, Mode: mode} networks := *r.Networks networks = append(networks, network) r.Networks = &networks return r }
go
func (r *Application) SetNetwork(name string, mode PodNetworkMode) *Application { if r.Networks == nil { r.EmptyNetworks() } network := PodNetwork{Name: name, Mode: mode} networks := *r.Networks networks = append(networks, network) r.Networks = &networks return r }
[ "func", "(", "r", "*", "Application", ")", "SetNetwork", "(", "name", "string", ",", "mode", "PodNetworkMode", ")", "*", "Application", "{", "if", "r", ".", "Networks", "==", "nil", "{", "r", ".", "EmptyNetworks", "(", ")", "\n", "}", "\n\n", "network", ":=", "PodNetwork", "{", "Name", ":", "name", ",", "Mode", ":", "mode", "}", "\n", "networks", ":=", "*", "r", ".", "Networks", "\n", "networks", "=", "append", "(", "networks", ",", "network", ")", "\n", "r", ".", "Networks", "=", "&", "networks", "\n", "return", "r", "\n", "}" ]
// SetNetwork sets the networking mode
[ "SetNetwork", "sets", "the", "networking", "mode" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application.go#L975-L985
17,040
gambol99/go-marathon
task.go
HasHealthCheckResults
func (r *Task) HasHealthCheckResults() bool { return r.HealthCheckResults != nil && len(r.HealthCheckResults) > 0 }
go
func (r *Task) HasHealthCheckResults() bool { return r.HealthCheckResults != nil && len(r.HealthCheckResults) > 0 }
[ "func", "(", "r", "*", "Task", ")", "HasHealthCheckResults", "(", ")", "bool", "{", "return", "r", ".", "HealthCheckResults", "!=", "nil", "&&", "len", "(", "r", ".", "HealthCheckResults", ")", ">", "0", "\n", "}" ]
// HasHealthCheckResults checks if the task has any health checks
[ "HasHealthCheckResults", "checks", "if", "the", "task", "has", "any", "health", "checks" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/task.go#L76-L78
17,041
gambol99/go-marathon
port_definition.go
SetPort
func (p *PortDefinition) SetPort(port int) *PortDefinition { if p.Port == nil { p.EmptyPort() } p.Port = &port return p }
go
func (p *PortDefinition) SetPort(port int) *PortDefinition { if p.Port == nil { p.EmptyPort() } p.Port = &port return p }
[ "func", "(", "p", "*", "PortDefinition", ")", "SetPort", "(", "port", "int", ")", "*", "PortDefinition", "{", "if", "p", ".", "Port", "==", "nil", "{", "p", ".", "EmptyPort", "(", ")", "\n", "}", "\n", "p", ".", "Port", "=", "&", "port", "\n", "return", "p", "\n", "}" ]
// SetPort sets the given port for the PortDefinition
[ "SetPort", "sets", "the", "given", "port", "for", "the", "PortDefinition" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/port_definition.go#L30-L36
17,042
gambol99/go-marathon
pod_marshalling.go
UnmarshalJSON
func (p *Pod) UnmarshalJSON(b []byte) error { aux := &struct { *PodAlias Env map[string]interface{} `json:"environment"` Secrets map[string]TmpSecret `json:"secrets"` }{ PodAlias: (*PodAlias)(p), } if err := json.Unmarshal(b, aux); err != nil { return fmt.Errorf("malformed pod definition %v", err) } env := map[string]string{} secrets := map[string]Secret{} for envName, genericEnvValue := range aux.Env { switch envValOrSecret := genericEnvValue.(type) { case string: env[envName] = envValOrSecret case map[string]interface{}: for secret, secretStore := range envValOrSecret { if secStore, ok := secretStore.(string); ok && secret == "secret" { secrets[secStore] = Secret{EnvVar: envName} break } return fmt.Errorf("unexpected secret field %v of value type %T", secret, envValOrSecret[secret]) } default: return fmt.Errorf("unexpected environment variable type %T", envValOrSecret) } } p.Env = env for k, v := range aux.Secrets { tmp := secrets[k] tmp.Source = v.Source secrets[k] = tmp } p.Secrets = secrets return nil }
go
func (p *Pod) UnmarshalJSON(b []byte) error { aux := &struct { *PodAlias Env map[string]interface{} `json:"environment"` Secrets map[string]TmpSecret `json:"secrets"` }{ PodAlias: (*PodAlias)(p), } if err := json.Unmarshal(b, aux); err != nil { return fmt.Errorf("malformed pod definition %v", err) } env := map[string]string{} secrets := map[string]Secret{} for envName, genericEnvValue := range aux.Env { switch envValOrSecret := genericEnvValue.(type) { case string: env[envName] = envValOrSecret case map[string]interface{}: for secret, secretStore := range envValOrSecret { if secStore, ok := secretStore.(string); ok && secret == "secret" { secrets[secStore] = Secret{EnvVar: envName} break } return fmt.Errorf("unexpected secret field %v of value type %T", secret, envValOrSecret[secret]) } default: return fmt.Errorf("unexpected environment variable type %T", envValOrSecret) } } p.Env = env for k, v := range aux.Secrets { tmp := secrets[k] tmp.Source = v.Source secrets[k] = tmp } p.Secrets = secrets return nil }
[ "func", "(", "p", "*", "Pod", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "aux", ":=", "&", "struct", "{", "*", "PodAlias", "\n", "Env", "map", "[", "string", "]", "interface", "{", "}", "`json:\"environment\"`", "\n", "Secrets", "map", "[", "string", "]", "TmpSecret", "`json:\"secrets\"`", "\n", "}", "{", "PodAlias", ":", "(", "*", "PodAlias", ")", "(", "p", ")", ",", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "aux", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "env", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "secrets", ":=", "map", "[", "string", "]", "Secret", "{", "}", "\n\n", "for", "envName", ",", "genericEnvValue", ":=", "range", "aux", ".", "Env", "{", "switch", "envValOrSecret", ":=", "genericEnvValue", ".", "(", "type", ")", "{", "case", "string", ":", "env", "[", "envName", "]", "=", "envValOrSecret", "\n", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "for", "secret", ",", "secretStore", ":=", "range", "envValOrSecret", "{", "if", "secStore", ",", "ok", ":=", "secretStore", ".", "(", "string", ")", ";", "ok", "&&", "secret", "==", "\"", "\"", "{", "secrets", "[", "secStore", "]", "=", "Secret", "{", "EnvVar", ":", "envName", "}", "\n", "break", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "secret", ",", "envValOrSecret", "[", "secret", "]", ")", "\n", "}", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "envValOrSecret", ")", "\n", "}", "\n", "}", "\n", "p", ".", "Env", "=", "env", "\n", "for", "k", ",", "v", ":=", "range", "aux", ".", "Secrets", "{", "tmp", ":=", "secrets", "[", "k", "]", "\n", "tmp", ".", "Source", "=", "v", ".", "Source", "\n", "secrets", "[", "k", "]", "=", "tmp", "\n", "}", "\n", "p", ".", "Secrets", "=", "secrets", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON unmarshals the given Pod JSON as expected except for environment variables and secrets. // Environment variables are stored in the Env field. Secrets, including the environment variable part, // are stored in the Secrets field.
[ "UnmarshalJSON", "unmarshals", "the", "given", "Pod", "JSON", "as", "expected", "except", "for", "environment", "variables", "and", "secrets", ".", "Environment", "variables", "are", "stored", "in", "the", "Env", "field", ".", "Secrets", "including", "the", "environment", "variable", "part", "are", "stored", "in", "the", "Secrets", "field", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_marshalling.go#L30-L68
17,043
gambol99/go-marathon
pod_marshalling.go
MarshalJSON
func (p *Pod) MarshalJSON() ([]byte, error) { env := make(map[string]interface{}) secrets := make(map[string]TmpSecret) if p.Env != nil { for k, v := range p.Env { env[string(k)] = string(v) } } if p.Secrets != nil { for k, v := range p.Secrets { // Only add it to the root level pod environment if it's used // Otherwise it's likely in one of the container environments if v.EnvVar != "" { env[v.EnvVar] = TmpEnvSecret{Secret: k} } secrets[k] = TmpSecret{v.Source} } } aux := &struct { *PodAlias Env map[string]interface{} `json:"environment,omitempty"` Secrets map[string]TmpSecret `json:"secrets,omitempty"` }{PodAlias: (*PodAlias)(p), Env: env, Secrets: secrets} return json.Marshal(aux) }
go
func (p *Pod) MarshalJSON() ([]byte, error) { env := make(map[string]interface{}) secrets := make(map[string]TmpSecret) if p.Env != nil { for k, v := range p.Env { env[string(k)] = string(v) } } if p.Secrets != nil { for k, v := range p.Secrets { // Only add it to the root level pod environment if it's used // Otherwise it's likely in one of the container environments if v.EnvVar != "" { env[v.EnvVar] = TmpEnvSecret{Secret: k} } secrets[k] = TmpSecret{v.Source} } } aux := &struct { *PodAlias Env map[string]interface{} `json:"environment,omitempty"` Secrets map[string]TmpSecret `json:"secrets,omitempty"` }{PodAlias: (*PodAlias)(p), Env: env, Secrets: secrets} return json.Marshal(aux) }
[ "func", "(", "p", "*", "Pod", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "env", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "secrets", ":=", "make", "(", "map", "[", "string", "]", "TmpSecret", ")", "\n\n", "if", "p", ".", "Env", "!=", "nil", "{", "for", "k", ",", "v", ":=", "range", "p", ".", "Env", "{", "env", "[", "string", "(", "k", ")", "]", "=", "string", "(", "v", ")", "\n", "}", "\n", "}", "\n", "if", "p", ".", "Secrets", "!=", "nil", "{", "for", "k", ",", "v", ":=", "range", "p", ".", "Secrets", "{", "// Only add it to the root level pod environment if it's used", "// Otherwise it's likely in one of the container environments", "if", "v", ".", "EnvVar", "!=", "\"", "\"", "{", "env", "[", "v", ".", "EnvVar", "]", "=", "TmpEnvSecret", "{", "Secret", ":", "k", "}", "\n", "}", "\n", "secrets", "[", "k", "]", "=", "TmpSecret", "{", "v", ".", "Source", "}", "\n", "}", "\n", "}", "\n", "aux", ":=", "&", "struct", "{", "*", "PodAlias", "\n", "Env", "map", "[", "string", "]", "interface", "{", "}", "`json:\"environment,omitempty\"`", "\n", "Secrets", "map", "[", "string", "]", "TmpSecret", "`json:\"secrets,omitempty\"`", "\n", "}", "{", "PodAlias", ":", "(", "*", "PodAlias", ")", "(", "p", ")", ",", "Env", ":", "env", ",", "Secrets", ":", "secrets", "}", "\n\n", "return", "json", ".", "Marshal", "(", "aux", ")", "\n", "}" ]
// MarshalJSON marshals the given Pod as expected except for environment variables and secrets, // which are marshaled from specialized structs. The environment variable piece of the secrets and other // normal environment variables are combined and marshaled to the env field. The secrets and the related // source are marshaled into the secrets field.
[ "MarshalJSON", "marshals", "the", "given", "Pod", "as", "expected", "except", "for", "environment", "variables", "and", "secrets", "which", "are", "marshaled", "from", "specialized", "structs", ".", "The", "environment", "variable", "piece", "of", "the", "secrets", "and", "other", "normal", "environment", "variables", "are", "combined", "and", "marshaled", "to", "the", "env", "field", ".", "The", "secrets", "and", "the", "related", "source", "are", "marshaled", "into", "the", "secrets", "field", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_marshalling.go#L74-L100
17,044
gambol99/go-marathon
config.go
NewDefaultConfig
func NewDefaultConfig() Config { return Config{ URL: "http://127.0.0.1:8080", EventsTransport: EventsTransportCallback, EventsPort: 10001, EventsInterface: "eth0", LogOutput: ioutil.Discard, PollingWaitTime: defaultPollingWaitTime, } }
go
func NewDefaultConfig() Config { return Config{ URL: "http://127.0.0.1:8080", EventsTransport: EventsTransportCallback, EventsPort: 10001, EventsInterface: "eth0", LogOutput: ioutil.Discard, PollingWaitTime: defaultPollingWaitTime, } }
[ "func", "NewDefaultConfig", "(", ")", "Config", "{", "return", "Config", "{", "URL", ":", "\"", "\"", ",", "EventsTransport", ":", "EventsTransportCallback", ",", "EventsPort", ":", "10001", ",", "EventsInterface", ":", "\"", "\"", ",", "LogOutput", ":", "ioutil", ".", "Discard", ",", "PollingWaitTime", ":", "defaultPollingWaitTime", ",", "}", "\n", "}" ]
// NewDefaultConfig create a default client config
[ "NewDefaultConfig", "create", "a", "default", "client", "config" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/config.go#L62-L71
17,045
gambol99/go-marathon
error.go
newInvalidEndpointError
func newInvalidEndpointError(message string, args ...interface{}) error { return &InvalidEndpointError{message: fmt.Sprintf(message, args...)} }
go
func newInvalidEndpointError(message string, args ...interface{}) error { return &InvalidEndpointError{message: fmt.Sprintf(message, args...)} }
[ "func", "newInvalidEndpointError", "(", "message", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "return", "&", "InvalidEndpointError", "{", "message", ":", "fmt", ".", "Sprintf", "(", "message", ",", "args", "...", ")", "}", "\n", "}" ]
// newInvalidEndpointError creates a new error
[ "newInvalidEndpointError", "creates", "a", "new", "error" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/error.go#L60-L62
17,046
gambol99/go-marathon
error.go
NewAPIError
func NewAPIError(code int, content []byte) error { var errDef errorDefinition switch { case code == http.StatusBadRequest: errDef = &badRequestDef{} case code == http.StatusUnauthorized: errDef = &simpleErrDef{code: ErrCodeUnauthorized} case code == http.StatusForbidden: errDef = &simpleErrDef{code: ErrCodeForbidden} case code == http.StatusNotFound: errDef = &simpleErrDef{code: ErrCodeNotFound} case code == http.StatusMethodNotAllowed: errDef = &simpleErrDef{code: ErrCodeMethodNotAllowed} case code == http.StatusConflict: errDef = &conflictDef{} case code == 422: errDef = &unprocessableEntityDef{} case code >= http.StatusInternalServerError: errDef = &simpleErrDef{code: ErrCodeServer} default: errDef = &simpleErrDef{code: ErrCodeUnknown} } return parseContent(errDef, content) }
go
func NewAPIError(code int, content []byte) error { var errDef errorDefinition switch { case code == http.StatusBadRequest: errDef = &badRequestDef{} case code == http.StatusUnauthorized: errDef = &simpleErrDef{code: ErrCodeUnauthorized} case code == http.StatusForbidden: errDef = &simpleErrDef{code: ErrCodeForbidden} case code == http.StatusNotFound: errDef = &simpleErrDef{code: ErrCodeNotFound} case code == http.StatusMethodNotAllowed: errDef = &simpleErrDef{code: ErrCodeMethodNotAllowed} case code == http.StatusConflict: errDef = &conflictDef{} case code == 422: errDef = &unprocessableEntityDef{} case code >= http.StatusInternalServerError: errDef = &simpleErrDef{code: ErrCodeServer} default: errDef = &simpleErrDef{code: ErrCodeUnknown} } return parseContent(errDef, content) }
[ "func", "NewAPIError", "(", "code", "int", ",", "content", "[", "]", "byte", ")", "error", "{", "var", "errDef", "errorDefinition", "\n", "switch", "{", "case", "code", "==", "http", ".", "StatusBadRequest", ":", "errDef", "=", "&", "badRequestDef", "{", "}", "\n", "case", "code", "==", "http", ".", "StatusUnauthorized", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeUnauthorized", "}", "\n", "case", "code", "==", "http", ".", "StatusForbidden", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeForbidden", "}", "\n", "case", "code", "==", "http", ".", "StatusNotFound", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeNotFound", "}", "\n", "case", "code", "==", "http", ".", "StatusMethodNotAllowed", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeMethodNotAllowed", "}", "\n", "case", "code", "==", "http", ".", "StatusConflict", ":", "errDef", "=", "&", "conflictDef", "{", "}", "\n", "case", "code", "==", "422", ":", "errDef", "=", "&", "unprocessableEntityDef", "{", "}", "\n", "case", "code", ">=", "http", ".", "StatusInternalServerError", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeServer", "}", "\n", "default", ":", "errDef", "=", "&", "simpleErrDef", "{", "code", ":", "ErrCodeUnknown", "}", "\n", "}", "\n\n", "return", "parseContent", "(", "errDef", ",", "content", ")", "\n", "}" ]
// NewAPIError creates a new APIError instance from the given response code and content.
[ "NewAPIError", "creates", "a", "new", "APIError", "instance", "from", "the", "given", "response", "code", "and", "content", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/error.go#L76-L100
17,047
gambol99/go-marathon
pod_container.go
NewPodContainer
func NewPodContainer() *PodContainer { return &PodContainer{ Endpoints: []*PodEndpoint{}, Env: map[string]string{}, VolumeMounts: []*PodVolumeMount{}, Artifacts: []*PodArtifact{}, Labels: map[string]string{}, Resources: NewResources(), } }
go
func NewPodContainer() *PodContainer { return &PodContainer{ Endpoints: []*PodEndpoint{}, Env: map[string]string{}, VolumeMounts: []*PodVolumeMount{}, Artifacts: []*PodArtifact{}, Labels: map[string]string{}, Resources: NewResources(), } }
[ "func", "NewPodContainer", "(", ")", "*", "PodContainer", "{", "return", "&", "PodContainer", "{", "Endpoints", ":", "[", "]", "*", "PodEndpoint", "{", "}", ",", "Env", ":", "map", "[", "string", "]", "string", "{", "}", ",", "VolumeMounts", ":", "[", "]", "*", "PodVolumeMount", "{", "}", ",", "Artifacts", ":", "[", "]", "*", "PodArtifact", "{", "}", ",", "Labels", ":", "map", "[", "string", "]", "string", "{", "}", ",", "Resources", ":", "NewResources", "(", ")", ",", "}", "\n", "}" ]
// NewPodContainer creates an empty PodContainer
[ "NewPodContainer", "creates", "an", "empty", "PodContainer" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L61-L70
17,048
gambol99/go-marathon
pod_container.go
SetName
func (p *PodContainer) SetName(name string) *PodContainer { p.Name = name return p }
go
func (p *PodContainer) SetName(name string) *PodContainer { p.Name = name return p }
[ "func", "(", "p", "*", "PodContainer", ")", "SetName", "(", "name", "string", ")", "*", "PodContainer", "{", "p", ".", "Name", "=", "name", "\n", "return", "p", "\n", "}" ]
// SetName sets the name of a pod container
[ "SetName", "sets", "the", "name", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L73-L76
17,049
gambol99/go-marathon
pod_container.go
SetCommand
func (p *PodContainer) SetCommand(name string) *PodContainer { p.Exec = &PodExec{ Command: PodCommand{ Shell: name, }, } return p }
go
func (p *PodContainer) SetCommand(name string) *PodContainer { p.Exec = &PodExec{ Command: PodCommand{ Shell: name, }, } return p }
[ "func", "(", "p", "*", "PodContainer", ")", "SetCommand", "(", "name", "string", ")", "*", "PodContainer", "{", "p", ".", "Exec", "=", "&", "PodExec", "{", "Command", ":", "PodCommand", "{", "Shell", ":", "name", ",", "}", ",", "}", "\n", "return", "p", "\n", "}" ]
// SetCommand sets the shell command of a pod container
[ "SetCommand", "sets", "the", "shell", "command", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L79-L86
17,050
gambol99/go-marathon
pod_container.go
CPUs
func (p *PodContainer) CPUs(cpu float64) *PodContainer { p.Resources.Cpus = cpu return p }
go
func (p *PodContainer) CPUs(cpu float64) *PodContainer { p.Resources.Cpus = cpu return p }
[ "func", "(", "p", "*", "PodContainer", ")", "CPUs", "(", "cpu", "float64", ")", "*", "PodContainer", "{", "p", ".", "Resources", ".", "Cpus", "=", "cpu", "\n", "return", "p", "\n", "}" ]
// CPUs sets the CPUs of a pod container
[ "CPUs", "sets", "the", "CPUs", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L89-L92
17,051
gambol99/go-marathon
pod_container.go
Memory
func (p *PodContainer) Memory(memory float64) *PodContainer { p.Resources.Mem = memory return p }
go
func (p *PodContainer) Memory(memory float64) *PodContainer { p.Resources.Mem = memory return p }
[ "func", "(", "p", "*", "PodContainer", ")", "Memory", "(", "memory", "float64", ")", "*", "PodContainer", "{", "p", ".", "Resources", ".", "Mem", "=", "memory", "\n", "return", "p", "\n", "}" ]
// Memory sets the memory of a pod container
[ "Memory", "sets", "the", "memory", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L95-L98
17,052
gambol99/go-marathon
pod_container.go
Storage
func (p *PodContainer) Storage(disk float64) *PodContainer { p.Resources.Disk = disk return p }
go
func (p *PodContainer) Storage(disk float64) *PodContainer { p.Resources.Disk = disk return p }
[ "func", "(", "p", "*", "PodContainer", ")", "Storage", "(", "disk", "float64", ")", "*", "PodContainer", "{", "p", ".", "Resources", ".", "Disk", "=", "disk", "\n", "return", "p", "\n", "}" ]
// Storage sets the storage capacity of a pod container
[ "Storage", "sets", "the", "storage", "capacity", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L101-L104
17,053
gambol99/go-marathon
pod_container.go
GPUs
func (p *PodContainer) GPUs(gpu int32) *PodContainer { p.Resources.Gpus = gpu return p }
go
func (p *PodContainer) GPUs(gpu int32) *PodContainer { p.Resources.Gpus = gpu return p }
[ "func", "(", "p", "*", "PodContainer", ")", "GPUs", "(", "gpu", "int32", ")", "*", "PodContainer", "{", "p", ".", "Resources", ".", "Gpus", "=", "gpu", "\n", "return", "p", "\n", "}" ]
// GPUs sets the GPU requirements of a pod container
[ "GPUs", "sets", "the", "GPU", "requirements", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L107-L110
17,054
gambol99/go-marathon
pod_container.go
AddEndpoint
func (p *PodContainer) AddEndpoint(endpoint *PodEndpoint) *PodContainer { p.Endpoints = append(p.Endpoints, endpoint) return p }
go
func (p *PodContainer) AddEndpoint(endpoint *PodEndpoint) *PodContainer { p.Endpoints = append(p.Endpoints, endpoint) return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddEndpoint", "(", "endpoint", "*", "PodEndpoint", ")", "*", "PodContainer", "{", "p", ".", "Endpoints", "=", "append", "(", "p", ".", "Endpoints", ",", "endpoint", ")", "\n", "return", "p", "\n", "}" ]
// AddEndpoint appends an endpoint for a pod container
[ "AddEndpoint", "appends", "an", "endpoint", "for", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L113-L116
17,055
gambol99/go-marathon
pod_container.go
SetImage
func (p *PodContainer) SetImage(image *PodContainerImage) *PodContainer { p.Image = image return p }
go
func (p *PodContainer) SetImage(image *PodContainerImage) *PodContainer { p.Image = image return p }
[ "func", "(", "p", "*", "PodContainer", ")", "SetImage", "(", "image", "*", "PodContainerImage", ")", "*", "PodContainer", "{", "p", ".", "Image", "=", "image", "\n", "return", "p", "\n", "}" ]
// SetImage sets the image of a pod container
[ "SetImage", "sets", "the", "image", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L119-L122
17,056
gambol99/go-marathon
pod_container.go
EmptyEnvs
func (p *PodContainer) EmptyEnvs() *PodContainer { p.Env = make(map[string]string) return p }
go
func (p *PodContainer) EmptyEnvs() *PodContainer { p.Env = make(map[string]string) return p }
[ "func", "(", "p", "*", "PodContainer", ")", "EmptyEnvs", "(", ")", "*", "PodContainer", "{", "p", ".", "Env", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "return", "p", "\n", "}" ]
// EmptyEnvs initialized env to empty
[ "EmptyEnvs", "initialized", "env", "to", "empty" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L125-L128
17,057
gambol99/go-marathon
pod_container.go
AddEnv
func (p *PodContainer) AddEnv(name, value string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } p.Env[name] = value return p }
go
func (p *PodContainer) AddEnv(name, value string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } p.Env[name] = value return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddEnv", "(", "name", ",", "value", "string", ")", "*", "PodContainer", "{", "if", "p", ".", "Env", "==", "nil", "{", "p", "=", "p", ".", "EmptyEnvs", "(", ")", "\n", "}", "\n", "p", ".", "Env", "[", "name", "]", "=", "value", "\n", "return", "p", "\n", "}" ]
// AddEnv adds an environment variable for a pod container
[ "AddEnv", "adds", "an", "environment", "variable", "for", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L131-L137
17,058
gambol99/go-marathon
pod_container.go
ExtendEnv
func (p *PodContainer) ExtendEnv(env map[string]string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } for k, v := range env { p.AddEnv(k, v) } return p }
go
func (p *PodContainer) ExtendEnv(env map[string]string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } for k, v := range env { p.AddEnv(k, v) } return p }
[ "func", "(", "p", "*", "PodContainer", ")", "ExtendEnv", "(", "env", "map", "[", "string", "]", "string", ")", "*", "PodContainer", "{", "if", "p", ".", "Env", "==", "nil", "{", "p", "=", "p", ".", "EmptyEnvs", "(", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "env", "{", "p", ".", "AddEnv", "(", "k", ",", "v", ")", "\n", "}", "\n", "return", "p", "\n", "}" ]
// ExtendEnv extends the environment for a pod container
[ "ExtendEnv", "extends", "the", "environment", "for", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L140-L148
17,059
gambol99/go-marathon
pod_container.go
AddSecret
func (p *PodContainer) AddSecret(name, secretName string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } p.Env[name] = secretName return p }
go
func (p *PodContainer) AddSecret(name, secretName string) *PodContainer { if p.Env == nil { p = p.EmptyEnvs() } p.Env[name] = secretName return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddSecret", "(", "name", ",", "secretName", "string", ")", "*", "PodContainer", "{", "if", "p", ".", "Env", "==", "nil", "{", "p", "=", "p", ".", "EmptyEnvs", "(", ")", "\n", "}", "\n", "p", ".", "Env", "[", "name", "]", "=", "secretName", "\n", "return", "p", "\n", "}" ]
// AddSecret adds a secret to the environment for a pod container
[ "AddSecret", "adds", "a", "secret", "to", "the", "environment", "for", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L151-L157
17,060
gambol99/go-marathon
pod_container.go
SetHealthCheck
func (p *PodContainer) SetHealthCheck(healthcheck *PodHealthCheck) *PodContainer { p.HealthCheck = healthcheck return p }
go
func (p *PodContainer) SetHealthCheck(healthcheck *PodHealthCheck) *PodContainer { p.HealthCheck = healthcheck return p }
[ "func", "(", "p", "*", "PodContainer", ")", "SetHealthCheck", "(", "healthcheck", "*", "PodHealthCheck", ")", "*", "PodContainer", "{", "p", ".", "HealthCheck", "=", "healthcheck", "\n", "return", "p", "\n", "}" ]
// SetHealthCheck sets the health check of a pod container
[ "SetHealthCheck", "sets", "the", "health", "check", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L166-L169
17,061
gambol99/go-marathon
pod_container.go
AddVolumeMount
func (p *PodContainer) AddVolumeMount(mount *PodVolumeMount) *PodContainer { p.VolumeMounts = append(p.VolumeMounts, mount) return p }
go
func (p *PodContainer) AddVolumeMount(mount *PodVolumeMount) *PodContainer { p.VolumeMounts = append(p.VolumeMounts, mount) return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddVolumeMount", "(", "mount", "*", "PodVolumeMount", ")", "*", "PodContainer", "{", "p", ".", "VolumeMounts", "=", "append", "(", "p", ".", "VolumeMounts", ",", "mount", ")", "\n", "return", "p", "\n", "}" ]
// AddVolumeMount appends a volume mount to a pod container
[ "AddVolumeMount", "appends", "a", "volume", "mount", "to", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L172-L175
17,062
gambol99/go-marathon
pod_container.go
AddArtifact
func (p *PodContainer) AddArtifact(artifact *PodArtifact) *PodContainer { p.Artifacts = append(p.Artifacts, artifact) return p }
go
func (p *PodContainer) AddArtifact(artifact *PodArtifact) *PodContainer { p.Artifacts = append(p.Artifacts, artifact) return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddArtifact", "(", "artifact", "*", "PodArtifact", ")", "*", "PodContainer", "{", "p", ".", "Artifacts", "=", "append", "(", "p", ".", "Artifacts", ",", "artifact", ")", "\n", "return", "p", "\n", "}" ]
// AddArtifact appends an artifact to a pod container
[ "AddArtifact", "appends", "an", "artifact", "to", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L178-L181
17,063
gambol99/go-marathon
pod_container.go
AddLabel
func (p *PodContainer) AddLabel(key, value string) *PodContainer { p.Labels[key] = value return p }
go
func (p *PodContainer) AddLabel(key, value string) *PodContainer { p.Labels[key] = value return p }
[ "func", "(", "p", "*", "PodContainer", ")", "AddLabel", "(", "key", ",", "value", "string", ")", "*", "PodContainer", "{", "p", ".", "Labels", "[", "key", "]", "=", "value", "\n", "return", "p", "\n", "}" ]
// AddLabel adds a label to a pod container
[ "AddLabel", "adds", "a", "label", "to", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L184-L187
17,064
gambol99/go-marathon
pod_container.go
SetLifecycle
func (p *PodContainer) SetLifecycle(lifecycle PodLifecycle) *PodContainer { p.Lifecycle = lifecycle return p }
go
func (p *PodContainer) SetLifecycle(lifecycle PodLifecycle) *PodContainer { p.Lifecycle = lifecycle return p }
[ "func", "(", "p", "*", "PodContainer", ")", "SetLifecycle", "(", "lifecycle", "PodLifecycle", ")", "*", "PodContainer", "{", "p", ".", "Lifecycle", "=", "lifecycle", "\n", "return", "p", "\n", "}" ]
// SetLifecycle sets the lifecycle of a pod container
[ "SetLifecycle", "sets", "the", "lifecycle", "of", "a", "pod", "container" ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/pod_container.go#L190-L193
17,065
gambol99/go-marathon
application_marshalling.go
MarshalJSON
func (app *Application) MarshalJSON() ([]byte, error) { env := make(map[string]interface{}) secrets := make(map[string]TmpSecret) if app.Env != nil { for k, v := range *app.Env { env[string(k)] = string(v) } } if app.Secrets != nil { for k, v := range *app.Secrets { env[v.EnvVar] = TmpEnvSecret{Secret: k} secrets[k] = TmpSecret{v.Source} } } aux := &struct { *Alias Env map[string]interface{} `json:"env,omitempty"` Secrets map[string]TmpSecret `json:"secrets,omitempty"` }{Alias: (*Alias)(app), Env: env, Secrets: secrets} return json.Marshal(aux) }
go
func (app *Application) MarshalJSON() ([]byte, error) { env := make(map[string]interface{}) secrets := make(map[string]TmpSecret) if app.Env != nil { for k, v := range *app.Env { env[string(k)] = string(v) } } if app.Secrets != nil { for k, v := range *app.Secrets { env[v.EnvVar] = TmpEnvSecret{Secret: k} secrets[k] = TmpSecret{v.Source} } } aux := &struct { *Alias Env map[string]interface{} `json:"env,omitempty"` Secrets map[string]TmpSecret `json:"secrets,omitempty"` }{Alias: (*Alias)(app), Env: env, Secrets: secrets} return json.Marshal(aux) }
[ "func", "(", "app", "*", "Application", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "env", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "secrets", ":=", "make", "(", "map", "[", "string", "]", "TmpSecret", ")", "\n\n", "if", "app", ".", "Env", "!=", "nil", "{", "for", "k", ",", "v", ":=", "range", "*", "app", ".", "Env", "{", "env", "[", "string", "(", "k", ")", "]", "=", "string", "(", "v", ")", "\n", "}", "\n", "}", "\n", "if", "app", ".", "Secrets", "!=", "nil", "{", "for", "k", ",", "v", ":=", "range", "*", "app", ".", "Secrets", "{", "env", "[", "v", ".", "EnvVar", "]", "=", "TmpEnvSecret", "{", "Secret", ":", "k", "}", "\n", "secrets", "[", "k", "]", "=", "TmpSecret", "{", "v", ".", "Source", "}", "\n", "}", "\n", "}", "\n", "aux", ":=", "&", "struct", "{", "*", "Alias", "\n", "Env", "map", "[", "string", "]", "interface", "{", "}", "`json:\"env,omitempty\"`", "\n", "Secrets", "map", "[", "string", "]", "TmpSecret", "`json:\"secrets,omitempty\"`", "\n", "}", "{", "Alias", ":", "(", "*", "Alias", ")", "(", "app", ")", ",", "Env", ":", "env", ",", "Secrets", ":", "secrets", "}", "\n\n", "return", "json", ".", "Marshal", "(", "aux", ")", "\n", "}" ]
// MarshalJSON marshals the given Application as expected except for environment variables and secrets, // which are marshaled from specialized structs. The environment variable piece of the secrets and other // normal environment variables are combined and marshaled to the env field. The secrets and the related // source are marshaled into the secrets field.
[ "MarshalJSON", "marshals", "the", "given", "Application", "as", "expected", "except", "for", "environment", "variables", "and", "secrets", "which", "are", "marshaled", "from", "specialized", "structs", ".", "The", "environment", "variable", "piece", "of", "the", "secrets", "and", "other", "normal", "environment", "variables", "are", "combined", "and", "marshaled", "to", "the", "env", "field", ".", "The", "secrets", "and", "the", "related", "source", "are", "marshaled", "into", "the", "secrets", "field", "." ]
80365667fd5354cd063520a8ca8f53dfad6e6c81
https://github.com/gambol99/go-marathon/blob/80365667fd5354cd063520a8ca8f53dfad6e6c81/application_marshalling.go#L84-L106
17,066
intel-go/fastjson
scanner.go
pushRecord
func (s *scanner) pushRecord(state, pos int) { s.stateRecord = append(s.stateRecord, Record{state:state, pos:pos}) //state are at even positions, pos are at odd positions in stateRecord array }
go
func (s *scanner) pushRecord(state, pos int) { s.stateRecord = append(s.stateRecord, Record{state:state, pos:pos}) //state are at even positions, pos are at odd positions in stateRecord array }
[ "func", "(", "s", "*", "scanner", ")", "pushRecord", "(", "state", ",", "pos", "int", ")", "{", "s", ".", "stateRecord", "=", "append", "(", "s", ".", "stateRecord", ",", "Record", "{", "state", ":", "state", ",", "pos", ":", "pos", "}", ")", "//state are at even positions, pos are at odd positions in stateRecord array", "\n", "}" ]
//pushes Record into array
[ "pushes", "Record", "into", "array" ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/scanner.go#L220-L222
17,067
intel-go/fastjson
scanner.go
peekPos
func (s *scanner) peekPos() int { if s.readPos >= len(s.stateRecord){ return s.cacheRecord.pos// peek can be called when the array is over , only if unmarshal error occured, so return last read position } if !s.cached { s.cached = true s.cacheRecord = s.stateRecord[s.readPos] } return s.cacheRecord.pos }
go
func (s *scanner) peekPos() int { if s.readPos >= len(s.stateRecord){ return s.cacheRecord.pos// peek can be called when the array is over , only if unmarshal error occured, so return last read position } if !s.cached { s.cached = true s.cacheRecord = s.stateRecord[s.readPos] } return s.cacheRecord.pos }
[ "func", "(", "s", "*", "scanner", ")", "peekPos", "(", ")", "int", "{", "if", "s", ".", "readPos", ">=", "len", "(", "s", ".", "stateRecord", ")", "{", "return", "s", ".", "cacheRecord", ".", "pos", "// peek can be called when the array is over , only if unmarshal error occured, so return last read position ", "\n", "}", "\n", "if", "!", "s", ".", "cached", "{", "s", ".", "cached", "=", "true", "\n", "s", ".", "cacheRecord", "=", "s", ".", "stateRecord", "[", "s", ".", "readPos", "]", "\n", "}", "\n", "return", "s", ".", "cacheRecord", ".", "pos", "\n", "}" ]
//peeks current state for filling object. Doesn't change position. Returns state, pos
[ "peeks", "current", "state", "for", "filling", "object", ".", "Doesn", "t", "change", "position", ".", "Returns", "state", "pos" ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/scanner.go#L225-L234
17,068
intel-go/fastjson
scanner.go
takeState
func (s *scanner) takeState() int { if s.cached { s.cached = false }else{ s.peekState() } s.readPos += 1 return s.cacheRecord.state }
go
func (s *scanner) takeState() int { if s.cached { s.cached = false }else{ s.peekState() } s.readPos += 1 return s.cacheRecord.state }
[ "func", "(", "s", "*", "scanner", ")", "takeState", "(", ")", "int", "{", "if", "s", ".", "cached", "{", "s", ".", "cached", "=", "false", "\n", "}", "else", "{", "s", ".", "peekState", "(", ")", "\n", "}", "\n", "s", ".", "readPos", "+=", "1", "\n", "return", "s", ".", "cacheRecord", ".", "state", "\n", "}" ]
//takes current state and increments reading position.
[ "takes", "current", "state", "and", "increments", "reading", "position", "." ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/scanner.go#L248-L256
17,069
intel-go/fastjson
scanner.go
isNeededState
func (s *scanner) isNeededState(state int) bool { if s.endLiteral { return true } if state > scanEndArray || state < scanBeginLiteral { return false } return true }
go
func (s *scanner) isNeededState(state int) bool { if s.endLiteral { return true } if state > scanEndArray || state < scanBeginLiteral { return false } return true }
[ "func", "(", "s", "*", "scanner", ")", "isNeededState", "(", "state", "int", ")", "bool", "{", "if", "s", ".", "endLiteral", "{", "return", "true", "\n", "}", "\n", "if", "state", ">", "scanEndArray", "||", "state", "<", "scanBeginLiteral", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
//checks if we need this state to be recorded
[ "checks", "if", "we", "need", "this", "state", "to", "be", "recorded" ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/scanner.go#L274-L282
17,070
intel-go/fastjson
scanner.go
stateTru
func stateTru(s *scanner, c byte) int { if c == 'e' { s.step = stateEndValue s.endLiteral = true return scanContinue } return s.error(c, "in literal true (expecting 'e')") }
go
func stateTru(s *scanner, c byte) int { if c == 'e' { s.step = stateEndValue s.endLiteral = true return scanContinue } return s.error(c, "in literal true (expecting 'e')") }
[ "func", "stateTru", "(", "s", "*", "scanner", ",", "c", "byte", ")", "int", "{", "if", "c", "==", "'e'", "{", "s", ".", "step", "=", "stateEndValue", "\n", "s", ".", "endLiteral", "=", "true", "\n", "return", "scanContinue", "\n", "}", "\n", "return", "s", ".", "error", "(", "c", ",", "\"", "\"", ")", "\n", "}" ]
// stateTru is the state after reading `tru`.
[ "stateTru", "is", "the", "state", "after", "reading", "tru", "." ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/scanner.go#L629-L636
17,071
intel-go/fastjson
decode.go
next
func (d *decodeState) next() []byte { startop, start := d.peekRecord() var endop int switch startop { case scanBeginArray: endop = scanEndArray case scanBeginObject: endop = scanEndObject case scanBeginLiteral: endop = scanEndLiteral default: panic(errPhase) } count := 1 //counts number of open and not closed brackets. d.skipRecord() end := 0 //end of value op := startop for count != 0 { //we need here cycle because of nested objects and slices op, end = d.takeRecord() if op == startop { count++ } if op == endop { count-- } } return d.data[start : end+1] }
go
func (d *decodeState) next() []byte { startop, start := d.peekRecord() var endop int switch startop { case scanBeginArray: endop = scanEndArray case scanBeginObject: endop = scanEndObject case scanBeginLiteral: endop = scanEndLiteral default: panic(errPhase) } count := 1 //counts number of open and not closed brackets. d.skipRecord() end := 0 //end of value op := startop for count != 0 { //we need here cycle because of nested objects and slices op, end = d.takeRecord() if op == startop { count++ } if op == endop { count-- } } return d.data[start : end+1] }
[ "func", "(", "d", "*", "decodeState", ")", "next", "(", ")", "[", "]", "byte", "{", "startop", ",", "start", ":=", "d", ".", "peekRecord", "(", ")", "\n\n", "var", "endop", "int", "\n\n", "switch", "startop", "{", "case", "scanBeginArray", ":", "endop", "=", "scanEndArray", "\n", "case", "scanBeginObject", ":", "endop", "=", "scanEndObject", "\n", "case", "scanBeginLiteral", ":", "endop", "=", "scanEndLiteral", "\n", "default", ":", "panic", "(", "errPhase", ")", "\n", "}", "\n\n", "count", ":=", "1", "//counts number of open and not closed brackets.", "\n", "d", ".", "skipRecord", "(", ")", "\n", "end", ":=", "0", "//end of value", "\n", "op", ":=", "startop", "\n", "for", "count", "!=", "0", "{", "//we need here cycle because of nested objects and slices", "op", ",", "end", "=", "d", ".", "takeRecord", "(", ")", "\n\n", "if", "op", "==", "startop", "{", "count", "++", "\n", "}", "\n\n", "if", "op", "==", "endop", "{", "count", "--", "\n", "}", "\n\n", "}", "\n", "return", "d", ".", "data", "[", "start", ":", "end", "+", "1", "]", "\n", "}" ]
// next cuts off and returns the next full JSON value // The next value is known to be an object or array or a literal
[ "next", "cuts", "off", "and", "returns", "the", "next", "full", "JSON", "value", "The", "next", "value", "is", "known", "to", "be", "an", "object", "or", "array", "or", "a", "literal" ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/decode.go#L283-L316
17,072
intel-go/fastjson
decode.go
takeRecord
func (d *decodeState) takeRecord() (int, int) { return d.scan.peekState(), d.scan.takePos() }
go
func (d *decodeState) takeRecord() (int, int) { return d.scan.peekState(), d.scan.takePos() }
[ "func", "(", "d", "*", "decodeState", ")", "takeRecord", "(", ")", "(", "int", ",", "int", ")", "{", "return", "d", ".", "scan", ".", "peekState", "(", ")", ",", "d", ".", "scan", ".", "takePos", "(", ")", "\n", "}" ]
//wrappers scanner funcs
[ "wrappers", "scanner", "funcs" ]
f846ae58a1ab4a99d9480ce565601aebd84e333a
https://github.com/intel-go/fastjson/blob/f846ae58a1ab4a99d9480ce565601aebd84e333a/decode.go#L319-L321
17,073
mailgun/holster
misc.go
GetEnv
func GetEnv(envName, defaultValue string) string { value := os.Getenv(envName) if value == "" { return defaultValue } return value }
go
func GetEnv(envName, defaultValue string) string { value := os.Getenv(envName) if value == "" { return defaultValue } return value }
[ "func", "GetEnv", "(", "envName", ",", "defaultValue", "string", ")", "string", "{", "value", ":=", "os", ".", "Getenv", "(", "envName", ")", "\n", "if", "value", "==", "\"", "\"", "{", "return", "defaultValue", "\n", "}", "\n", "return", "value", "\n", "}" ]
// Get the environment variable or return the default value if unset
[ "Get", "the", "environment", "variable", "or", "return", "the", "default", "value", "if", "unset" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/misc.go#L67-L73
17,074
mailgun/holster
expire_cache.go
NewExpireCache
func NewExpireCache(ttl time.Duration) *ExpireCache { return &ExpireCache{ cache: make(map[interface{}]*expireRecord), ttl: ttl, } }
go
func NewExpireCache(ttl time.Duration) *ExpireCache { return &ExpireCache{ cache: make(map[interface{}]*expireRecord), ttl: ttl, } }
[ "func", "NewExpireCache", "(", "ttl", "time", ".", "Duration", ")", "*", "ExpireCache", "{", "return", "&", "ExpireCache", "{", "cache", ":", "make", "(", "map", "[", "interface", "{", "}", "]", "*", "expireRecord", ")", ",", "ttl", ":", "ttl", ",", "}", "\n", "}" ]
// New creates a new ExpireCache.
[ "New", "creates", "a", "new", "ExpireCache", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L65-L70
17,075
mailgun/holster
expire_cache.go
Get
func (c *ExpireCache) Get(key interface{}) (interface{}, bool) { c.mutex.Lock() defer c.mutex.Unlock() record, ok := c.cache[key] if !ok { c.stats.Miss++ return nil, ok } // Since this was recently accessed, keep it in // the cache by resetting the expire time record.ExpireAt = time.Now().UTC().Add(c.ttl) c.stats.Hit++ return record.Value, ok }
go
func (c *ExpireCache) Get(key interface{}) (interface{}, bool) { c.mutex.Lock() defer c.mutex.Unlock() record, ok := c.cache[key] if !ok { c.stats.Miss++ return nil, ok } // Since this was recently accessed, keep it in // the cache by resetting the expire time record.ExpireAt = time.Now().UTC().Add(c.ttl) c.stats.Hit++ return record.Value, ok }
[ "func", "(", "c", "*", "ExpireCache", ")", "Get", "(", "key", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "record", ",", "ok", ":=", "c", ".", "cache", "[", "key", "]", "\n", "if", "!", "ok", "{", "c", ".", "stats", ".", "Miss", "++", "\n", "return", "nil", ",", "ok", "\n", "}", "\n\n", "// Since this was recently accessed, keep it in", "// the cache by resetting the expire time", "record", ".", "ExpireAt", "=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Add", "(", "c", ".", "ttl", ")", "\n\n", "c", ".", "stats", ".", "Hit", "++", "\n", "return", "record", ".", "Value", ",", "ok", "\n", "}" ]
// Retrieves a key's value from the cache
[ "Retrieves", "a", "key", "s", "value", "from", "the", "cache" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L73-L89
17,076
mailgun/holster
expire_cache.go
Add
func (c *ExpireCache) Add(key interface{}, value interface{}) { c.mutex.Lock() defer c.mutex.Unlock() record := expireRecord{ Value: value, ExpireAt: time.Now().UTC().Add(c.ttl), } // Add the record to the cache c.cache[key] = &record }
go
func (c *ExpireCache) Add(key interface{}, value interface{}) { c.mutex.Lock() defer c.mutex.Unlock() record := expireRecord{ Value: value, ExpireAt: time.Now().UTC().Add(c.ttl), } // Add the record to the cache c.cache[key] = &record }
[ "func", "(", "c", "*", "ExpireCache", ")", "Add", "(", "key", "interface", "{", "}", ",", "value", "interface", "{", "}", ")", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "record", ":=", "expireRecord", "{", "Value", ":", "value", ",", "ExpireAt", ":", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Add", "(", "c", ".", "ttl", ")", ",", "}", "\n", "// Add the record to the cache", "c", ".", "cache", "[", "key", "]", "=", "&", "record", "\n", "}" ]
// Put the key, value and TTL in the cache
[ "Put", "the", "key", "value", "and", "TTL", "in", "the", "cache" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L92-L102
17,077
mailgun/holster
expire_cache.go
Update
func (c *ExpireCache) Update(key interface{}, value interface{}) error { c.mutex.Lock() defer c.mutex.Unlock() record, ok := c.cache[key] if !ok { return errors.Errorf("ExpoireCache() - No record found for '%+v'", key) } record.Value = value return nil }
go
func (c *ExpireCache) Update(key interface{}, value interface{}) error { c.mutex.Lock() defer c.mutex.Unlock() record, ok := c.cache[key] if !ok { return errors.Errorf("ExpoireCache() - No record found for '%+v'", key) } record.Value = value return nil }
[ "func", "(", "c", "*", "ExpireCache", ")", "Update", "(", "key", "interface", "{", "}", ",", "value", "interface", "{", "}", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "record", ",", "ok", ":=", "c", ".", "cache", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "record", ".", "Value", "=", "value", "\n", "return", "nil", "\n", "}" ]
// Update the value in the cache without updating the TTL
[ "Update", "the", "value", "in", "the", "cache", "without", "updating", "the", "TTL" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L105-L115
17,078
mailgun/holster
expire_cache.go
Peek
func (c *ExpireCache) Peek(key interface{}) (value interface{}, ok bool) { defer c.mutex.Unlock() c.mutex.Lock() if record, hit := c.cache[key]; hit { return record.Value, true } return nil, false }
go
func (c *ExpireCache) Peek(key interface{}) (value interface{}, ok bool) { defer c.mutex.Unlock() c.mutex.Lock() if record, hit := c.cache[key]; hit { return record.Value, true } return nil, false }
[ "func", "(", "c", "*", "ExpireCache", ")", "Peek", "(", "key", "interface", "{", "}", ")", "(", "value", "interface", "{", "}", ",", "ok", "bool", ")", "{", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "c", ".", "mutex", ".", "Lock", "(", ")", "\n\n", "if", "record", ",", "hit", ":=", "c", ".", "cache", "[", "key", "]", ";", "hit", "{", "return", "record", ".", "Value", ",", "true", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// Get the value without updating the expiration
[ "Get", "the", "value", "without", "updating", "the", "expiration" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L129-L137
17,079
mailgun/holster
expire_cache.go
Each
func (c *ExpireCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error { fanOut := NewFanOut(concurrent) keys := c.Keys() for _, key := range keys { fanOut.Run(func(key interface{}) error { c.mutex.Lock() record, ok := c.cache[key] c.mutex.Unlock() if !ok { return errors.Errorf("Each() - key '%+v' disapeared "+ "from cache during iteration", key) } err := callBack(key, record.Value) if err != nil { return err } c.mutex.Lock() if record.ExpireAt.Before(time.Now().UTC()) { delete(c.cache, key) } c.mutex.Unlock() return nil }, key) } // Wait for all the routines to complete errs := fanOut.Wait() if errs != nil { return errs } return nil }
go
func (c *ExpireCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error { fanOut := NewFanOut(concurrent) keys := c.Keys() for _, key := range keys { fanOut.Run(func(key interface{}) error { c.mutex.Lock() record, ok := c.cache[key] c.mutex.Unlock() if !ok { return errors.Errorf("Each() - key '%+v' disapeared "+ "from cache during iteration", key) } err := callBack(key, record.Value) if err != nil { return err } c.mutex.Lock() if record.ExpireAt.Before(time.Now().UTC()) { delete(c.cache, key) } c.mutex.Unlock() return nil }, key) } // Wait for all the routines to complete errs := fanOut.Wait() if errs != nil { return errs } return nil }
[ "func", "(", "c", "*", "ExpireCache", ")", "Each", "(", "concurrent", "int", ",", "callBack", "func", "(", "key", "interface", "{", "}", ",", "value", "interface", "{", "}", ")", "error", ")", "[", "]", "error", "{", "fanOut", ":=", "NewFanOut", "(", "concurrent", ")", "\n", "keys", ":=", "c", ".", "Keys", "(", ")", "\n\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "fanOut", ".", "Run", "(", "func", "(", "key", "interface", "{", "}", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "record", ",", "ok", ":=", "c", ".", "cache", "[", "key", "]", "\n", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "key", ")", "\n", "}", "\n\n", "err", ":=", "callBack", "(", "key", ",", "record", ".", "Value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "if", "record", ".", "ExpireAt", ".", "Before", "(", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ")", "{", "delete", "(", "c", ".", "cache", ",", "key", ")", "\n", "}", "\n", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", ",", "key", ")", "\n", "}", "\n\n", "// Wait for all the routines to complete", "errs", ":=", "fanOut", ".", "Wait", "(", ")", "\n", "if", "errs", "!=", "nil", "{", "return", "errs", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Processes each item in the cache in a thread safe way, such that the cache can be in use // while processing items in the cache
[ "Processes", "each", "item", "in", "the", "cache", "in", "a", "thread", "safe", "way", "such", "that", "the", "cache", "can", "be", "in", "use", "while", "processing", "items", "in", "the", "cache" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L141-L176
17,080
mailgun/holster
expire_cache.go
GetStats
func (c *ExpireCache) GetStats() ExpireCacheStats { c.mutex.Lock() c.stats.Size = int64(len(c.cache)) defer func() { c.stats = ExpireCacheStats{} c.mutex.Unlock() }() return c.stats }
go
func (c *ExpireCache) GetStats() ExpireCacheStats { c.mutex.Lock() c.stats.Size = int64(len(c.cache)) defer func() { c.stats = ExpireCacheStats{} c.mutex.Unlock() }() return c.stats }
[ "func", "(", "c", "*", "ExpireCache", ")", "GetStats", "(", ")", "ExpireCacheStats", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "c", ".", "stats", ".", "Size", "=", "int64", "(", "len", "(", "c", ".", "cache", ")", ")", "\n", "defer", "func", "(", ")", "{", "c", ".", "stats", "=", "ExpireCacheStats", "{", "}", "\n", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "}", "(", ")", "\n", "return", "c", ".", "stats", "\n", "}" ]
// Retrieve stats about the cache
[ "Retrieve", "stats", "about", "the", "cache" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L179-L187
17,081
mailgun/holster
expire_cache.go
Size
func (c *ExpireCache) Size() int64 { defer c.mutex.Unlock() c.mutex.Lock() return int64(len(c.cache)) }
go
func (c *ExpireCache) Size() int64 { defer c.mutex.Unlock() c.mutex.Lock() return int64(len(c.cache)) }
[ "func", "(", "c", "*", "ExpireCache", ")", "Size", "(", ")", "int64", "{", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "return", "int64", "(", "len", "(", "c", ".", "cache", ")", ")", "\n", "}" ]
// Returns the number of items in the cache.
[ "Returns", "the", "number", "of", "items", "in", "the", "cache", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/expire_cache.go#L190-L194
17,082
mailgun/holster
fanout.go
Run
func (p *FanOut) Run(callBack func(interface{}) error, data interface{}) { p.size <- true go func() { err := callBack(data) if err != nil { p.errChan <- err } <-p.size }() }
go
func (p *FanOut) Run(callBack func(interface{}) error, data interface{}) { p.size <- true go func() { err := callBack(data) if err != nil { p.errChan <- err } <-p.size }() }
[ "func", "(", "p", "*", "FanOut", ")", "Run", "(", "callBack", "func", "(", "interface", "{", "}", ")", "error", ",", "data", "interface", "{", "}", ")", "{", "p", ".", "size", "<-", "true", "\n", "go", "func", "(", ")", "{", "err", ":=", "callBack", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "errChan", "<-", "err", "\n", "}", "\n", "<-", "p", ".", "size", "\n", "}", "(", ")", "\n", "}" ]
// Run a new routine with an optional data value
[ "Run", "a", "new", "routine", "with", "an", "optional", "data", "value" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/fanout.go#L63-L72
17,083
mailgun/holster
fanout.go
Wait
func (p *FanOut) Wait() []error { // Wait for all the routines to complete for i := 0; i < cap(p.size); i++ { p.size <- true } // Close the err channel if p.errChan != nil { close(p.errChan) } // Wait until the error collector routine is complete p.wg.Wait() // If there are no errors if len(p.errs) == 0 { return nil } return p.errs }
go
func (p *FanOut) Wait() []error { // Wait for all the routines to complete for i := 0; i < cap(p.size); i++ { p.size <- true } // Close the err channel if p.errChan != nil { close(p.errChan) } // Wait until the error collector routine is complete p.wg.Wait() // If there are no errors if len(p.errs) == 0 { return nil } return p.errs }
[ "func", "(", "p", "*", "FanOut", ")", "Wait", "(", ")", "[", "]", "error", "{", "// Wait for all the routines to complete", "for", "i", ":=", "0", ";", "i", "<", "cap", "(", "p", ".", "size", ")", ";", "i", "++", "{", "p", ".", "size", "<-", "true", "\n", "}", "\n", "// Close the err channel", "if", "p", ".", "errChan", "!=", "nil", "{", "close", "(", "p", ".", "errChan", ")", "\n", "}", "\n\n", "// Wait until the error collector routine is complete", "p", ".", "wg", ".", "Wait", "(", ")", "\n\n", "// If there are no errors", "if", "len", "(", "p", ".", "errs", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "p", ".", "errs", "\n", "}" ]
// Wait for all the routines to complete and return any errors
[ "Wait", "for", "all", "the", "routines", "to", "complete", "and", "return", "any", "errors" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/fanout.go#L75-L93
17,084
mailgun/holster
random.go
RandomRunes
func RandomRunes(prefix string, length int, runes ...string) string { chars := strings.Join(runes, "") var bytes = make([]byte, length) rand.Read(bytes) for i, b := range bytes { bytes[i] = chars[b%byte(len(chars))] } return prefix + string(bytes) }
go
func RandomRunes(prefix string, length int, runes ...string) string { chars := strings.Join(runes, "") var bytes = make([]byte, length) rand.Read(bytes) for i, b := range bytes { bytes[i] = chars[b%byte(len(chars))] } return prefix + string(bytes) }
[ "func", "RandomRunes", "(", "prefix", "string", ",", "length", "int", ",", "runes", "...", "string", ")", "string", "{", "chars", ":=", "strings", ".", "Join", "(", "runes", ",", "\"", "\"", ")", "\n", "var", "bytes", "=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "rand", ".", "Read", "(", "bytes", ")", "\n", "for", "i", ",", "b", ":=", "range", "bytes", "{", "bytes", "[", "i", "]", "=", "chars", "[", "b", "%", "byte", "(", "len", "(", "chars", ")", ")", "]", "\n", "}", "\n", "return", "prefix", "+", "string", "(", "bytes", ")", "\n", "}" ]
// Return a random string made up of characters passed
[ "Return", "a", "random", "string", "made", "up", "of", "characters", "passed" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/random.go#L28-L36
17,085
mailgun/holster
random.go
RandomAlpha
func RandomAlpha(prefix string, length int) string { return RandomRunes(prefix, length, AlphaRunes) }
go
func RandomAlpha(prefix string, length int) string { return RandomRunes(prefix, length, AlphaRunes) }
[ "func", "RandomAlpha", "(", "prefix", "string", ",", "length", "int", ")", "string", "{", "return", "RandomRunes", "(", "prefix", ",", "length", ",", "AlphaRunes", ")", "\n", "}" ]
// Return a random string of alpha characters
[ "Return", "a", "random", "string", "of", "alpha", "characters" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/random.go#L39-L41
17,086
mailgun/holster
random.go
RandomString
func RandomString(prefix string, length int) string { return RandomRunes(prefix, length, AlphaRunes, NumericRunes) }
go
func RandomString(prefix string, length int) string { return RandomRunes(prefix, length, AlphaRunes, NumericRunes) }
[ "func", "RandomString", "(", "prefix", "string", ",", "length", "int", ")", "string", "{", "return", "RandomRunes", "(", "prefix", ",", "length", ",", "AlphaRunes", ",", "NumericRunes", ")", "\n", "}" ]
// Return a random string of alpha and numeric characters
[ "Return", "a", "random", "string", "of", "alpha", "and", "numeric", "characters" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/random.go#L44-L46
17,087
mailgun/holster
random.go
RandomItem
func RandomItem(items ...string) string { var bytes = make([]byte, 1) rand.Read(bytes) return items[bytes[0]%byte(len(items))] }
go
func RandomItem(items ...string) string { var bytes = make([]byte, 1) rand.Read(bytes) return items[bytes[0]%byte(len(items))] }
[ "func", "RandomItem", "(", "items", "...", "string", ")", "string", "{", "var", "bytes", "=", "make", "(", "[", "]", "byte", ",", "1", ")", "\n", "rand", ".", "Read", "(", "bytes", ")", "\n", "return", "items", "[", "bytes", "[", "0", "]", "%", "byte", "(", "len", "(", "items", ")", ")", "]", "\n", "}" ]
// Given a list of strings, return one of the strings randomly
[ "Given", "a", "list", "of", "strings", "return", "one", "of", "the", "strings", "randomly" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/random.go#L49-L53
17,088
mailgun/holster
clock/clock.go
Advance
func Advance(d time.Duration) time.Duration { ft, ok := provider.(*frozenTime) if !ok { panic("Freeze time first!") } ft.advance(d) return Now().UTC().Sub(frozenAt) }
go
func Advance(d time.Duration) time.Duration { ft, ok := provider.(*frozenTime) if !ok { panic("Freeze time first!") } ft.advance(d) return Now().UTC().Sub(frozenAt) }
[ "func", "Advance", "(", "d", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "ft", ",", "ok", ":=", "provider", ".", "(", "*", "frozenTime", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "ft", ".", "advance", "(", "d", ")", "\n", "return", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Sub", "(", "frozenAt", ")", "\n", "}" ]
// Makes the deterministic time move forward by the specified duration, firing // timers along the way in the natural order. It returns how much time has // passed since it was frozen. So you can assert on the return value in tests // to make it explicit where you stand on the deterministic time scale.
[ "Makes", "the", "deterministic", "time", "move", "forward", "by", "the", "specified", "duration", "firing", "timers", "along", "the", "way", "in", "the", "natural", "order", ".", "It", "returns", "how", "much", "time", "has", "passed", "since", "it", "was", "frozen", ".", "So", "you", "can", "assert", "on", "the", "return", "value", "in", "tests", "to", "make", "it", "explicit", "where", "you", "stand", "on", "the", "deterministic", "time", "scale", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/clock/clock.go#L54-L61
17,089
mailgun/holster
clock/clock.go
Wait4Scheduled
func Wait4Scheduled(count int, timeout time.Duration) bool { return provider.Wait4Scheduled(count, timeout) }
go
func Wait4Scheduled(count int, timeout time.Duration) bool { return provider.Wait4Scheduled(count, timeout) }
[ "func", "Wait4Scheduled", "(", "count", "int", ",", "timeout", "time", ".", "Duration", ")", "bool", "{", "return", "provider", ".", "Wait4Scheduled", "(", "count", ",", "timeout", ")", "\n", "}" ]
// Wait4Scheduled blocks until either there are n or more scheduled events, or // the timeout elapses. It returns true if the wait condition has been met // before the timeout expired, false otherwise.
[ "Wait4Scheduled", "blocks", "until", "either", "there", "are", "n", "or", "more", "scheduled", "events", "or", "the", "timeout", "elapses", ".", "It", "returns", "true", "if", "the", "wait", "condition", "has", "been", "met", "before", "the", "timeout", "expired", "false", "otherwise", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/clock/clock.go#L66-L68
17,090
mailgun/holster
clock/clock.go
AfterFunc
func AfterFunc(d time.Duration, f func()) Timer { return provider.AfterFunc(d, f) }
go
func AfterFunc(d time.Duration, f func()) Timer { return provider.AfterFunc(d, f) }
[ "func", "AfterFunc", "(", "d", "time", ".", "Duration", ",", "f", "func", "(", ")", ")", "Timer", "{", "return", "provider", ".", "AfterFunc", "(", "d", ",", "f", ")", "\n", "}" ]
// AfterFunc see time.AfterFunc.
[ "AfterFunc", "see", "time", ".", "AfterFunc", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/clock/clock.go#L98-L100
17,091
mailgun/holster
httpsign/auth.go
SignRequest
func (s *Service) SignRequest(r *http.Request) error { if s.secretKey == nil { return fmt.Errorf("service not loaded with key.") } return s.SignRequestWithKey(r, s.secretKey) }
go
func (s *Service) SignRequest(r *http.Request) error { if s.secretKey == nil { return fmt.Errorf("service not loaded with key.") } return s.SignRequestWithKey(r, s.secretKey) }
[ "func", "(", "s", "*", "Service", ")", "SignRequest", "(", "r", "*", "http", ".", "Request", ")", "error", "{", "if", "s", ".", "secretKey", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "s", ".", "SignRequestWithKey", "(", "r", ",", "s", ".", "secretKey", ")", "\n", "}" ]
// Signs a given HTTP request with signature, nonce, and timestamp.
[ "Signs", "a", "given", "HTTP", "request", "with", "signature", "nonce", "and", "timestamp", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/httpsign/auth.go#L216-L221
17,092
mailgun/holster
httpsign/auth.go
AuthenticateRequest
func (s *Service) AuthenticateRequest(r *http.Request) error { if s.secretKey == nil { return fmt.Errorf("service not loaded with key.") } return s.AuthenticateRequestWithKey(r, s.secretKey) }
go
func (s *Service) AuthenticateRequest(r *http.Request) error { if s.secretKey == nil { return fmt.Errorf("service not loaded with key.") } return s.AuthenticateRequestWithKey(r, s.secretKey) }
[ "func", "(", "s", "*", "Service", ")", "AuthenticateRequest", "(", "r", "*", "http", ".", "Request", ")", "error", "{", "if", "s", ".", "secretKey", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "s", ".", "AuthenticateRequestWithKey", "(", "r", ",", "s", ".", "secretKey", ")", "\n", "}" ]
// Authenticates HTTP request to ensure it was sent by an authorized sender.
[ "Authenticates", "HTTP", "request", "to", "ensure", "it", "was", "sent", "by", "an", "authorized", "sender", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/httpsign/auth.go#L265-L270
17,093
mailgun/holster
httpsign/auth.go
AuthenticateRequestWithKey
func (s *Service) AuthenticateRequestWithKey(r *http.Request, secretKey []byte) (err error) { // Emit a success or failure metric on return. defer func() { if err == nil { s.metricsClient.Inc("success", 1, 1) } else { s.metricsClient.Inc("failure", 1, 1) } }() // extract parameters signature := r.Header.Get(s.config.SignatureHeaderName) if signature == "" { return fmt.Errorf("header not found: %v", s.config.SignatureHeaderName) } nonce := r.Header.Get(s.config.NonceHeaderName) if nonce == "" { return fmt.Errorf("header not found: %v", s.config.NonceHeaderName) } timestamp := r.Header.Get(s.config.TimestampHeaderName) if timestamp == "" { return fmt.Errorf("header not found: %v", s.config.TimestampHeaderName) } // extract request body bytes bodyBytes, err := readBody(r) if err != nil { return err } // extract any headers if requested headerValues, err := extractHeaderValues(r, s.config.HeadersToSign) if err != nil { return err } // check the hmac isValid, err := checkMAC(secretKey, s.config.SignVerbAndURI, r.Method, r.URL.RequestURI(), timestamp, nonce, bodyBytes, headerValues, signature) if !isValid { return err } // check timestamp isValid, err = s.CheckTimestamp(timestamp) if !isValid { return err } // check to see if we have seen nonce before inCache := s.nonceCache.InCache(nonce) if inCache { return fmt.Errorf("nonce already in cache: %v", nonce) } // set the body bytes we read in to nil to hint to the gc to pick it up bodyBytes = nil return nil }
go
func (s *Service) AuthenticateRequestWithKey(r *http.Request, secretKey []byte) (err error) { // Emit a success or failure metric on return. defer func() { if err == nil { s.metricsClient.Inc("success", 1, 1) } else { s.metricsClient.Inc("failure", 1, 1) } }() // extract parameters signature := r.Header.Get(s.config.SignatureHeaderName) if signature == "" { return fmt.Errorf("header not found: %v", s.config.SignatureHeaderName) } nonce := r.Header.Get(s.config.NonceHeaderName) if nonce == "" { return fmt.Errorf("header not found: %v", s.config.NonceHeaderName) } timestamp := r.Header.Get(s.config.TimestampHeaderName) if timestamp == "" { return fmt.Errorf("header not found: %v", s.config.TimestampHeaderName) } // extract request body bytes bodyBytes, err := readBody(r) if err != nil { return err } // extract any headers if requested headerValues, err := extractHeaderValues(r, s.config.HeadersToSign) if err != nil { return err } // check the hmac isValid, err := checkMAC(secretKey, s.config.SignVerbAndURI, r.Method, r.URL.RequestURI(), timestamp, nonce, bodyBytes, headerValues, signature) if !isValid { return err } // check timestamp isValid, err = s.CheckTimestamp(timestamp) if !isValid { return err } // check to see if we have seen nonce before inCache := s.nonceCache.InCache(nonce) if inCache { return fmt.Errorf("nonce already in cache: %v", nonce) } // set the body bytes we read in to nil to hint to the gc to pick it up bodyBytes = nil return nil }
[ "func", "(", "s", "*", "Service", ")", "AuthenticateRequestWithKey", "(", "r", "*", "http", ".", "Request", ",", "secretKey", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "// Emit a success or failure metric on return.", "defer", "func", "(", ")", "{", "if", "err", "==", "nil", "{", "s", ".", "metricsClient", ".", "Inc", "(", "\"", "\"", ",", "1", ",", "1", ")", "\n", "}", "else", "{", "s", ".", "metricsClient", ".", "Inc", "(", "\"", "\"", ",", "1", ",", "1", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "// extract parameters", "signature", ":=", "r", ".", "Header", ".", "Get", "(", "s", ".", "config", ".", "SignatureHeaderName", ")", "\n", "if", "signature", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "config", ".", "SignatureHeaderName", ")", "\n", "}", "\n", "nonce", ":=", "r", ".", "Header", ".", "Get", "(", "s", ".", "config", ".", "NonceHeaderName", ")", "\n", "if", "nonce", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "config", ".", "NonceHeaderName", ")", "\n", "}", "\n", "timestamp", ":=", "r", ".", "Header", ".", "Get", "(", "s", ".", "config", ".", "TimestampHeaderName", ")", "\n", "if", "timestamp", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "config", ".", "TimestampHeaderName", ")", "\n", "}", "\n\n", "// extract request body bytes", "bodyBytes", ",", "err", ":=", "readBody", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// extract any headers if requested", "headerValues", ",", "err", ":=", "extractHeaderValues", "(", "r", ",", "s", ".", "config", ".", "HeadersToSign", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// check the hmac", "isValid", ",", "err", ":=", "checkMAC", "(", "secretKey", ",", "s", ".", "config", ".", "SignVerbAndURI", ",", "r", ".", "Method", ",", "r", ".", "URL", ".", "RequestURI", "(", ")", ",", "timestamp", ",", "nonce", ",", "bodyBytes", ",", "headerValues", ",", "signature", ")", "\n", "if", "!", "isValid", "{", "return", "err", "\n", "}", "\n\n", "// check timestamp", "isValid", ",", "err", "=", "s", ".", "CheckTimestamp", "(", "timestamp", ")", "\n", "if", "!", "isValid", "{", "return", "err", "\n", "}", "\n\n", "// check to see if we have seen nonce before", "inCache", ":=", "s", ".", "nonceCache", ".", "InCache", "(", "nonce", ")", "\n", "if", "inCache", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "nonce", ")", "\n", "}", "\n\n", "// set the body bytes we read in to nil to hint to the gc to pick it up", "bodyBytes", "=", "nil", "\n\n", "return", "nil", "\n", "}" ]
// Authenticates HTTP request to ensure it was sent by an authorized sender. // Checks message signature with the passed in key, not the one initialized with.
[ "Authenticates", "HTTP", "request", "to", "ensure", "it", "was", "sent", "by", "an", "authorized", "sender", ".", "Checks", "message", "signature", "with", "the", "passed", "in", "key", "not", "the", "one", "initialized", "with", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/httpsign/auth.go#L274-L333
17,094
mailgun/holster
httpsign/auth.go
CheckTimestamp
func (s *Service) CheckTimestamp(timestampHeader string) (bool, error) { // convert unix timestamp string into time struct timestamp, err := strconv.ParseInt(timestampHeader, 10, 0) if err != nil { return false, fmt.Errorf("unable to parse %v: %v", s.config.TimestampHeaderName, timestampHeader) } now := s.clock.Now().UTC().Unix() // if timestamp is from the future, it's invalid if timestamp >= now+MaxSkewSec { return false, fmt.Errorf("timestamp header from the future; now: %v; %v: %v; difference: %v", now, s.config.TimestampHeaderName, timestamp, timestamp-now) } // if the timestamp is older than ttl - skew, it's invalid if timestamp <= now-int64(s.nonceCache.cacheTTL-MaxSkewSec) { return false, fmt.Errorf("timestamp header too old; now: %v; %v: %v; difference: %v", now, s.config.TimestampHeaderName, timestamp, now-timestamp) } return true, nil }
go
func (s *Service) CheckTimestamp(timestampHeader string) (bool, error) { // convert unix timestamp string into time struct timestamp, err := strconv.ParseInt(timestampHeader, 10, 0) if err != nil { return false, fmt.Errorf("unable to parse %v: %v", s.config.TimestampHeaderName, timestampHeader) } now := s.clock.Now().UTC().Unix() // if timestamp is from the future, it's invalid if timestamp >= now+MaxSkewSec { return false, fmt.Errorf("timestamp header from the future; now: %v; %v: %v; difference: %v", now, s.config.TimestampHeaderName, timestamp, timestamp-now) } // if the timestamp is older than ttl - skew, it's invalid if timestamp <= now-int64(s.nonceCache.cacheTTL-MaxSkewSec) { return false, fmt.Errorf("timestamp header too old; now: %v; %v: %v; difference: %v", now, s.config.TimestampHeaderName, timestamp, now-timestamp) } return true, nil }
[ "func", "(", "s", "*", "Service", ")", "CheckTimestamp", "(", "timestampHeader", "string", ")", "(", "bool", ",", "error", ")", "{", "// convert unix timestamp string into time struct", "timestamp", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "timestampHeader", ",", "10", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "config", ".", "TimestampHeaderName", ",", "timestampHeader", ")", "\n", "}", "\n\n", "now", ":=", "s", ".", "clock", ".", "Now", "(", ")", ".", "UTC", "(", ")", ".", "Unix", "(", ")", "\n\n", "// if timestamp is from the future, it's invalid", "if", "timestamp", ">=", "now", "+", "MaxSkewSec", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "now", ",", "s", ".", "config", ".", "TimestampHeaderName", ",", "timestamp", ",", "timestamp", "-", "now", ")", "\n", "}", "\n\n", "// if the timestamp is older than ttl - skew, it's invalid", "if", "timestamp", "<=", "now", "-", "int64", "(", "s", ".", "nonceCache", ".", "cacheTTL", "-", "MaxSkewSec", ")", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "now", ",", "s", ".", "config", ".", "TimestampHeaderName", ",", "timestamp", ",", "now", "-", "timestamp", ")", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// Parses a timestamp header and returns true if the timestamp is neither older than the TTL or is from the future.
[ "Parses", "a", "timestamp", "header", "and", "returns", "true", "if", "the", "timestamp", "is", "neither", "older", "than", "the", "TTL", "or", "is", "from", "the", "future", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/httpsign/auth.go#L336-L358
17,095
mailgun/holster
stack/stack.go
GetLastFrame
func GetLastFrame(frames errors.StackTrace) FrameInfo { if len(frames) == 0 { return FrameInfo{} } pc := uintptr(frames[0]) - 1 fn := runtime.FuncForPC(pc) if fn == nil { return FrameInfo{Func: fmt.Sprintf("unknown func at %v", pc)} } filePath, lineNo := fn.FileLine(pc) return FrameInfo{ CallStack: GetCallStack(frames), Func: FuncName(fn), File: filePath, LineNo: lineNo, } }
go
func GetLastFrame(frames errors.StackTrace) FrameInfo { if len(frames) == 0 { return FrameInfo{} } pc := uintptr(frames[0]) - 1 fn := runtime.FuncForPC(pc) if fn == nil { return FrameInfo{Func: fmt.Sprintf("unknown func at %v", pc)} } filePath, lineNo := fn.FileLine(pc) return FrameInfo{ CallStack: GetCallStack(frames), Func: FuncName(fn), File: filePath, LineNo: lineNo, } }
[ "func", "GetLastFrame", "(", "frames", "errors", ".", "StackTrace", ")", "FrameInfo", "{", "if", "len", "(", "frames", ")", "==", "0", "{", "return", "FrameInfo", "{", "}", "\n", "}", "\n", "pc", ":=", "uintptr", "(", "frames", "[", "0", "]", ")", "-", "1", "\n", "fn", ":=", "runtime", ".", "FuncForPC", "(", "pc", ")", "\n", "if", "fn", "==", "nil", "{", "return", "FrameInfo", "{", "Func", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pc", ")", "}", "\n", "}", "\n", "filePath", ",", "lineNo", ":=", "fn", ".", "FileLine", "(", "pc", ")", "\n", "return", "FrameInfo", "{", "CallStack", ":", "GetCallStack", "(", "frames", ")", ",", "Func", ":", "FuncName", "(", "fn", ")", ",", "File", ":", "filePath", ",", "LineNo", ":", "lineNo", ",", "}", "\n", "}" ]
// Returns Caller information on the first frame in the stack trace
[ "Returns", "Caller", "information", "on", "the", "first", "frame", "in", "the", "stack", "trace" ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/stack/stack.go#L29-L45
17,096
mailgun/holster
secret/secret.go
New
func New(config *Config) (SecretService, error) { var err error var keyBytes *[SecretKeyLength]byte var metricsClient metrics.Client // Read in key from KeyPath or if not given, try getting them from KeyBytes. if config.KeyPath != "" { if keyBytes, err = ReadKeyFromDisk(config.KeyPath); err != nil { return nil, err } } else { if config.KeyBytes == nil { return nil, errors.New("No key bytes provided.") } keyBytes = config.KeyBytes } // setup metrics service if config.EmitStats { // get hostname of box hostname, err := os.Hostname() if err != nil { return nil, fmt.Errorf("failed to obtain hostname: %v", err) } // build lemma prefix prefix := "lemma." + strings.Replace(hostname, ".", "_", -1) if config.StatsdPrefix != "" { prefix += "." + config.StatsdPrefix } // build metrics client hostport := fmt.Sprintf("%v:%v", config.StatsdHost, config.StatsdPort) metricsClient, err = metrics.NewWithOptions(hostport, prefix, metrics.Options{UseBuffering: true}) if err != nil { return nil, err } } else { // if you don't want to emit stats, use the nop client metricsClient = metrics.NewNop() } return &Service{ secretKey: keyBytes, metricsClient: metricsClient, }, nil }
go
func New(config *Config) (SecretService, error) { var err error var keyBytes *[SecretKeyLength]byte var metricsClient metrics.Client // Read in key from KeyPath or if not given, try getting them from KeyBytes. if config.KeyPath != "" { if keyBytes, err = ReadKeyFromDisk(config.KeyPath); err != nil { return nil, err } } else { if config.KeyBytes == nil { return nil, errors.New("No key bytes provided.") } keyBytes = config.KeyBytes } // setup metrics service if config.EmitStats { // get hostname of box hostname, err := os.Hostname() if err != nil { return nil, fmt.Errorf("failed to obtain hostname: %v", err) } // build lemma prefix prefix := "lemma." + strings.Replace(hostname, ".", "_", -1) if config.StatsdPrefix != "" { prefix += "." + config.StatsdPrefix } // build metrics client hostport := fmt.Sprintf("%v:%v", config.StatsdHost, config.StatsdPort) metricsClient, err = metrics.NewWithOptions(hostport, prefix, metrics.Options{UseBuffering: true}) if err != nil { return nil, err } } else { // if you don't want to emit stats, use the nop client metricsClient = metrics.NewNop() } return &Service{ secretKey: keyBytes, metricsClient: metricsClient, }, nil }
[ "func", "New", "(", "config", "*", "Config", ")", "(", "SecretService", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "keyBytes", "*", "[", "SecretKeyLength", "]", "byte", "\n", "var", "metricsClient", "metrics", ".", "Client", "\n\n", "// Read in key from KeyPath or if not given, try getting them from KeyBytes.", "if", "config", ".", "KeyPath", "!=", "\"", "\"", "{", "if", "keyBytes", ",", "err", "=", "ReadKeyFromDisk", "(", "config", ".", "KeyPath", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "else", "{", "if", "config", ".", "KeyBytes", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "keyBytes", "=", "config", ".", "KeyBytes", "\n", "}", "\n\n", "// setup metrics service", "if", "config", ".", "EmitStats", "{", "// get hostname of box", "hostname", ",", "err", ":=", "os", ".", "Hostname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// build lemma prefix", "prefix", ":=", "\"", "\"", "+", "strings", ".", "Replace", "(", "hostname", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "if", "config", ".", "StatsdPrefix", "!=", "\"", "\"", "{", "prefix", "+=", "\"", "\"", "+", "config", ".", "StatsdPrefix", "\n", "}", "\n\n", "// build metrics client", "hostport", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "config", ".", "StatsdHost", ",", "config", ".", "StatsdPort", ")", "\n", "metricsClient", ",", "err", "=", "metrics", ".", "NewWithOptions", "(", "hostport", ",", "prefix", ",", "metrics", ".", "Options", "{", "UseBuffering", ":", "true", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "else", "{", "// if you don't want to emit stats, use the nop client", "metricsClient", "=", "metrics", ".", "NewNop", "(", ")", "\n", "}", "\n\n", "return", "&", "Service", "{", "secretKey", ":", "keyBytes", ",", "metricsClient", ":", "metricsClient", ",", "}", ",", "nil", "\n", "}" ]
// New returns a new Service. Config can not be nil.
[ "New", "returns", "a", "new", "Service", ".", "Config", "can", "not", "be", "nil", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/secret/secret.go#L94-L140
17,097
mailgun/holster
secret/secret.go
Seal
func Seal(value []byte, secretKey *[SecretKeyLength]byte) (SealedData, error) { if secretKey == nil { return nil, fmt.Errorf("secret key is nil") } secretService, err := New(&Config{KeyBytes: secretKey}) if err != nil { return nil, err } return secretService.Seal(value) }
go
func Seal(value []byte, secretKey *[SecretKeyLength]byte) (SealedData, error) { if secretKey == nil { return nil, fmt.Errorf("secret key is nil") } secretService, err := New(&Config{KeyBytes: secretKey}) if err != nil { return nil, err } return secretService.Seal(value) }
[ "func", "Seal", "(", "value", "[", "]", "byte", ",", "secretKey", "*", "[", "SecretKeyLength", "]", "byte", ")", "(", "SealedData", ",", "error", ")", "{", "if", "secretKey", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "secretService", ",", "err", ":=", "New", "(", "&", "Config", "{", "KeyBytes", ":", "secretKey", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "secretService", ".", "Seal", "(", "value", ")", "\n", "}" ]
// Seal takes plaintext and a key and returns encrypted and authenticated ciphertext. // Allows passing in a key and useful for one off sealing purposes, otherwise // create a secret.Service to seal multiple times.
[ "Seal", "takes", "plaintext", "and", "a", "key", "and", "returns", "encrypted", "and", "authenticated", "ciphertext", ".", "Allows", "passing", "in", "a", "key", "and", "useful", "for", "one", "off", "sealing", "purposes", "otherwise", "create", "a", "secret", ".", "Service", "to", "seal", "multiple", "times", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/secret/secret.go#L145-L156
17,098
mailgun/holster
secret/secret.go
Open
func Open(e SealedData, secretKey *[SecretKeyLength]byte) ([]byte, error) { if secretKey == nil { return nil, fmt.Errorf("secret key is nil") } secretService, err := New(&Config{KeyBytes: secretKey}) if err != nil { return nil, err } return secretService.Open(e) }
go
func Open(e SealedData, secretKey *[SecretKeyLength]byte) ([]byte, error) { if secretKey == nil { return nil, fmt.Errorf("secret key is nil") } secretService, err := New(&Config{KeyBytes: secretKey}) if err != nil { return nil, err } return secretService.Open(e) }
[ "func", "Open", "(", "e", "SealedData", ",", "secretKey", "*", "[", "SecretKeyLength", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "secretKey", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "secretService", ",", "err", ":=", "New", "(", "&", "Config", "{", "KeyBytes", ":", "secretKey", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "secretService", ".", "Open", "(", "e", ")", "\n", "}" ]
// Open authenticates the ciphertext and if valid, decrypts and returns plaintext. // Allows passing in a key and useful for one off opening purposes, otherwise // create a secret.Service to open multiple times.
[ "Open", "authenticates", "the", "ciphertext", "and", "if", "valid", "decrypts", "and", "returns", "plaintext", ".", "Allows", "passing", "in", "a", "key", "and", "useful", "for", "one", "off", "opening", "purposes", "otherwise", "create", "a", "secret", ".", "Service", "to", "open", "multiple", "times", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/secret/secret.go#L161-L172
17,099
mailgun/holster
secret/secret.go
Seal
func (s *Service) Seal(value []byte) (SealedData, error) { // generate nonce nonce, err := generateNonce() if err != nil { return nil, fmt.Errorf("unable to generate nonce: %v", err) } // use nacl secret box to encrypt plaintext var encrypted []byte encrypted = secretbox.Seal(encrypted, value, nonce, s.secretKey) // return sealed ciphertext return &SealedBytes{ Ciphertext: encrypted, Nonce: nonce[:], }, nil }
go
func (s *Service) Seal(value []byte) (SealedData, error) { // generate nonce nonce, err := generateNonce() if err != nil { return nil, fmt.Errorf("unable to generate nonce: %v", err) } // use nacl secret box to encrypt plaintext var encrypted []byte encrypted = secretbox.Seal(encrypted, value, nonce, s.secretKey) // return sealed ciphertext return &SealedBytes{ Ciphertext: encrypted, Nonce: nonce[:], }, nil }
[ "func", "(", "s", "*", "Service", ")", "Seal", "(", "value", "[", "]", "byte", ")", "(", "SealedData", ",", "error", ")", "{", "// generate nonce", "nonce", ",", "err", ":=", "generateNonce", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// use nacl secret box to encrypt plaintext", "var", "encrypted", "[", "]", "byte", "\n", "encrypted", "=", "secretbox", ".", "Seal", "(", "encrypted", ",", "value", ",", "nonce", ",", "s", ".", "secretKey", ")", "\n\n", "// return sealed ciphertext", "return", "&", "SealedBytes", "{", "Ciphertext", ":", "encrypted", ",", "Nonce", ":", "nonce", "[", ":", "]", ",", "}", ",", "nil", "\n", "}" ]
// Seal takes plaintext and returns encrypted and authenticated ciphertext.
[ "Seal", "takes", "plaintext", "and", "returns", "encrypted", "and", "authenticated", "ciphertext", "." ]
769f8d7f9b18d38062e704a0c26c8861702f0ea6
https://github.com/mailgun/holster/blob/769f8d7f9b18d38062e704a0c26c8861702f0ea6/secret/secret.go#L175-L191