repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1003-L1012
go
train
// ListVersionsByFunctionWithContext mocks base method
func (m *MockLambdaAPI) ListVersionsByFunctionWithContext(arg0 aws.Context, arg1 *lambda.ListVersionsByFunctionInput, arg2 ...request.Option) (*lambda.ListVersionsByFunctionOutput, error)
// ListVersionsByFunctionWithContext mocks base method func (m *MockLambdaAPI) ListVersionsByFunctionWithContext(arg0 aws.Context, arg1 *lambda.ListVersionsByFunctionInput, arg2 ...request.Option) (*lambda.ListVersionsByFunctionOutput, error)
{ varargs := []interface{}{arg0, arg1} for _, a := range arg2 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "ListVersionsByFunctionWithContext", varargs...) ret0, _ := ret[0].(*lambda.ListVersionsByFunctionOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1021-L1026
go
train
// PublishVersion mocks base method
func (m *MockLambdaAPI) PublishVersion(arg0 *lambda.PublishVersionInput) (*lambda.FunctionConfiguration, error)
// PublishVersion mocks base method func (m *MockLambdaAPI) PublishVersion(arg0 *lambda.PublishVersionInput) (*lambda.FunctionConfiguration, error)
{ ret := m.ctrl.Call(m, "PublishVersion", arg0) ret0, _ := ret[0].(*lambda.FunctionConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1034-L1039
go
train
// PublishVersionRequest mocks base method
func (m *MockLambdaAPI) PublishVersionRequest(arg0 *lambda.PublishVersionInput) (*request.Request, *lambda.FunctionConfiguration)
// PublishVersionRequest mocks base method func (m *MockLambdaAPI) PublishVersionRequest(arg0 *lambda.PublishVersionInput) (*request.Request, *lambda.FunctionConfiguration)
{ ret := m.ctrl.Call(m, "PublishVersionRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.FunctionConfiguration) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1065-L1070
go
train
// PutFunctionConcurrency mocks base method
func (m *MockLambdaAPI) PutFunctionConcurrency(arg0 *lambda.PutFunctionConcurrencyInput) (*lambda.PutFunctionConcurrencyOutput, error)
// PutFunctionConcurrency mocks base method func (m *MockLambdaAPI) PutFunctionConcurrency(arg0 *lambda.PutFunctionConcurrencyInput) (*lambda.PutFunctionConcurrencyOutput, error)
{ ret := m.ctrl.Call(m, "PutFunctionConcurrency", arg0) ret0, _ := ret[0].(*lambda.PutFunctionConcurrencyOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1078-L1083
go
train
// PutFunctionConcurrencyRequest mocks base method
func (m *MockLambdaAPI) PutFunctionConcurrencyRequest(arg0 *lambda.PutFunctionConcurrencyInput) (*request.Request, *lambda.PutFunctionConcurrencyOutput)
// PutFunctionConcurrencyRequest mocks base method func (m *MockLambdaAPI) PutFunctionConcurrencyRequest(arg0 *lambda.PutFunctionConcurrencyInput) (*request.Request, *lambda.PutFunctionConcurrencyOutput)
{ ret := m.ctrl.Call(m, "PutFunctionConcurrencyRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.PutFunctionConcurrencyOutput) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1091-L1100
go
train
// PutFunctionConcurrencyWithContext mocks base method
func (m *MockLambdaAPI) PutFunctionConcurrencyWithContext(arg0 aws.Context, arg1 *lambda.PutFunctionConcurrencyInput, arg2 ...request.Option) (*lambda.PutFunctionConcurrencyOutput, error)
// PutFunctionConcurrencyWithContext mocks base method func (m *MockLambdaAPI) PutFunctionConcurrencyWithContext(arg0 aws.Context, arg1 *lambda.PutFunctionConcurrencyInput, arg2 ...request.Option) (*lambda.PutFunctionConcurrencyOutput, error)
{ varargs := []interface{}{arg0, arg1} for _, a := range arg2 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "PutFunctionConcurrencyWithContext", varargs...) ret0, _ := ret[0].(*lambda.PutFunctionConcurrencyOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1109-L1114
go
train
// RemovePermission mocks base method
func (m *MockLambdaAPI) RemovePermission(arg0 *lambda.RemovePermissionInput) (*lambda.RemovePermissionOutput, error)
// RemovePermission mocks base method func (m *MockLambdaAPI) RemovePermission(arg0 *lambda.RemovePermissionInput) (*lambda.RemovePermissionOutput, error)
{ ret := m.ctrl.Call(m, "RemovePermission", arg0) ret0, _ := ret[0].(*lambda.RemovePermissionOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1122-L1127
go
train
// RemovePermissionRequest mocks base method
func (m *MockLambdaAPI) RemovePermissionRequest(arg0 *lambda.RemovePermissionInput) (*request.Request, *lambda.RemovePermissionOutput)
// RemovePermissionRequest mocks base method func (m *MockLambdaAPI) RemovePermissionRequest(arg0 *lambda.RemovePermissionInput) (*request.Request, *lambda.RemovePermissionOutput)
{ ret := m.ctrl.Call(m, "RemovePermissionRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.RemovePermissionOutput) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1135-L1144
go
train
// RemovePermissionWithContext mocks base method
func (m *MockLambdaAPI) RemovePermissionWithContext(arg0 aws.Context, arg1 *lambda.RemovePermissionInput, arg2 ...request.Option) (*lambda.RemovePermissionOutput, error)
// RemovePermissionWithContext mocks base method func (m *MockLambdaAPI) RemovePermissionWithContext(arg0 aws.Context, arg1 *lambda.RemovePermissionInput, arg2 ...request.Option) (*lambda.RemovePermissionOutput, error)
{ varargs := []interface{}{arg0, arg1} for _, a := range arg2 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "RemovePermissionWithContext", varargs...) ret0, _ := ret[0].(*lambda.RemovePermissionOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1153-L1158
go
train
// TagResource mocks base method
func (m *MockLambdaAPI) TagResource(arg0 *lambda.TagResourceInput) (*lambda.TagResourceOutput, error)
// TagResource mocks base method func (m *MockLambdaAPI) TagResource(arg0 *lambda.TagResourceInput) (*lambda.TagResourceOutput, error)
{ ret := m.ctrl.Call(m, "TagResource", arg0) ret0, _ := ret[0].(*lambda.TagResourceOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1166-L1171
go
train
// TagResourceRequest mocks base method
func (m *MockLambdaAPI) TagResourceRequest(arg0 *lambda.TagResourceInput) (*request.Request, *lambda.TagResourceOutput)
// TagResourceRequest mocks base method func (m *MockLambdaAPI) TagResourceRequest(arg0 *lambda.TagResourceInput) (*request.Request, *lambda.TagResourceOutput)
{ ret := m.ctrl.Call(m, "TagResourceRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.TagResourceOutput) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1179-L1188
go
train
// TagResourceWithContext mocks base method
func (m *MockLambdaAPI) TagResourceWithContext(arg0 aws.Context, arg1 *lambda.TagResourceInput, arg2 ...request.Option) (*lambda.TagResourceOutput, error)
// TagResourceWithContext mocks base method func (m *MockLambdaAPI) TagResourceWithContext(arg0 aws.Context, arg1 *lambda.TagResourceInput, arg2 ...request.Option) (*lambda.TagResourceOutput, error)
{ varargs := []interface{}{arg0, arg1} for _, a := range arg2 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "TagResourceWithContext", varargs...) ret0, _ := ret[0].(*lambda.TagResourceOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1197-L1202
go
train
// UntagResource mocks base method
func (m *MockLambdaAPI) UntagResource(arg0 *lambda.UntagResourceInput) (*lambda.UntagResourceOutput, error)
// UntagResource mocks base method func (m *MockLambdaAPI) UntagResource(arg0 *lambda.UntagResourceInput) (*lambda.UntagResourceOutput, error)
{ ret := m.ctrl.Call(m, "UntagResource", arg0) ret0, _ := ret[0].(*lambda.UntagResourceOutput) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1210-L1215
go
train
// UntagResourceRequest mocks base method
func (m *MockLambdaAPI) UntagResourceRequest(arg0 *lambda.UntagResourceInput) (*request.Request, *lambda.UntagResourceOutput)
// UntagResourceRequest mocks base method func (m *MockLambdaAPI) UntagResourceRequest(arg0 *lambda.UntagResourceInput) (*request.Request, *lambda.UntagResourceOutput)
{ ret := m.ctrl.Call(m, "UntagResourceRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.UntagResourceOutput) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1241-L1246
go
train
// UpdateAlias mocks base method
func (m *MockLambdaAPI) UpdateAlias(arg0 *lambda.UpdateAliasInput) (*lambda.AliasConfiguration, error)
// UpdateAlias mocks base method func (m *MockLambdaAPI) UpdateAlias(arg0 *lambda.UpdateAliasInput) (*lambda.AliasConfiguration, error)
{ ret := m.ctrl.Call(m, "UpdateAlias", arg0) ret0, _ := ret[0].(*lambda.AliasConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1254-L1259
go
train
// UpdateAliasRequest mocks base method
func (m *MockLambdaAPI) UpdateAliasRequest(arg0 *lambda.UpdateAliasInput) (*request.Request, *lambda.AliasConfiguration)
// UpdateAliasRequest mocks base method func (m *MockLambdaAPI) UpdateAliasRequest(arg0 *lambda.UpdateAliasInput) (*request.Request, *lambda.AliasConfiguration)
{ ret := m.ctrl.Call(m, "UpdateAliasRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.AliasConfiguration) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1285-L1290
go
train
// UpdateEventSourceMapping mocks base method
func (m *MockLambdaAPI) UpdateEventSourceMapping(arg0 *lambda.UpdateEventSourceMappingInput) (*lambda.EventSourceMappingConfiguration, error)
// UpdateEventSourceMapping mocks base method func (m *MockLambdaAPI) UpdateEventSourceMapping(arg0 *lambda.UpdateEventSourceMappingInput) (*lambda.EventSourceMappingConfiguration, error)
{ ret := m.ctrl.Call(m, "UpdateEventSourceMapping", arg0) ret0, _ := ret[0].(*lambda.EventSourceMappingConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1298-L1303
go
train
// UpdateEventSourceMappingRequest mocks base method
func (m *MockLambdaAPI) UpdateEventSourceMappingRequest(arg0 *lambda.UpdateEventSourceMappingInput) (*request.Request, *lambda.EventSourceMappingConfiguration)
// UpdateEventSourceMappingRequest mocks base method func (m *MockLambdaAPI) UpdateEventSourceMappingRequest(arg0 *lambda.UpdateEventSourceMappingInput) (*request.Request, *lambda.EventSourceMappingConfiguration)
{ ret := m.ctrl.Call(m, "UpdateEventSourceMappingRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.EventSourceMappingConfiguration) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1311-L1320
go
train
// UpdateEventSourceMappingWithContext mocks base method
func (m *MockLambdaAPI) UpdateEventSourceMappingWithContext(arg0 aws.Context, arg1 *lambda.UpdateEventSourceMappingInput, arg2 ...request.Option) (*lambda.EventSourceMappingConfiguration, error)
// UpdateEventSourceMappingWithContext mocks base method func (m *MockLambdaAPI) UpdateEventSourceMappingWithContext(arg0 aws.Context, arg1 *lambda.UpdateEventSourceMappingInput, arg2 ...request.Option) (*lambda.EventSourceMappingConfiguration, error)
{ varargs := []interface{}{arg0, arg1} for _, a := range arg2 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "UpdateEventSourceMappingWithContext", varargs...) ret0, _ := ret[0].(*lambda.EventSourceMappingConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1329-L1334
go
train
// UpdateFunctionCode mocks base method
func (m *MockLambdaAPI) UpdateFunctionCode(arg0 *lambda.UpdateFunctionCodeInput) (*lambda.FunctionConfiguration, error)
// UpdateFunctionCode mocks base method func (m *MockLambdaAPI) UpdateFunctionCode(arg0 *lambda.UpdateFunctionCodeInput) (*lambda.FunctionConfiguration, error)
{ ret := m.ctrl.Call(m, "UpdateFunctionCode", arg0) ret0, _ := ret[0].(*lambda.FunctionConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1342-L1347
go
train
// UpdateFunctionCodeRequest mocks base method
func (m *MockLambdaAPI) UpdateFunctionCodeRequest(arg0 *lambda.UpdateFunctionCodeInput) (*request.Request, *lambda.FunctionConfiguration)
// UpdateFunctionCodeRequest mocks base method func (m *MockLambdaAPI) UpdateFunctionCodeRequest(arg0 *lambda.UpdateFunctionCodeInput) (*request.Request, *lambda.FunctionConfiguration)
{ ret := m.ctrl.Call(m, "UpdateFunctionCodeRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.FunctionConfiguration) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1373-L1378
go
train
// UpdateFunctionConfiguration mocks base method
func (m *MockLambdaAPI) UpdateFunctionConfiguration(arg0 *lambda.UpdateFunctionConfigurationInput) (*lambda.FunctionConfiguration, error)
// UpdateFunctionConfiguration mocks base method func (m *MockLambdaAPI) UpdateFunctionConfiguration(arg0 *lambda.UpdateFunctionConfigurationInput) (*lambda.FunctionConfiguration, error)
{ ret := m.ctrl.Call(m, "UpdateFunctionConfiguration", arg0) ret0, _ := ret[0].(*lambda.FunctionConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
mock/lambdaiface.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/mock/lambdaiface.go#L1386-L1391
go
train
// UpdateFunctionConfigurationRequest mocks base method
func (m *MockLambdaAPI) UpdateFunctionConfigurationRequest(arg0 *lambda.UpdateFunctionConfigurationInput) (*request.Request, *lambda.FunctionConfiguration)
// UpdateFunctionConfigurationRequest mocks base method func (m *MockLambdaAPI) UpdateFunctionConfigurationRequest(arg0 *lambda.UpdateFunctionConfigurationInput) (*request.Request, *lambda.FunctionConfiguration)
{ ret := m.ctrl.Call(m, "UpdateFunctionConfigurationRequest", arg0) ret0, _ := ret[0].(*request.Request) ret1, _ := ret[1].(*lambda.FunctionConfiguration) return ret0, ret1 }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
upgrade/upgrade.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/upgrade/upgrade.go#L17-L66
go
train
// Upgrade the current `version` of apex to the latest.
func Upgrade(version string) error
// Upgrade the current `version` of apex to the latest. func Upgrade(version string) error
{ term.HideCursor() defer term.ShowCursor() p := &update.Manager{ Command: "apex", Store: &github.Store{ Owner: "apex", Repo: "apex", Version: version, }, } // fetch releases releases, err := p.LatestReleases() if err != nil { return errors.Wrap(err, "fetching latest release") } // no updates if len(releases) == 0 { util.LogPad("No updates available, you're good :)") return nil } // latest r := releases[0] // find the tarball for this system a := r.FindTarball(runtime.GOOS, runtime.GOARCH) if a == nil { return errors.Errorf("failed to find a binary for %s %s", runtime.GOOS, runtime.GOARCH) } // download tarball to a tmp dir tarball, err := a.DownloadProxy(progressreader.New) if err != nil { return errors.Wrap(err, "downloading tarball") } // install it if err := p.Install(tarball); err != nil { return errors.Wrap(err, "installing") } term.ClearAll() util.LogPad("Updated %s to %s", version, r.Version) return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L82-L98
go
train
// Boot the project.
func (b *Bootstrapper) Boot() error
// Boot the project. func (b *Bootstrapper) Boot() error
{ fmt.Println(logo) if b.isProject() { help("I've detected a ./project.json file, this seems to already be a project!") return nil } help("Enter the name of your project. It should be machine-friendly, as this\nis used to prefix your functions in Lambda.") b.name = prompt.StringRequired(indent(" Project name: ")) help("Enter an optional description of your project.") b.description = prompt.String(indent(" Project description: ")) fmt.Println() return b.bootVanilla() }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L101-L104
go
train
// check if there's a project.
func (b *Bootstrapper) isProject() bool
// check if there's a project. func (b *Bootstrapper) isProject() bool
{ _, err := os.Stat("project.json") return err == nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L107-L119
go
train
// Bootstrap without Terraform.
func (b *Bootstrapper) bootVanilla() error
// Bootstrap without Terraform. func (b *Bootstrapper) bootVanilla() error
{ iamRole, err := b.createRole() if err != nil { return err } if err := b.initProjectFiles(iamRole); err != nil { return err } fmt.Println(setupCompleteVanilla) return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L122-L158
go
train
// Create IAM role, returning the ARN.
func (b *Bootstrapper) createRole() (string, error)
// Create IAM role, returning the ARN. func (b *Bootstrapper) createRole() (string, error)
{ roleName := fmt.Sprintf("%s_lambda_function", b.name) policyName := fmt.Sprintf("%s_lambda_logs", b.name) logf("creating IAM %s role", roleName) role, err := b.IAM.CreateRole(&iam.CreateRoleInput{ RoleName: &roleName, AssumeRolePolicyDocument: aws.String(iamAssumeRolePolicy), }) if err != nil { return "", fmt.Errorf("creating role: %s", err) } logf("creating IAM %s policy", policyName) policy, err := b.IAM.CreatePolicy(&iam.CreatePolicyInput{ PolicyName: &policyName, Description: aws.String("Allow lambda_function to utilize CloudWatchLogs. Created by apex(1)."), PolicyDocument: aws.String(iamLogsPolicy), }) if err != nil { return "", fmt.Errorf("creating policy: %s", err) } logf("attaching policy to lambda_function role.") _, err = b.IAM.AttachRolePolicy(&iam.AttachRolePolicyInput{ RoleName: &roleName, PolicyArn: policy.Policy.Arn, }) if err != nil { return "", fmt.Errorf("creating policy: %s", err) } return *role.Role.Arn, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L161-L172
go
train
// Initialize project files such as project.json and ./functions.
func (b *Bootstrapper) initProjectFiles(iamRole string) error
// Initialize project files such as project.json and ./functions. func (b *Bootstrapper) initProjectFiles(iamRole string) error
{ logf("creating ./project.json") project := fmt.Sprintf(projectConfig, b.name, b.description, iamRole) if err := ioutil.WriteFile("project.json", []byte(project), 0644); err != nil { return err } logf("creating ./functions") return boilerplate.RestoreAssets(".", "functions") }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L175-L179
go
train
// help string output.
func help(s string)
// help string output. func help(s string)
{ os.Stdout.WriteString("\n") os.Stdout.WriteString(indent(s)) os.Stdout.WriteString("\n\n") }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L182-L188
go
train
// indent multiline string with 2 spaces.
func indent(s string) (out string)
// indent multiline string with 2 spaces. func indent(s string) (out string)
{ for _, l := range strings.SplitAfter(s, "\n") { out += fmt.Sprintf(" %s", l) } return }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
boot/boot.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/boot/boot.go#L191-L193
go
train
// logf outputs a log message.
func logf(s string, v ...interface{})
// logf outputs a log message. func logf(s string, v ...interface{})
{ fmt.Printf(" \033[34m[+]\033[0m %s\n", fmt.Sprintf(s, v...)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
logs/logs.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/logs/logs.go#L34-L48
go
train
// Start consuming logs.
func (l *Logs) Start() <-chan *Event
// Start consuming logs. func (l *Logs) Start() <-chan *Event
{ ch := make(chan *Event) done := make(chan error) for _, name := range l.GroupNames { go l.consume(name, ch, done) } go func() { l.wait(done) close(ch) }() return ch }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
logs/logs.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/logs/logs.go#L56-L63
go
train
// wait for each log group to complete.
func (l *Logs) wait(done <-chan error)
// wait for each log group to complete. func (l *Logs) wait(done <-chan error)
{ for range l.GroupNames { if err := <-done; err != nil { l.err = err return } } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
logs/logs.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/logs/logs.go#L66-L78
go
train
// consume logs for group `name`.
func (l *Logs) consume(name string, ch chan *Event, done chan error)
// consume logs for group `name`. func (l *Logs) consume(name string, ch chan *Event, done chan error)
{ log := Log{ Config: l.Config, GroupName: name, Log: log.WithField("group", name), } for event := range log.Start() { ch <- event } done <- log.Err() }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
cmd/apex/metrics/metrics.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/metrics/metrics.go#L42-L47
go
train
// Initialize.
func init()
// Initialize. func init()
{ root.Register(Command) f := Command.Flags() f.DurationVarP(&duration, "since", "s", 24*time.Hour, "Start time of the results") }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
cmd/apex/metrics/metrics.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/metrics/metrics.go#L50-L98
go
train
// Run command.
func run(c *cobra.Command, args []string) error
// Run command. func run(c *cobra.Command, args []string) error
{ if err := root.Project.LoadFunctions(args...); err != nil { return err } service := lambda.New(root.Session) config := metrics.Config{ Service: cloudwatch.New(root.Session), StartDate: time.Now().UTC().Add(-duration), EndDate: time.Now().UTC(), } m := metrics.Metrics{ Config: config, } for _, fn := range root.Project.Functions { m.FunctionNames = append(m.FunctionNames, fn.FunctionName) } aggregated := m.Collect() fmt.Println() for _, fn := range root.Project.Functions { m := aggregated[fn.FunctionName] conf, err := service.GetFunctionConfiguration(&lambda.GetFunctionConfigurationInput{FunctionName: &fn.FunctionName}) if err != nil { return err } memory := int(*conf.MemorySize) costTotal := humanize.FormatFloat("", cost.Cost(m.Invocations, m.Duration, memory)) costDuration := humanize.FormatFloat("", cost.DurationCost(m.Duration, memory)) costInvocations := humanize.FormatFloat("", cost.RequestCost(m.Invocations)) fmt.Printf(" \033[%dm%s\033[0m\n", colors.Blue, fn.Name) fmt.Printf(" total cost: $%s\n", costTotal) fmt.Printf(" invocations: %s ($%s)\n", humanize.Comma(int64(m.Invocations)), costInvocations) fmt.Printf(" duration: %s ($%s)\n", time.Millisecond*time.Duration(m.Duration), costDuration) fmt.Printf(" throttles: %v\n", m.Throttles) fmt.Printf(" errors: %s\n", humanize.Comma(int64(m.Errors))) fmt.Printf(" memory: %d\n", memory) fmt.Println() } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
cmd/apex/root/root.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/root/root.go#L64-L75
go
train
// Initialize.
func init()
// Initialize. func init()
{ f := Command.PersistentFlags() f.StringVarP(&environment, "env", "e", "", "Environment name") f.StringVarP(&chdir, "chdir", "C", "", "Working directory") f.BoolVarP(&dryRun, "dry-run", "D", false, "Perform a dry-run") f.StringVarP(&logLevel, "log-level", "l", "info", "Log severity level") f.StringVarP(&profile, "profile", "p", "", "AWS profile") f.StringVarP(&iamrole, "iamrole", "i", "", "AWS iamrole") f.StringVarP(&region, "region", "r", "", "AWS region") f.StringVar(&endpoint, "endpoint", "", "AWS endpoint") }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
cmd/apex/root/root.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/root/root.go#L84-L91
go
train
// preRun sets up global tasks used for most commands, some use PreRunNoop // to remove this default behaviour.
func preRun(c *cobra.Command, args []string) error
// preRun sets up global tasks used for most commands, some use PreRunNoop // to remove this default behaviour. func preRun(c *cobra.Command, args []string) error
{ err := Prepare(c, args) if err != nil { return err } return Project.Open() }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
cmd/apex/root/root.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/root/root.go#L102-L186
go
train
// Prepare handles the global CLI flags and shared functionality without // the assumption that a Project has already been initialized. // // Precedence is currently: // // - flags such as --profile // - env vars such as AWS_PROFILE // - files such as ~/.aws/config //
func Prepare(c *cobra.Command, args []string) error
// Prepare handles the global CLI flags and shared functionality without // the assumption that a Project has already been initialized. // // Precedence is currently: // // - flags such as --profile // - env vars such as AWS_PROFILE // - files such as ~/.aws/config // func Prepare(c *cobra.Command, args []string) error
{ if l, err := log.ParseLevel(logLevel); err == nil { log.SetLevel(l) } // config defaults Config = aws.NewConfig() if chdir != "" { if err := os.Chdir(chdir); err != nil { return err } } configProfile, configRegion, _ := utils.ProfileAndRegionFromConfig(environment) // profile from flag, config, env, "default" if profile == "" { profile = configProfile if profile == "" { profile = os.Getenv("AWS_PROFILE") if profile == "" { profile = "default" } } } // the default SharedCredentialsProvider checks the env os.Setenv("AWS_PROFILE", profile) // region from flag, config, env, file if region == "" { region = configRegion if region == "" { region = os.Getenv("AWS_REGION") if region == "" { region, _ = utils.GetRegion(profile) } } } if region != "" { Config = Config.WithRegion(region) } // environment from flag or env if environment == "" { environment = os.Getenv("APEX_ENVIRONMENT") } // iamrole from flag, env if iamrole == "" { iamrole = os.Getenv("AWS_ROLE") } if iamrole != "" { config, err := utils.AssumeRole(iamrole, Config) if err != nil { return errors.Wrap(err, "assuming role") } Config = config } // endpoint from flag if endpoint != "" { Config = Config.WithEndpoint(endpoint) } Session = session.New(Config) Project = &project.Project{ Environment: environment, InfraEnvironment: environment, Log: log.Log, Path: ".", } if dryRun { log.SetLevel(log.WarnLevel) Project.Concurrency = 1 } Project.ServiceProvider = service.NewProvider(Session, dryRun) return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L24-L28
go
train
// Sha256 returns a base64 encoded SHA256 hash of `b`.
func Sha256(b []byte) string
// Sha256 returns a base64 encoded SHA256 hash of `b`. func Sha256(b []byte) string
{ h := sha256.New() h.Write(b) return base64.StdEncoding.EncodeToString(h.Sum(nil)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L32-L65
go
train
// LoadFiles return filtered map of relative to 'root' file paths; // for filtering it uses shell file name pattern matching
func LoadFiles(root string, ignoreFile []byte) (files []string, err error)
// LoadFiles return filtered map of relative to 'root' file paths; // for filtering it uses shell file name pattern matching func LoadFiles(root string, ignoreFile []byte) (files []string, err error)
{ err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } mode := info.Mode() if !(mode.IsDir() || mode.IsRegular() || mode&os.ModeSymlink == os.ModeSymlink) { return nil } rel, err := filepath.Rel(root, path) if err != nil { return err } matched, err := gitignorer.GitIgnore(bytes.NewReader(ignoreFile), rel) if err != nil { return err } if mode.IsDir() && matched { return filepath.SkipDir } else if mode.IsDir() || matched { return nil } files = append(files, rel) return nil }) return }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L68-L91
go
train
// GetRegion attempts loading the AWS region from ~/.aws/config.
func GetRegion(profile string) (string, error)
// GetRegion attempts loading the AWS region from ~/.aws/config. func GetRegion(profile string) (string, error)
{ home, err := homedir.Dir() if err != nil { return "", err } path := filepath.Join(home, ".aws", "config") cfg, err := goconfig.LoadConfigFile(path) if err != nil { return "", err } sectionName := "default" if profile != "" && profile != "default" { sectionName = fmt.Sprintf("profile %s", profile) } section, err := cfg.GetSection(sectionName) if err != nil { return "", fmt.Errorf("Could not find AWS region in %s", path) } return section["region"], nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L94-L108
go
train
// ReadIgnoreFile reads .apexignore in `dir` when present and returns a list of patterns.
func ReadIgnoreFile(dir string) ([]byte, error)
// ReadIgnoreFile reads .apexignore in `dir` when present and returns a list of patterns. func ReadIgnoreFile(dir string) ([]byte, error)
{ path := filepath.Join(dir, ".apexignore") b, err := ioutil.ReadFile(path) if os.IsNotExist(err) { return nil, nil } if err != nil { return nil, err } return b, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L111-L118
go
train
// ContainsString checks if array contains string
func ContainsString(array []string, element string) bool
// ContainsString checks if array contains string func ContainsString(array []string, element string) bool
{ for _, e := range array { if element == e { return true } } return false }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L121-L134
go
train
// ParseEnv accepts an `env` slice from the command-line and returns a map.
func ParseEnv(env []string) (map[string]string, error)
// ParseEnv accepts an `env` slice from the command-line and returns a map. func ParseEnv(env []string) (map[string]string, error)
{ m := make(map[string]string) for _, s := range env { parts := strings.SplitN(s, "=", 2) if len(parts) == 2 { m[parts[0]] = parts[1] } else { return nil, fmt.Errorf("environment variable %q is missing a value", parts[0]) } } return m, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L137-L160
go
train
// ProfileAndRegionFromConfig attempts to load the .profile setting from `environment`'s config.
func ProfileAndRegionFromConfig(environment string) (string, string, error)
// ProfileAndRegionFromConfig attempts to load the .profile setting from `environment`'s config. func ProfileAndRegionFromConfig(environment string) (string, string, error)
{ configFile := "project.json" if environment != "" { configFile = fmt.Sprintf("project.%s.json", environment) } f, err := os.Open(configFile) if err != nil { return "", "", err } defer f.Close() var v struct { Profile string `json:"profile"` Region string `json:"region"` } if err := json.NewDecoder(f).Decode(&v); err != nil { return "", "", err } return v.Profile, v.Region, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
utils/utils.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/utils/utils.go#L163-L185
go
train
// AssumeRole uses STS to assume the given `role`.
func AssumeRole(role string, config *aws.Config) (*aws.Config, error)
// AssumeRole uses STS to assume the given `role`. func AssumeRole(role string, config *aws.Config) (*aws.Config, error)
{ stscreds := sts.New(session.New(config)) params := &sts.AssumeRoleInput{ RoleArn: &role, RoleSessionName: aws.String("apex"), DurationSeconds: aws.Int64(1800), } res, err := stscreds.AssumeRole(params) if err != nil { return nil, err } id := *res.Credentials.AccessKeyId secret := *res.Credentials.SecretAccessKey token := *res.Credentials.SessionToken return &aws.Config{ Region: config.Region, Credentials: credentials.NewStaticCredentials(id, secret, token), }, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L77-L97
go
train
// defaults applies configuration defaults.
func (p *Project) defaults()
// defaults applies configuration defaults. func (p *Project) defaults()
{ p.Memory = DefaultMemory p.Timeout = DefaultTimeout p.IgnoreFile = []byte(".apexignore\nfunction.json\n") if p.Concurrency == 0 { p.Concurrency = 5 } if p.Config.Environment == nil { p.Config.Environment = make(map[string]string) } if p.NameTemplate == "" { p.NameTemplate = "{{.Project.Name}}_{{.Function.Name}}" } if p.RetainedVersions == nil { p.RetainedVersions = aws.Int(DefaultRetainedVersions) } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L100-L142
go
train
// Open the project.json file and prime the config.
func (p *Project) Open() error
// Open the project.json file and prime the config. func (p *Project) Open() error
{ p.defaults() configFile := "project.json" if p.Environment != "" { configFile = fmt.Sprintf("project.%s.json", p.Environment) } f, err := os.Open(filepath.Join(p.Path, configFile)) if err != nil { return err } if err := json.NewDecoder(f).Decode(&p.Config); err != nil { return err } if p.InfraEnvironment == "" { p.InfraEnvironment = p.Config.DefaultEnvironment } if p.Role == "" { p.Role = p.readInfraRole() } if err := validator.Validate(&p.Config); err != nil { return err } t, err := template.New("nameTemplate").Parse(p.NameTemplate) if err != nil { return err } p.nameTemplate = t ignoreFile, err := utils.ReadIgnoreFile(p.Path) if err != nil { return err } p.IgnoreFile = append(p.IgnoreFile, ignoreFile...) return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L146-L178
go
train
// LoadFunctions reads the ./functions directory, populating the Functions field. // If no `patterns` are specified, all functions are loaded.
func (p *Project) LoadFunctions(patterns ...string) error
// LoadFunctions reads the ./functions directory, populating the Functions field. // If no `patterns` are specified, all functions are loaded. func (p *Project) LoadFunctions(patterns ...string) error
{ dir := filepath.Join(p.Path, functionsDir) p.Log.Debugf("loading functions in %s", dir) names, err := p.FunctionDirNames() if err != nil { return err } for _, name := range names { match, err := matches(name, patterns) if err != nil { return errors.Wrapf(err, "matching %s", name) } if !match { continue } fn, err := p.LoadFunction(name) if err != nil { return errors.Wrapf(err, "loading %s", name) } p.Functions = append(p.Functions, fn) } if len(p.Functions) == 0 { return errors.New("no function loaded") } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L181-L187
go
train
// DeployAndClean deploys functions and then cleans up their build artifacts.
func (p *Project) DeployAndClean() error
// DeployAndClean deploys functions and then cleans up their build artifacts. func (p *Project) DeployAndClean() error
{ if err := p.Deploy(); err != nil { return err } return p.Clean() }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L190-L224
go
train
// Deploy functions and their configurations.
func (p *Project) Deploy() error
// Deploy functions and their configurations. func (p *Project) Deploy() error
{ p.Log.Debugf("deploying %d functions", len(p.Functions)) sem := make(semaphore.Semaphore, p.Concurrency) errs := make(chan error) go func() { for _, fn := range p.Functions { fn := fn sem.Acquire() go func() { defer sem.Release() err := fn.Deploy() if err != nil { err = fmt.Errorf("function %s: %s", fn.Name, err) } errs <- err }() } sem.Wait() close(errs) }() for err := range errs { if err != nil { return err } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L227-L237
go
train
// Clean up function build artifacts.
func (p *Project) Clean() error
// Clean up function build artifacts. func (p *Project) Clean() error
{ p.Log.Debugf("cleaning %d functions", len(p.Functions)) for _, fn := range p.Functions { if err := fn.Clean(); err != nil { return fmt.Errorf("function %s: %s", fn.Name, err) } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L240-L258
go
train
// Delete functions.
func (p *Project) Delete() error
// Delete functions. func (p *Project) Delete() error
{ p.Log.Debugf("deleting %d functions", len(p.Functions)) for _, fn := range p.Functions { if _, err := fn.GetConfig(); err != nil { if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" { p.Log.Infof("function %q hasn't been deployed yet or has been deleted manually on AWS Lambda", fn.Name) continue } return fmt.Errorf("function %s: %s", fn.Name, err) } if err := fn.Delete(); err != nil { return fmt.Errorf("function %s: %s", fn.Name, err) } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L274-L284
go
train
// RollbackVersion project functions to the specified version.
func (p *Project) RollbackVersion(version string) error
// RollbackVersion project functions to the specified version. func (p *Project) RollbackVersion(version string) error
{ p.Log.Debugf("rolling back %d functions to version %s", len(p.Functions), version) for _, fn := range p.Functions { if err := fn.RollbackVersion(version); err != nil { return fmt.Errorf("function %s: %s", fn.Name, err) } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L287-L302
go
train
// FunctionDirNames returns a list of function directory names.
func (p *Project) FunctionDirNames() (list []string, err error)
// FunctionDirNames returns a list of function directory names. func (p *Project) FunctionDirNames() (list []string, err error)
{ dir := filepath.Join(p.Path, functionsDir) files, err := ioutil.ReadDir(dir) if err != nil { return nil, err } for _, file := range files { if file.IsDir() { list = append(list, file.Name()) } } return list, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L305-L324
go
train
// LoadEnvFromFile reads `path` JSON and applies it to the environment.
func (p *Project) LoadEnvFromFile(path string) error
// LoadEnvFromFile reads `path` JSON and applies it to the environment. func (p *Project) LoadEnvFromFile(path string) error
{ p.Log.Debugf("load env from file %q", path) var env map[string]string f, err := os.Open(path) if err != nil { return err } defer f.Close() if err := json.NewDecoder(f).Decode(&env); err != nil { return err } for k, v := range env { p.Setenv(k, v) } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L327-L331
go
train
// Setenv sets environment variable `name` to `value` on every function in project.
func (p *Project) Setenv(name, value string)
// Setenv sets environment variable `name` to `value` on every function in project. func (p *Project) Setenv(name, value string)
{ for _, fn := range p.Functions { fn.Setenv(name, value) } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L334-L336
go
train
// LoadFunction returns the function in the ./functions/<name> directory.
func (p *Project) LoadFunction(name string) (*function.Function, error)
// LoadFunction returns the function in the ./functions/<name> directory. func (p *Project) LoadFunction(name string) (*function.Function, error)
{ return p.LoadFunctionByPath(name, filepath.Join(p.Path, functionsDir, name)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L339-L374
go
train
// LoadFunctionByPath returns the function in the given directory.
func (p *Project) LoadFunctionByPath(name, path string) (*function.Function, error)
// LoadFunctionByPath returns the function in the given directory. func (p *Project) LoadFunctionByPath(name, path string) (*function.Function, error)
{ fn := &function.Function{ Config: function.Config{ Runtime: p.Runtime, Memory: p.Memory, Timeout: p.Timeout, Role: p.Role, Handler: p.Handler, Shim: p.Shim, Hooks: p.Hooks, Environment: copyStringMap(p.Config.Environment), RetainedVersions: p.RetainedVersions, VPC: copyVPC(p.VPC), Zip: p.Zip, }, Name: name, Path: path, Log: p.Log, IgnoreFile: p.IgnoreFile, Alias: p.Alias, } if name, err := p.name(fn); err == nil { fn.FunctionName = name } else { return nil, err } if err := fn.Open(p.Environment); err != nil { return nil, err } fn.Service = p.ServiceProvider.NewService(fn.AWSConfig()) return fn, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L377-L416
go
train
// CreateOrUpdateAlias ensures the given `alias` is available for `version`.
func (p *Project) CreateOrUpdateAlias(alias, version string) error
// CreateOrUpdateAlias ensures the given `alias` is available for `version`. func (p *Project) CreateOrUpdateAlias(alias, version string) error
{ p.Log.Debugf("updating %d functions", len(p.Functions)) sem := make(semaphore.Semaphore, p.Concurrency) errs := make(chan error) go func() { for _, fn := range p.Functions { fn := fn sem.Acquire() go func() { defer sem.Release() version, err := fn.GetVersionFromAlias(version) if err != nil { err = fmt.Errorf("function %s: %s", fn.Name, err) } err = fn.CreateOrUpdateAlias(alias, version) if err != nil { err = fmt.Errorf("function %s: %s", fn.Name, err) } errs <- err }() } sem.Wait() close(errs) }() for err := range errs { if err != nil { return err } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L419-L434
go
train
// name returns the computed name for `fn`, using the nameTemplate.
func (p *Project) name(fn *function.Function) (string, error)
// name returns the computed name for `fn`, using the nameTemplate. func (p *Project) name(fn *function.Function) (string, error)
{ data := struct { Project *Project Function *function.Function }{ Project: p, Function: fn, } name, err := render(p.nameTemplate, data) if err != nil { return "", err } return name, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L437-L445
go
train
// readInfraRole reads lambda function IAM role from infrastructure
func (p *Project) readInfraRole() string
// readInfraRole reads lambda function IAM role from infrastructure func (p *Project) readInfraRole() string
{ role, err := infra.Output(p.InfraEnvironment, "lambda_function_role_id") if err != nil { p.Log.Debugf("couldn't read role from infrastructure: %s", err) return "" } return role }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L448-L456
go
train
// render returns a string by executing template `t` against the given value `v`.
func render(t *template.Template, v interface{}) (string, error)
// render returns a string by executing template `t` against the given value `v`. func render(t *template.Template, v interface{}) (string, error)
{ buf := new(bytes.Buffer) if err := t.Execute(buf, v); err != nil { return "", err } return buf.String(), nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L468-L478
go
train
// copyVPC returns a copy of `in`.
func copyVPC(in vpc.VPC) vpc.VPC
// copyVPC returns a copy of `in`. func copyVPC(in vpc.VPC) vpc.VPC
{ securityGroups := make([]string, len(in.SecurityGroups)) copy(securityGroups, in.SecurityGroups) subnets := make([]string, len(in.Subnets)) copy(subnets, in.Subnets) return vpc.VPC{ SecurityGroups: securityGroups, Subnets: subnets, } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
project/project.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/project/project.go#L482-L499
go
train
// matches returns true if `name` is matched by any of the given `patterns`, // or if zero `patterns` are provided.
func matches(name string, patterns []string) (bool, error)
// matches returns true if `name` is matched by any of the given `patterns`, // or if zero `patterns` are provided. func matches(name string, patterns []string) (bool, error)
{ if len(patterns) == 0 { return true, nil } for _, pattern := range patterns { match, err := filepath.Match(pattern, name) if err != nil { return false, err } if match { return true, nil } } return false, nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/progressreader/progressreader.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/progressreader/progressreader.go#L24-L31
go
train
// Read implementation.
func (r *reader) Read(b []byte) (int, error)
// Read implementation. func (r *reader) Read(b []byte) (int, error)
{ r.Do(term.ClearAll) n, err := r.ReadCloser.Read(b) r.written += n r.p.ValueInt(r.written) r.render(term.CenterLine(r.p.String())) return n, err }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/progressreader/progressreader.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/progressreader/progressreader.go#L34-L40
go
train
// New returns a progress bar reader.
func New(size int, r io.ReadCloser) io.ReadCloser
// New returns a progress bar reader. func New(size int, r io.ReadCloser) io.ReadCloser
{ return &reader{ ReadCloser: r, p: util.NewProgressInt(size), render: term.Renderer(), } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L21-L38
go
train
// Collect and aggregate metrics for on function.
func (m *Metric) Collect() (a AggregatedMetrics)
// Collect and aggregate metrics for on function. func (m *Metric) Collect() (a AggregatedMetrics)
{ for n := range m.collect(m.gen()) { value := aggregate(n.Value) switch n.Name { case "Duration": a.Duration = value case "Errors": a.Errors = value case "Invocations": a.Invocations = value case "Throttles": a.Throttles = value } } return }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L47-L65
go
train
// stats for function `name`.
func (m *Metric) stats(name string) (*cloudwatch.GetMetricStatisticsOutput, error)
// stats for function `name`. func (m *Metric) stats(name string) (*cloudwatch.GetMetricStatisticsOutput, error)
{ return m.Service.GetMetricStatistics(&cloudwatch.GetMetricStatisticsInput{ StartTime: &m.StartDate, EndTime: &m.EndDate, MetricName: &name, Namespace: aws.String("AWS/Lambda"), Period: aws.Int64(int64(period(m.StartDate, m.EndDate).Seconds())), Statistics: []*string{ aws.String("Sum"), }, Dimensions: []*cloudwatch.Dimension{ { Name: aws.String("FunctionName"), Value: &m.FunctionName, }, }, Unit: aws.String(unit(name)), }) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L68-L99
go
train
// collect starts a new cloudwatch session and requests the key metrics.
func (m *Metric) collect(in <-chan string) <-chan cloudWatchMetric
// collect starts a new cloudwatch session and requests the key metrics. func (m *Metric) collect(in <-chan string) <-chan cloudWatchMetric
{ var wg sync.WaitGroup out := make(chan cloudWatchMetric) for name := range in { wg.Add(1) name := name go func() { defer wg.Done() res, err := m.stats(name) if err != nil { // TODO: refactor so that errors are reported in cmd fmt.Println(err.Error()) return } out <- cloudWatchMetric{ Name: name, Value: res.Datapoints, } }() } go func() { wg.Wait() close(out) }() return out }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L102-L109
go
train
// gen generates the key metric structs and returns a channel pipeline.
func (m *Metric) gen() <-chan string
// gen generates the key metric structs and returns a channel pipeline. func (m *Metric) gen() <-chan string
{ out := make(chan string, len(metricsNames)) for _, n := range metricsNames { out <- n } close(out) return out }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L112-L119
go
train
// period returns the resolution of metrics.
func period(start, end time.Time) time.Duration
// period returns the resolution of metrics. func period(start, end time.Time) time.Duration
{ switch n := end.Sub(start).Hours(); { case n > 24: return time.Hour * 24 default: return time.Hour } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
metrics/metric.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L132-L140
go
train
// aggregate accumulates the datapoints.
func aggregate(datapoints []*cloudwatch.Datapoint) int
// aggregate accumulates the datapoints. func aggregate(datapoints []*cloudwatch.Datapoint) int
{ sum := 0.0 for _, datapoint := range datapoints { sum += *datapoint.Sum } return int(sum) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
plugins/hooks/hooks.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L28-L30
go
train
// Error string.
func (e *HookError) Error() string
// Error string. func (e *HookError) Error() string
{ return fmt.Sprintf("%s hook: %s", e.Hook, e.Output) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
plugins/hooks/hooks.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L36-L38
go
train
// Build runs the "build" hook commands.
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error
// Build runs the "build" hook commands. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error
{ return p.run("build", fn.Hooks.Build, fn) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
plugins/hooks/hooks.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L46-L48
go
train
// Deploy runs the "deploy" hook commands.
func (p *Plugin) Deploy(fn *function.Function) error
// Deploy runs the "deploy" hook commands. func (p *Plugin) Deploy(fn *function.Function) error
{ return p.run("deploy", fn.Hooks.Deploy, fn) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
plugins/hooks/hooks.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L51-L80
go
train
// run a hook command.
func (p *Plugin) run(hook, command string, fn *function.Function) error
// run a hook command. func (p *Plugin) run(hook, command string, fn *function.Function) error
{ if command == "" { return nil } fn.Log.WithFields(log.Fields{ "hook": hook, "command": command, }).Debug("hook") var cmd *exec.Cmd if runtime.GOOS == "windows" { cmd = exec.Command("cmd", "/c", command) } else { cmd = exec.Command("sh", "-c", command) } cmd.Env = os.Environ() cmd.Dir = fn.Path b, err := cmd.CombinedOutput() if err != nil { return &HookError{ Hook: hook, Command: command, Output: string(b), } } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L38-L46
go
train
// ClearHeader removes all header fields.
func ClearHeader(h http.Header)
// ClearHeader removes all header fields. func ClearHeader(h http.Header)
{ for k := range h { if keepFields[k] { continue } h.Del(k) } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L64-L75
go
train
// ReadFileJSON reads json from the given path.
func ReadFileJSON(path string, v interface{}) error
// ReadFileJSON reads json from the given path. func ReadFileJSON(path string, v interface{}) error
{ b, err := ioutil.ReadFile(path) if err != nil { return errors.Wrap(err, "reading") } if err := json.Unmarshal(b, &v); err != nil { return errors.Wrap(err, "unmarshaling") } return nil }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L78-L80
go
train
// Camelcase string with optional args.
func Camelcase(s string, v ...interface{}) string
// Camelcase string with optional args. func Camelcase(s string, v ...interface{}) string
{ return name.CamelCase(fmt.Sprintf(s, v...), true) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L95-L104
go
train
// NewInlineProgressInt with the given total.
func NewInlineProgressInt(total int) *progress.Bar
// NewInlineProgressInt with the given total. func NewInlineProgressInt(total int) *progress.Bar
{ b := progress.NewInt(total) b.Template(`{{.Bar}} {{.Percent | printf "%0.0f"}}% {{.Text}}`) b.Width = 20 b.StartDelimiter = colors.Gray("|") b.EndDelimiter = colors.Gray("|") b.Filled = colors.Purple("█") b.Empty = colors.Gray(" ") return b }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L115-L118
go
train
// Fatal error.
func Fatal(err error)
// Fatal error. func Fatal(err error)
{ fmt.Fprintf(os.Stderr, "\n %s %s\n\n", colors.Red("Error:"), err) os.Exit(1) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L121-L123
go
train
// IsJSON returns true if the string looks like json.
func IsJSON(s string) bool
// IsJSON returns true if the string looks like json. func IsJSON(s string) bool
{ return len(s) > 1 && s[0] == '{' && s[len(s)-1] == '}' }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L131-L142
go
train
// IsNotFound returns true if err is not nil and represents a missing resource.
func IsNotFound(err error) bool
// IsNotFound returns true if err is not nil and represents a missing resource. func IsNotFound(err error) bool
{ switch { case err == nil: return false case strings.Contains(err.Error(), "does not exist"): return true case strings.Contains(err.Error(), "not found"): return true default: return false } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L157-L162
go
train
// Env returns a slice from environment variable map.
func Env(m map[string]string) (env []string)
// Env returns a slice from environment variable map. func Env(m map[string]string) (env []string)
{ for k, v := range m { env = append(env, fmt.Sprintf("%s=%s", k, v)) } return }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L165-L171
go
train
// PrefixLines prefixes the lines in s with prefix.
func PrefixLines(s string, prefix string) string
// PrefixLines prefixes the lines in s with prefix. func PrefixLines(s string, prefix string) string
{ lines := strings.Split(s, "\n") for i, l := range lines { lines[i] = prefix + l } return strings.Join(lines, "\n") }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L179-L198
go
train
// WaitForListen blocks until `u` is listening with timeout.
func WaitForListen(u *url.URL, timeout time.Duration) error
// WaitForListen blocks until `u` is listening with timeout. func WaitForListen(u *url.URL, timeout time.Duration) error
{ timedout := time.After(timeout) b := backoff.Backoff{ Min: 100 * time.Millisecond, Max: time.Second, Factor: 1.5, } for { select { case <-timedout: return errors.Errorf("timed out after %s", timeout) case <-time.After(b.Duration()): if IsListening(u) { return nil } } } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L201-L209
go
train
// IsListening returns true if there's a server listening on `u`.
func IsListening(u *url.URL) bool
// IsListening returns true if there's a server listening on `u`. func IsListening(u *url.URL) bool
{ conn, err := net.Dial("tcp", u.Host) if err != nil { return false } conn.Close() return true }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L212-L227
go
train
// ExitStatus returns the exit status of cmd.
func ExitStatus(cmd *exec.Cmd, err error) string
// ExitStatus returns the exit status of cmd. func ExitStatus(cmd *exec.Cmd, err error) string
{ ps := cmd.ProcessState if e, ok := err.(*exec.ExitError); ok { ps = e.ProcessState } if ps != nil { s, ok := ps.Sys().(syscall.WaitStatus) if ok { return fmt.Sprintf("%d", s.ExitStatus()) } } return "?" }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L252-L254
go
train
// Log outputs a log message.
func Log(msg string, v ...interface{})
// Log outputs a log message. func Log(msg string, v ...interface{})
{ fmt.Printf(" %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L257-L261
go
train
// LogClear clears the line and outputs a log message.
func LogClear(msg string, v ...interface{})
// LogClear clears the line and outputs a log message. func LogClear(msg string, v ...interface{})
{ term.MoveUp(1) term.ClearLine() fmt.Printf("\r %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L264-L266
go
train
// LogTitle outputs a log title.
func LogTitle(msg string, v ...interface{})
// LogTitle outputs a log title. func LogTitle(msg string, v ...interface{})
{ fmt.Printf("\n \x1b[1m%s\x1b[m\n\n", fmt.Sprintf(msg, v...)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L269-L271
go
train
// LogName outputs a log message with name.
func LogName(name, msg string, v ...interface{})
// LogName outputs a log message with name. func LogName(name, msg string, v ...interface{})
{ fmt.Printf(" %s %s\n", colors.Purple(name+":"), fmt.Sprintf(msg, v...)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L274-L276
go
train
// LogListItem outputs a list item.
func LogListItem(msg string, v ...interface{})
// LogListItem outputs a list item. func LogListItem(msg string, v ...interface{})
{ fmt.Printf(" • %s\n", fmt.Sprintf(msg, v...)) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L279-L308
go
train
// ToFloat returns a float or NaN.
func ToFloat(v interface{}) float64
// ToFloat returns a float or NaN. func ToFloat(v interface{}) float64
{ switch n := v.(type) { case int: return float64(n) case int8: return float64(n) case int16: return float64(n) case int32: return float64(n) case int64: return float64(n) case uint: return float64(n) case uint8: return float64(n) case uint16: return float64(n) case uint32: return float64(n) case uint64: return float64(n) case float32: return float64(n) case float64: return n default: return math.NaN() } }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L316-L318
go
train
// MillisecondsSince returns the duration as milliseconds relative to time t.
func MillisecondsSince(t time.Time) int
// MillisecondsSince returns the duration as milliseconds relative to time t. func MillisecondsSince(t time.Time) int
{ return int(time.Since(t) / time.Millisecond) }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L321-L346
go
train
// ParseDuration string with day and month approximation support.
func ParseDuration(s string) (d time.Duration, err error)
// ParseDuration string with day and month approximation support. func ParseDuration(s string) (d time.Duration, err error)
{ r := strings.NewReader(s) switch { case strings.HasSuffix(s, "d"): var v float64 _, err = fmt.Fscanf(r, "%fd", &v) d = time.Duration(v * float64(24*time.Hour)) case strings.HasSuffix(s, "w"): var v float64 _, err = fmt.Fscanf(r, "%fw", &v) d = time.Duration(v * float64(24*time.Hour*7)) case strings.HasSuffix(s, "mo"): var v float64 _, err = fmt.Fscanf(r, "%fmo", &v) d = time.Duration(v * float64(30*24*time.Hour)) case strings.HasSuffix(s, "M"): var v float64 _, err = fmt.Fscanf(r, "%fM", &v) d = time.Duration(v * float64(30*24*time.Hour)) default: d, err = time.ParseDuration(s) } return }
apex/apex
c31f0a78ce189a8328563fa6a6eb97d04ace4284
internal/util/util.go
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L358-L365
go
train
// Domain returns the effective domain. For example // the string "api.example.com" becomes "example.com", // while "api.example.co.uk" becomes "example.co.uk".
func Domain(s string) string
// Domain returns the effective domain. For example // the string "api.example.com" becomes "example.com", // while "api.example.co.uk" becomes "example.co.uk". func Domain(s string) string
{ d, err := publicsuffix.EffectiveTLDPlusOne(s) if err != nil { panic(errors.Wrap(err, "effective domain")) } return d }