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
20,100
heroku/heroku-go
v3/heroku.go
TeamAppCollaboratorList
func (s *Service) TeamAppCollaboratorList(ctx context.Context, teamAppIdentity string, lr *ListRange) (TeamAppCollaboratorListResult, error) { var teamAppCollaborator TeamAppCollaboratorListResult return teamAppCollaborator, s.Get(ctx, &teamAppCollaborator, fmt.Sprintf("/teams/apps/%v/collaborators", teamAppIdentity), nil, lr) }
go
func (s *Service) TeamAppCollaboratorList(ctx context.Context, teamAppIdentity string, lr *ListRange) (TeamAppCollaboratorListResult, error) { var teamAppCollaborator TeamAppCollaboratorListResult return teamAppCollaborator, s.Get(ctx, &teamAppCollaborator, fmt.Sprintf("/teams/apps/%v/collaborators", teamAppIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "TeamAppCollaboratorList", "(", "ctx", "context", ".", "Context", ",", "teamAppIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "TeamAppCollaboratorListResult", ",", "error", ")", "{", "var", "teamAppCollaborator", "TeamAppCollaboratorListResult", "\n", "return", "teamAppCollaborator", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamAppCollaborator", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamAppIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List collaborators on a team app.
[ "List", "collaborators", "on", "a", "team", "app", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4287-L4290
20,101
heroku/heroku-go
v3/heroku.go
TeamAppPermissionList
func (s *Service) TeamAppPermissionList(ctx context.Context, lr *ListRange) (TeamAppPermissionListResult, error) { var teamAppPermission TeamAppPermissionListResult return teamAppPermission, s.Get(ctx, &teamAppPermission, fmt.Sprintf("/teams/permissions"), nil, lr) }
go
func (s *Service) TeamAppPermissionList(ctx context.Context, lr *ListRange) (TeamAppPermissionListResult, error) { var teamAppPermission TeamAppPermissionListResult return teamAppPermission, s.Get(ctx, &teamAppPermission, fmt.Sprintf("/teams/permissions"), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "TeamAppPermissionList", "(", "ctx", "context", ".", "Context", ",", "lr", "*", "ListRange", ")", "(", "TeamAppPermissionListResult", ",", "error", ")", "{", "var", "teamAppPermission", "TeamAppPermissionListResult", "\n", "return", "teamAppPermission", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamAppPermission", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// Lists permissions available to teams.
[ "Lists", "permissions", "available", "to", "teams", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4301-L4304
20,102
heroku/heroku-go
v3/heroku.go
TeamFeatureInfo
func (s *Service) TeamFeatureInfo(ctx context.Context, teamIdentity string, teamFeatureIdentity string) (*TeamFeature, error) { var teamFeature TeamFeature return &teamFeature, s.Get(ctx, &teamFeature, fmt.Sprintf("/teams/%v/features/%v", teamIdentity, teamFeatureIdentity), nil, nil) }
go
func (s *Service) TeamFeatureInfo(ctx context.Context, teamIdentity string, teamFeatureIdentity string) (*TeamFeature, error) { var teamFeature TeamFeature return &teamFeature, s.Get(ctx, &teamFeature, fmt.Sprintf("/teams/%v/features/%v", teamIdentity, teamFeatureIdentity), nil, nil) }
[ "func", "(", "s", "*", "Service", ")", "TeamFeatureInfo", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "teamFeatureIdentity", "string", ")", "(", "*", "TeamFeature", ",", "error", ")", "{", "var", "teamFeature", "TeamFeature", "\n", "return", "&", "teamFeature", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamFeature", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ",", "teamFeatureIdentity", ")", ",", "nil", ",", "nil", ")", "\n", "}" ]
// Info for an existing team feature.
[ "Info", "for", "an", "existing", "team", "feature", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4321-L4324
20,103
heroku/heroku-go
v3/heroku.go
TeamFeatureList
func (s *Service) TeamFeatureList(ctx context.Context, teamIdentity string, lr *ListRange) (TeamFeatureListResult, error) { var teamFeature TeamFeatureListResult return teamFeature, s.Get(ctx, &teamFeature, fmt.Sprintf("/teams/%v/features", teamIdentity), nil, lr) }
go
func (s *Service) TeamFeatureList(ctx context.Context, teamIdentity string, lr *ListRange) (TeamFeatureListResult, error) { var teamFeature TeamFeatureListResult return teamFeature, s.Get(ctx, &teamFeature, fmt.Sprintf("/teams/%v/features", teamIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "TeamFeatureList", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "TeamFeatureListResult", ",", "error", ")", "{", "var", "teamFeature", "TeamFeatureListResult", "\n", "return", "teamFeature", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamFeature", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List existing team features.
[ "List", "existing", "team", "features", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4329-L4332
20,104
heroku/heroku-go
v3/heroku.go
TeamInvitationCreate
func (s *Service) TeamInvitationCreate(ctx context.Context, teamIdentity string, o TeamInvitationCreateOpts) (*TeamInvitation, error) { var teamInvitation TeamInvitation return &teamInvitation, s.Put(ctx, &teamInvitation, fmt.Sprintf("/teams/%v/invitations", teamIdentity), o) }
go
func (s *Service) TeamInvitationCreate(ctx context.Context, teamIdentity string, o TeamInvitationCreateOpts) (*TeamInvitation, error) { var teamInvitation TeamInvitation return &teamInvitation, s.Put(ctx, &teamInvitation, fmt.Sprintf("/teams/%v/invitations", teamIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "TeamInvitationCreate", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "o", "TeamInvitationCreateOpts", ")", "(", "*", "TeamInvitation", ",", "error", ")", "{", "var", "teamInvitation", "TeamInvitation", "\n", "return", "&", "teamInvitation", ",", "s", ".", "Put", "(", "ctx", ",", "&", "teamInvitation", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "o", ")", "\n", "}" ]
// Create Team Invitation
[ "Create", "Team", "Invitation" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4369-L4372
20,105
heroku/heroku-go
v3/heroku.go
TeamInvitationRevoke
func (s *Service) TeamInvitationRevoke(ctx context.Context, teamIdentity string, teamInvitationIdentity string) (*TeamInvitation, error) { var teamInvitation TeamInvitation return &teamInvitation, s.Delete(ctx, &teamInvitation, fmt.Sprintf("/teams/%v/invitations/%v", teamIdentity, teamInvitationIdentity)) }
go
func (s *Service) TeamInvitationRevoke(ctx context.Context, teamIdentity string, teamInvitationIdentity string) (*TeamInvitation, error) { var teamInvitation TeamInvitation return &teamInvitation, s.Delete(ctx, &teamInvitation, fmt.Sprintf("/teams/%v/invitations/%v", teamIdentity, teamInvitationIdentity)) }
[ "func", "(", "s", "*", "Service", ")", "TeamInvitationRevoke", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "teamInvitationIdentity", "string", ")", "(", "*", "TeamInvitation", ",", "error", ")", "{", "var", "teamInvitation", "TeamInvitation", "\n", "return", "&", "teamInvitation", ",", "s", ".", "Delete", "(", "ctx", ",", "&", "teamInvitation", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ",", "teamInvitationIdentity", ")", ")", "\n", "}" ]
// Revoke a team invitation.
[ "Revoke", "a", "team", "invitation", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4375-L4378
20,106
heroku/heroku-go
v3/heroku.go
TeamInvitationAccept
func (s *Service) TeamInvitationAccept(ctx context.Context, teamInvitationToken string) (*TeamInvitationAcceptResult, error) { var teamInvitation TeamInvitationAcceptResult return &teamInvitation, s.Post(ctx, &teamInvitation, fmt.Sprintf("/teams/invitations/%v/accept", teamInvitationToken), nil) }
go
func (s *Service) TeamInvitationAccept(ctx context.Context, teamInvitationToken string) (*TeamInvitationAcceptResult, error) { var teamInvitation TeamInvitationAcceptResult return &teamInvitation, s.Post(ctx, &teamInvitation, fmt.Sprintf("/teams/invitations/%v/accept", teamInvitationToken), nil) }
[ "func", "(", "s", "*", "Service", ")", "TeamInvitationAccept", "(", "ctx", "context", ".", "Context", ",", "teamInvitationToken", "string", ")", "(", "*", "TeamInvitationAcceptResult", ",", "error", ")", "{", "var", "teamInvitation", "TeamInvitationAcceptResult", "\n", "return", "&", "teamInvitation", ",", "s", ".", "Post", "(", "ctx", ",", "&", "teamInvitation", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamInvitationToken", ")", ",", "nil", ")", "\n", "}" ]
// Accept Team Invitation
[ "Accept", "Team", "Invitation" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4403-L4406
20,107
heroku/heroku-go
v3/heroku.go
TeamMemberCreateOrUpdate
func (s *Service) TeamMemberCreateOrUpdate(ctx context.Context, teamIdentity string, o TeamMemberCreateOrUpdateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Put(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
go
func (s *Service) TeamMemberCreateOrUpdate(ctx context.Context, teamIdentity string, o TeamMemberCreateOrUpdateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Put(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberCreateOrUpdate", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "o", "TeamMemberCreateOrUpdateOpts", ")", "(", "*", "TeamMember", ",", "error", ")", "{", "var", "teamMember", "TeamMember", "\n", "return", "&", "teamMember", ",", "s", ".", "Put", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "o", ")", "\n", "}" ]
// Create a new team member, or update their role.
[ "Create", "a", "new", "team", "member", "or", "update", "their", "role", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4466-L4469
20,108
heroku/heroku-go
v3/heroku.go
TeamMemberCreate
func (s *Service) TeamMemberCreate(ctx context.Context, teamIdentity string, o TeamMemberCreateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Post(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
go
func (s *Service) TeamMemberCreate(ctx context.Context, teamIdentity string, o TeamMemberCreateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Post(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberCreate", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "o", "TeamMemberCreateOpts", ")", "(", "*", "TeamMember", ",", "error", ")", "{", "var", "teamMember", "TeamMember", "\n", "return", "&", "teamMember", ",", "s", ".", "Post", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "o", ")", "\n", "}" ]
// Create a new team member.
[ "Create", "a", "new", "team", "member", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4478-L4481
20,109
heroku/heroku-go
v3/heroku.go
TeamMemberUpdate
func (s *Service) TeamMemberUpdate(ctx context.Context, teamIdentity string, o TeamMemberUpdateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Patch(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
go
func (s *Service) TeamMemberUpdate(ctx context.Context, teamIdentity string, o TeamMemberUpdateOpts) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Patch(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberUpdate", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "o", "TeamMemberUpdateOpts", ")", "(", "*", "TeamMember", ",", "error", ")", "{", "var", "teamMember", "TeamMember", "\n", "return", "&", "teamMember", ",", "s", ".", "Patch", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "o", ")", "\n", "}" ]
// Update a team member.
[ "Update", "a", "team", "member", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4490-L4493
20,110
heroku/heroku-go
v3/heroku.go
TeamMemberDelete
func (s *Service) TeamMemberDelete(ctx context.Context, teamIdentity string, teamMemberIdentity string) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Delete(ctx, &teamMember, fmt.Sprintf("/teams/%v/members/%v", teamIdentity, teamMemberIdentity)) }
go
func (s *Service) TeamMemberDelete(ctx context.Context, teamIdentity string, teamMemberIdentity string) (*TeamMember, error) { var teamMember TeamMember return &teamMember, s.Delete(ctx, &teamMember, fmt.Sprintf("/teams/%v/members/%v", teamIdentity, teamMemberIdentity)) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberDelete", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "teamMemberIdentity", "string", ")", "(", "*", "TeamMember", ",", "error", ")", "{", "var", "teamMember", "TeamMember", "\n", "return", "&", "teamMember", ",", "s", ".", "Delete", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ",", "teamMemberIdentity", ")", ")", "\n", "}" ]
// Remove a member from the team.
[ "Remove", "a", "member", "from", "the", "team", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4496-L4499
20,111
heroku/heroku-go
v3/heroku.go
TeamMemberList
func (s *Service) TeamMemberList(ctx context.Context, teamIdentity string, lr *ListRange) (TeamMemberListResult, error) { var teamMember TeamMemberListResult return teamMember, s.Get(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), nil, lr) }
go
func (s *Service) TeamMemberList(ctx context.Context, teamIdentity string, lr *ListRange) (TeamMemberListResult, error) { var teamMember TeamMemberListResult return teamMember, s.Get(ctx, &teamMember, fmt.Sprintf("/teams/%v/members", teamIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberList", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "TeamMemberListResult", ",", "error", ")", "{", "var", "teamMember", "TeamMemberListResult", "\n", "return", "teamMember", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List members of the team.
[ "List", "members", "of", "the", "team", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4504-L4507
20,112
heroku/heroku-go
v3/heroku.go
TeamMemberListByMember
func (s *Service) TeamMemberListByMember(ctx context.Context, teamIdentity string, teamMemberIdentity string, lr *ListRange) (TeamMemberListByMemberResult, error) { var teamMember TeamMemberListByMemberResult return teamMember, s.Get(ctx, &teamMember, fmt.Sprintf("/teams/%v/members/%v/apps", teamIdentity, teamMemberIdentity), nil, lr) }
go
func (s *Service) TeamMemberListByMember(ctx context.Context, teamIdentity string, teamMemberIdentity string, lr *ListRange) (TeamMemberListByMemberResult, error) { var teamMember TeamMemberListByMemberResult return teamMember, s.Get(ctx, &teamMember, fmt.Sprintf("/teams/%v/members/%v/apps", teamIdentity, teamMemberIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "TeamMemberListByMember", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "teamMemberIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "TeamMemberListByMemberResult", ",", "error", ")", "{", "var", "teamMember", "TeamMemberListByMemberResult", "\n", "return", "teamMember", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamMember", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ",", "teamMemberIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List the apps of a team member.
[ "List", "the", "apps", "of", "a", "team", "member", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4551-L4554
20,113
heroku/heroku-go
v3/heroku.go
TeamPreferencesList
func (s *Service) TeamPreferencesList(ctx context.Context, teamPreferencesIdentity string) (*TeamPreferences, error) { var teamPreferences TeamPreferences return &teamPreferences, s.Get(ctx, &teamPreferences, fmt.Sprintf("/teams/%v/preferences", teamPreferencesIdentity), nil, nil) }
go
func (s *Service) TeamPreferencesList(ctx context.Context, teamPreferencesIdentity string) (*TeamPreferences, error) { var teamPreferences TeamPreferences return &teamPreferences, s.Get(ctx, &teamPreferences, fmt.Sprintf("/teams/%v/preferences", teamPreferencesIdentity), nil, nil) }
[ "func", "(", "s", "*", "Service", ")", "TeamPreferencesList", "(", "ctx", "context", ".", "Context", ",", "teamPreferencesIdentity", "string", ")", "(", "*", "TeamPreferences", ",", "error", ")", "{", "var", "teamPreferences", "TeamPreferences", "\n", "return", "&", "teamPreferences", ",", "s", ".", "Get", "(", "ctx", ",", "&", "teamPreferences", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamPreferencesIdentity", ")", ",", "nil", ",", "nil", ")", "\n", "}" ]
// Retrieve Team Preferences
[ "Retrieve", "Team", "Preferences" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4563-L4566
20,114
heroku/heroku-go
v3/heroku.go
TeamPreferencesUpdate
func (s *Service) TeamPreferencesUpdate(ctx context.Context, teamPreferencesIdentity string, o TeamPreferencesUpdateOpts) (*TeamPreferences, error) { var teamPreferences TeamPreferences return &teamPreferences, s.Patch(ctx, &teamPreferences, fmt.Sprintf("/teams/%v/preferences", teamPreferencesIdentity), o) }
go
func (s *Service) TeamPreferencesUpdate(ctx context.Context, teamPreferencesIdentity string, o TeamPreferencesUpdateOpts) (*TeamPreferences, error) { var teamPreferences TeamPreferences return &teamPreferences, s.Patch(ctx, &teamPreferences, fmt.Sprintf("/teams/%v/preferences", teamPreferencesIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "TeamPreferencesUpdate", "(", "ctx", "context", ".", "Context", ",", "teamPreferencesIdentity", "string", ",", "o", "TeamPreferencesUpdateOpts", ")", "(", "*", "TeamPreferences", ",", "error", ")", "{", "var", "teamPreferences", "TeamPreferences", "\n", "return", "&", "teamPreferences", ",", "s", ".", "Patch", "(", "ctx", ",", "&", "teamPreferences", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamPreferencesIdentity", ")", ",", "o", ")", "\n", "}" ]
// Update Team Preferences
[ "Update", "Team", "Preferences" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4573-L4576
20,115
heroku/heroku-go
v3/heroku.go
UserPreferencesList
func (s *Service) UserPreferencesList(ctx context.Context, userPreferencesIdentity string) (*UserPreferences, error) { var userPreferences UserPreferences return &userPreferences, s.Get(ctx, &userPreferences, fmt.Sprintf("/users/%v/preferences", userPreferencesIdentity), nil, nil) }
go
func (s *Service) UserPreferencesList(ctx context.Context, userPreferencesIdentity string) (*UserPreferences, error) { var userPreferences UserPreferences return &userPreferences, s.Get(ctx, &userPreferences, fmt.Sprintf("/users/%v/preferences", userPreferencesIdentity), nil, nil) }
[ "func", "(", "s", "*", "Service", ")", "UserPreferencesList", "(", "ctx", "context", ".", "Context", ",", "userPreferencesIdentity", "string", ")", "(", "*", "UserPreferences", ",", "error", ")", "{", "var", "userPreferences", "UserPreferences", "\n", "return", "&", "userPreferences", ",", "s", ".", "Get", "(", "ctx", ",", "&", "userPreferences", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "userPreferencesIdentity", ")", ",", "nil", ",", "nil", ")", "\n", "}" ]
// Retrieve User Preferences
[ "Retrieve", "User", "Preferences" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4754-L4757
20,116
heroku/heroku-go
v3/heroku.go
UserPreferencesUpdate
func (s *Service) UserPreferencesUpdate(ctx context.Context, userPreferencesIdentity string, o UserPreferencesUpdateOpts) (*UserPreferences, error) { var userPreferences UserPreferences return &userPreferences, s.Patch(ctx, &userPreferences, fmt.Sprintf("/users/%v/preferences", userPreferencesIdentity), o) }
go
func (s *Service) UserPreferencesUpdate(ctx context.Context, userPreferencesIdentity string, o UserPreferencesUpdateOpts) (*UserPreferences, error) { var userPreferences UserPreferences return &userPreferences, s.Patch(ctx, &userPreferences, fmt.Sprintf("/users/%v/preferences", userPreferencesIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "UserPreferencesUpdate", "(", "ctx", "context", ".", "Context", ",", "userPreferencesIdentity", "string", ",", "o", "UserPreferencesUpdateOpts", ")", "(", "*", "UserPreferences", ",", "error", ")", "{", "var", "userPreferences", "UserPreferences", "\n", "return", "&", "userPreferences", ",", "s", ".", "Patch", "(", "ctx", ",", "&", "userPreferences", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "userPreferencesIdentity", ")", ",", "o", ")", "\n", "}" ]
// Update User Preferences
[ "Update", "User", "Preferences" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4775-L4778
20,117
heroku/heroku-go
v3/heroku.go
VPNConnectionCreate
func (s *Service) VPNConnectionCreate(ctx context.Context, spaceIdentity string, o VPNConnectionCreateOpts) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Post(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections", spaceIdentity), o) }
go
func (s *Service) VPNConnectionCreate(ctx context.Context, spaceIdentity string, o VPNConnectionCreateOpts) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Post(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections", spaceIdentity), o) }
[ "func", "(", "s", "*", "Service", ")", "VPNConnectionCreate", "(", "ctx", "context", ".", "Context", ",", "spaceIdentity", "string", ",", "o", "VPNConnectionCreateOpts", ")", "(", "*", "VPNConnection", ",", "error", ")", "{", "var", "vpnConnection", "VPNConnection", "\n", "return", "&", "vpnConnection", ",", "s", ".", "Post", "(", "ctx", ",", "&", "vpnConnection", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "spaceIdentity", ")", ",", "o", ")", "\n", "}" ]
// Create a new VPN connection in a private space.
[ "Create", "a", "new", "VPN", "connection", "in", "a", "private", "space", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4808-L4811
20,118
heroku/heroku-go
v3/heroku.go
VPNConnectionDestroy
func (s *Service) VPNConnectionDestroy(ctx context.Context, spaceIdentity string, vpnConnectionIdentity string) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Delete(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections/%v", spaceIdentity, vpnConnectionIdentity)) }
go
func (s *Service) VPNConnectionDestroy(ctx context.Context, spaceIdentity string, vpnConnectionIdentity string) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Delete(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections/%v", spaceIdentity, vpnConnectionIdentity)) }
[ "func", "(", "s", "*", "Service", ")", "VPNConnectionDestroy", "(", "ctx", "context", ".", "Context", ",", "spaceIdentity", "string", ",", "vpnConnectionIdentity", "string", ")", "(", "*", "VPNConnection", ",", "error", ")", "{", "var", "vpnConnection", "VPNConnection", "\n", "return", "&", "vpnConnection", ",", "s", ".", "Delete", "(", "ctx", ",", "&", "vpnConnection", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "spaceIdentity", ",", "vpnConnectionIdentity", ")", ")", "\n", "}" ]
// Destroy existing VPN Connection
[ "Destroy", "existing", "VPN", "Connection" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4814-L4817
20,119
heroku/heroku-go
v3/heroku.go
VPNConnectionList
func (s *Service) VPNConnectionList(ctx context.Context, spaceIdentity string, lr *ListRange) (VPNConnectionListResult, error) { var vpnConnection VPNConnectionListResult return vpnConnection, s.Get(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections", spaceIdentity), nil, lr) }
go
func (s *Service) VPNConnectionList(ctx context.Context, spaceIdentity string, lr *ListRange) (VPNConnectionListResult, error) { var vpnConnection VPNConnectionListResult return vpnConnection, s.Get(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections", spaceIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "VPNConnectionList", "(", "ctx", "context", ".", "Context", ",", "spaceIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "VPNConnectionListResult", ",", "error", ")", "{", "var", "vpnConnection", "VPNConnectionListResult", "\n", "return", "vpnConnection", ",", "s", ".", "Get", "(", "ctx", ",", "&", "vpnConnection", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "spaceIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List VPN connections for a space.
[ "List", "VPN", "connections", "for", "a", "space", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4822-L4825
20,120
heroku/heroku-go
v3/heroku.go
VPNConnectionInfo
func (s *Service) VPNConnectionInfo(ctx context.Context, spaceIdentity string, vpnConnectionIdentity string) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Get(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections/%v", spaceIdentity, vpnConnectionIdentity), nil, nil) }
go
func (s *Service) VPNConnectionInfo(ctx context.Context, spaceIdentity string, vpnConnectionIdentity string) (*VPNConnection, error) { var vpnConnection VPNConnection return &vpnConnection, s.Get(ctx, &vpnConnection, fmt.Sprintf("/spaces/%v/vpn-connections/%v", spaceIdentity, vpnConnectionIdentity), nil, nil) }
[ "func", "(", "s", "*", "Service", ")", "VPNConnectionInfo", "(", "ctx", "context", ".", "Context", ",", "spaceIdentity", "string", ",", "vpnConnectionIdentity", "string", ")", "(", "*", "VPNConnection", ",", "error", ")", "{", "var", "vpnConnection", "VPNConnection", "\n", "return", "&", "vpnConnection", ",", "s", ".", "Get", "(", "ctx", ",", "&", "vpnConnection", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "spaceIdentity", ",", "vpnConnectionIdentity", ")", ",", "nil", ",", "nil", ")", "\n", "}" ]
// Info for an existing vpn-connection.
[ "Info", "for", "an", "existing", "vpn", "-", "connection", "." ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4828-L4831
20,121
heroku/heroku-go
v3/heroku.go
WhitelistedAddOnServiceListByOrganization
func (s *Service) WhitelistedAddOnServiceListByOrganization(ctx context.Context, organizationIdentity string, lr *ListRange) (WhitelistedAddOnServiceListByOrganizationResult, error) { var whitelistedAddOnService WhitelistedAddOnServiceListByOrganizationResult return whitelistedAddOnService, s.Get(ctx, &whitelistedAddOnService, fmt.Sprintf("/organizations/%v/whitelisted-addon-services", organizationIdentity), nil, lr) }
go
func (s *Service) WhitelistedAddOnServiceListByOrganization(ctx context.Context, organizationIdentity string, lr *ListRange) (WhitelistedAddOnServiceListByOrganizationResult, error) { var whitelistedAddOnService WhitelistedAddOnServiceListByOrganizationResult return whitelistedAddOnService, s.Get(ctx, &whitelistedAddOnService, fmt.Sprintf("/organizations/%v/whitelisted-addon-services", organizationIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "WhitelistedAddOnServiceListByOrganization", "(", "ctx", "context", ".", "Context", ",", "organizationIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "WhitelistedAddOnServiceListByOrganizationResult", ",", "error", ")", "{", "var", "whitelistedAddOnService", "WhitelistedAddOnServiceListByOrganizationResult", "\n", "return", "whitelistedAddOnService", ",", "s", ".", "Get", "(", "ctx", ",", "&", "whitelistedAddOnService", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "organizationIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List all whitelisted Add-on Services for an Organization
[ "List", "all", "whitelisted", "Add", "-", "on", "Services", "for", "an", "Organization" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4850-L4853
20,122
heroku/heroku-go
v3/heroku.go
WhitelistedAddOnServiceListByTeam
func (s *Service) WhitelistedAddOnServiceListByTeam(ctx context.Context, teamIdentity string, lr *ListRange) (WhitelistedAddOnServiceListByTeamResult, error) { var whitelistedAddOnService WhitelistedAddOnServiceListByTeamResult return whitelistedAddOnService, s.Get(ctx, &whitelistedAddOnService, fmt.Sprintf("/teams/%v/whitelisted-addon-services", teamIdentity), nil, lr) }
go
func (s *Service) WhitelistedAddOnServiceListByTeam(ctx context.Context, teamIdentity string, lr *ListRange) (WhitelistedAddOnServiceListByTeamResult, error) { var whitelistedAddOnService WhitelistedAddOnServiceListByTeamResult return whitelistedAddOnService, s.Get(ctx, &whitelistedAddOnService, fmt.Sprintf("/teams/%v/whitelisted-addon-services", teamIdentity), nil, lr) }
[ "func", "(", "s", "*", "Service", ")", "WhitelistedAddOnServiceListByTeam", "(", "ctx", "context", ".", "Context", ",", "teamIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "WhitelistedAddOnServiceListByTeamResult", ",", "error", ")", "{", "var", "whitelistedAddOnService", "WhitelistedAddOnServiceListByTeamResult", "\n", "return", "whitelistedAddOnService", ",", "s", ".", "Get", "(", "ctx", ",", "&", "whitelistedAddOnService", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamIdentity", ")", ",", "nil", ",", "lr", ")", "\n", "}" ]
// List all whitelisted Add-on Services for a Team
[ "List", "all", "whitelisted", "Add", "-", "on", "Services", "for", "a", "Team" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/heroku.go#L4875-L4878
20,123
heroku/heroku-go
v3/transport.go
CancelRequest
func (t *Transport) CancelRequest(req *http.Request) { type canceler interface { CancelRequest(*http.Request) } tr, ok := t.Transport.(canceler) if !ok { log.Printf("heroku: Client Transport of type %T doesn't support CancelRequest; Timeout not supported\n", t.Transport) return } tr.CancelRequest(req) }
go
func (t *Transport) CancelRequest(req *http.Request) { type canceler interface { CancelRequest(*http.Request) } tr, ok := t.Transport.(canceler) if !ok { log.Printf("heroku: Client Transport of type %T doesn't support CancelRequest; Timeout not supported\n", t.Transport) return } tr.CancelRequest(req) }
[ "func", "(", "t", "*", "Transport", ")", "CancelRequest", "(", "req", "*", "http", ".", "Request", ")", "{", "type", "canceler", "interface", "{", "CancelRequest", "(", "*", "http", ".", "Request", ")", "\n", "}", "\n", "tr", ",", "ok", ":=", "t", ".", "Transport", ".", "(", "canceler", ")", "\n", "if", "!", "ok", "{", "log", ".", "Printf", "(", "\"", "\\n", "\"", ",", "t", ".", "Transport", ")", "\n", "return", "\n", "}", "\n", "tr", ".", "CancelRequest", "(", "req", ")", "\n", "}" ]
// Forward CancelRequest to underlying Transport
[ "Forward", "CancelRequest", "to", "underlying", "Transport" ]
ad17585a922f269c393cbccf2e0cf81eb8d2e431
https://github.com/heroku/heroku-go/blob/ad17585a922f269c393cbccf2e0cf81eb8d2e431/v3/transport.go#L49-L59
20,124
jtolds/gls
context.go
NewContextManager
func NewContextManager() *ContextManager { mgr := &ContextManager{values: make(map[uint]Values)} mgrRegistryMtx.Lock() defer mgrRegistryMtx.Unlock() mgrRegistry[mgr] = true return mgr }
go
func NewContextManager() *ContextManager { mgr := &ContextManager{values: make(map[uint]Values)} mgrRegistryMtx.Lock() defer mgrRegistryMtx.Unlock() mgrRegistry[mgr] = true return mgr }
[ "func", "NewContextManager", "(", ")", "*", "ContextManager", "{", "mgr", ":=", "&", "ContextManager", "{", "values", ":", "make", "(", "map", "[", "uint", "]", "Values", ")", "}", "\n", "mgrRegistryMtx", ".", "Lock", "(", ")", "\n", "defer", "mgrRegistryMtx", ".", "Unlock", "(", ")", "\n", "mgrRegistry", "[", "mgr", "]", "=", "true", "\n", "return", "mgr", "\n", "}" ]
// NewContextManager returns a brand new ContextManager. It also registers the // new ContextManager in the ContextManager registry which is used by the Go // method. ContextManagers are typically defined globally at package scope.
[ "NewContextManager", "returns", "a", "brand", "new", "ContextManager", ".", "It", "also", "registers", "the", "new", "ContextManager", "in", "the", "ContextManager", "registry", "which", "is", "used", "by", "the", "Go", "method", ".", "ContextManagers", "are", "typically", "defined", "globally", "at", "package", "scope", "." ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/context.go#L30-L36
20,125
jtolds/gls
context.go
Unregister
func (m *ContextManager) Unregister() { mgrRegistryMtx.Lock() defer mgrRegistryMtx.Unlock() delete(mgrRegistry, m) }
go
func (m *ContextManager) Unregister() { mgrRegistryMtx.Lock() defer mgrRegistryMtx.Unlock() delete(mgrRegistry, m) }
[ "func", "(", "m", "*", "ContextManager", ")", "Unregister", "(", ")", "{", "mgrRegistryMtx", ".", "Lock", "(", ")", "\n", "defer", "mgrRegistryMtx", ".", "Unlock", "(", ")", "\n", "delete", "(", "mgrRegistry", ",", "m", ")", "\n", "}" ]
// Unregister removes a ContextManager from the global registry, used by the // Go method. Only intended for use when you're completely done with a // ContextManager. Use of Unregister at all is rare.
[ "Unregister", "removes", "a", "ContextManager", "from", "the", "global", "registry", "used", "by", "the", "Go", "method", ".", "Only", "intended", "for", "use", "when", "you", "re", "completely", "done", "with", "a", "ContextManager", ".", "Use", "of", "Unregister", "at", "all", "is", "rare", "." ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/context.go#L41-L45
20,126
jtolds/gls
context.go
GetValue
func (m *ContextManager) GetValue(key interface{}) ( value interface{}, ok bool) { gid, ok := GetGoroutineId() if !ok { return nil, false } m.mtx.Lock() state, found := m.values[gid] m.mtx.Unlock() if !found { return nil, false } value, ok = state[key] return value, ok }
go
func (m *ContextManager) GetValue(key interface{}) ( value interface{}, ok bool) { gid, ok := GetGoroutineId() if !ok { return nil, false } m.mtx.Lock() state, found := m.values[gid] m.mtx.Unlock() if !found { return nil, false } value, ok = state[key] return value, ok }
[ "func", "(", "m", "*", "ContextManager", ")", "GetValue", "(", "key", "interface", "{", "}", ")", "(", "value", "interface", "{", "}", ",", "ok", "bool", ")", "{", "gid", ",", "ok", ":=", "GetGoroutineId", "(", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "false", "\n", "}", "\n\n", "m", ".", "mtx", ".", "Lock", "(", ")", "\n", "state", ",", "found", ":=", "m", ".", "values", "[", "gid", "]", "\n", "m", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "if", "!", "found", "{", "return", "nil", ",", "false", "\n", "}", "\n", "value", ",", "ok", "=", "state", "[", "key", "]", "\n", "return", "value", ",", "ok", "\n", "}" ]
// GetValue will return a previously set value, provided that the value was set // by SetValues somewhere higher up the stack. If the value is not found, ok // will be false.
[ "GetValue", "will", "return", "a", "previously", "set", "value", "provided", "that", "the", "value", "was", "set", "by", "SetValues", "somewhere", "higher", "up", "the", "stack", ".", "If", "the", "value", "is", "not", "found", "ok", "will", "be", "false", "." ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/context.go#L104-L120
20,127
jtolds/gls
context.go
Go
func Go(cb func()) { mgrRegistryMtx.RLock() defer mgrRegistryMtx.RUnlock() for mgr := range mgrRegistry { values := mgr.getValues() if len(values) > 0 { cb = func(mgr *ContextManager, cb func()) func() { return func() { mgr.SetValues(values, cb) } }(mgr, cb) } } go cb() }
go
func Go(cb func()) { mgrRegistryMtx.RLock() defer mgrRegistryMtx.RUnlock() for mgr := range mgrRegistry { values := mgr.getValues() if len(values) > 0 { cb = func(mgr *ContextManager, cb func()) func() { return func() { mgr.SetValues(values, cb) } }(mgr, cb) } } go cb() }
[ "func", "Go", "(", "cb", "func", "(", ")", ")", "{", "mgrRegistryMtx", ".", "RLock", "(", ")", "\n", "defer", "mgrRegistryMtx", ".", "RUnlock", "(", ")", "\n\n", "for", "mgr", ":=", "range", "mgrRegistry", "{", "values", ":=", "mgr", ".", "getValues", "(", ")", "\n", "if", "len", "(", "values", ")", ">", "0", "{", "cb", "=", "func", "(", "mgr", "*", "ContextManager", ",", "cb", "func", "(", ")", ")", "func", "(", ")", "{", "return", "func", "(", ")", "{", "mgr", ".", "SetValues", "(", "values", ",", "cb", ")", "}", "\n", "}", "(", "mgr", ",", "cb", ")", "\n", "}", "\n", "}", "\n\n", "go", "cb", "(", ")", "\n", "}" ]
// Go preserves ContextManager values and Goroutine-local-storage across new // goroutine invocations. The Go method makes a copy of all existing values on // all registered context managers and makes sure they are still set after // kicking off the provided function in a new goroutine. If you don't use this // Go method instead of the standard 'go' keyword, you will lose values in // ContextManagers, as goroutines have brand new stacks.
[ "Go", "preserves", "ContextManager", "values", "and", "Goroutine", "-", "local", "-", "storage", "across", "new", "goroutine", "invocations", ".", "The", "Go", "method", "makes", "a", "copy", "of", "all", "existing", "values", "on", "all", "registered", "context", "managers", "and", "makes", "sure", "they", "are", "still", "set", "after", "kicking", "off", "the", "provided", "function", "in", "a", "new", "goroutine", ".", "If", "you", "don", "t", "use", "this", "Go", "method", "instead", "of", "the", "standard", "go", "keyword", "you", "will", "lose", "values", "in", "ContextManagers", "as", "goroutines", "have", "brand", "new", "stacks", "." ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/context.go#L139-L153
20,128
jtolds/gls
gen_sym.go
GenSym
func GenSym() ContextKey { keyMtx.Lock() defer keyMtx.Unlock() keyCounter += 1 return ContextKey{id: keyCounter} }
go
func GenSym() ContextKey { keyMtx.Lock() defer keyMtx.Unlock() keyCounter += 1 return ContextKey{id: keyCounter} }
[ "func", "GenSym", "(", ")", "ContextKey", "{", "keyMtx", ".", "Lock", "(", ")", "\n", "defer", "keyMtx", ".", "Unlock", "(", ")", "\n", "keyCounter", "+=", "1", "\n", "return", "ContextKey", "{", "id", ":", "keyCounter", "}", "\n", "}" ]
// GenSym will return a brand new, never-before-used ContextKey
[ "GenSym", "will", "return", "a", "brand", "new", "never", "-", "before", "-", "used", "ContextKey" ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/gen_sym.go#L16-L21
20,129
jtolds/gls
gid.go
EnsureGoroutineId
func EnsureGoroutineId(cb func(gid uint)) { if gid, ok := readStackTag(); ok { cb(gid) return } gid := stackTagPool.Acquire() defer stackTagPool.Release(gid) addStackTag(gid, func() { cb(gid) }) }
go
func EnsureGoroutineId(cb func(gid uint)) { if gid, ok := readStackTag(); ok { cb(gid) return } gid := stackTagPool.Acquire() defer stackTagPool.Release(gid) addStackTag(gid, func() { cb(gid) }) }
[ "func", "EnsureGoroutineId", "(", "cb", "func", "(", "gid", "uint", ")", ")", "{", "if", "gid", ",", "ok", ":=", "readStackTag", "(", ")", ";", "ok", "{", "cb", "(", "gid", ")", "\n", "return", "\n", "}", "\n", "gid", ":=", "stackTagPool", ".", "Acquire", "(", ")", "\n", "defer", "stackTagPool", ".", "Release", "(", "gid", ")", "\n", "addStackTag", "(", "gid", ",", "func", "(", ")", "{", "cb", "(", "gid", ")", "}", ")", "\n", "}" ]
// Will call cb with the current goroutine identifier. If one hasn't already // been generated, one will be created and set first. The goroutine identifier // might be invalid after cb returns.
[ "Will", "call", "cb", "with", "the", "current", "goroutine", "identifier", ".", "If", "one", "hasn", "t", "already", "been", "generated", "one", "will", "be", "created", "and", "set", "first", ".", "The", "goroutine", "identifier", "might", "be", "invalid", "after", "cb", "returns", "." ]
b4936e06046bbecbb94cae9c18127ebe510a2cb9
https://github.com/jtolds/gls/blob/b4936e06046bbecbb94cae9c18127ebe510a2cb9/gid.go#L17-L25
20,130
mwitkow/grpc-proxy
proxy/handler.go
handler
func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error { // little bit of gRPC internals never hurt anyone fullMethodName, ok := grpc.MethodFromServerStream(serverStream) if !ok { return grpc.Errorf(codes.Internal, "lowLevelServerStream not exists in context") } // We require that the director's returned context inherits from the serverStream.Context(). outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName) if err != nil { return err } clientCtx, clientCancel := context.WithCancel(outgoingCtx) // TODO(mwitkow): Add a `forwarded` header to metadata, https://en.wikipedia.org/wiki/X-Forwarded-For. clientStream, err := grpc.NewClientStream(clientCtx, clientStreamDescForProxying, backendConn, fullMethodName) if err != nil { return err } // Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate. // Channels do not have to be closed, it is just a control flow mechanism, see // https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ s2cErrChan := s.forwardServerToClient(serverStream, clientStream) c2sErrChan := s.forwardClientToServer(clientStream, serverStream) // We don't know which side is going to stop sending first, so we need a select between the two. for i := 0; i < 2; i++ { select { case s2cErr := <-s2cErrChan: if s2cErr == io.EOF { // this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./ // the clientStream>serverStream may continue pumping though. clientStream.CloseSend() break } else { // however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need // to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and // exit with an error to the stack clientCancel() return grpc.Errorf(codes.Internal, "failed proxying s2c: %v", s2cErr) } case c2sErr := <-c2sErrChan: // This happens when the clientStream has nothing else to offer (io.EOF), returned a gRPC error. In those two // cases we may have received Trailers as part of the call. In case of other errors (stream closed) the trailers // will be nil. serverStream.SetTrailer(clientStream.Trailer()) // c2sErr will contain RPC error from client code. If not io.EOF return the RPC error as server stream error. if c2sErr != io.EOF { return c2sErr } return nil } } return grpc.Errorf(codes.Internal, "gRPC proxying should never reach this stage.") }
go
func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error { // little bit of gRPC internals never hurt anyone fullMethodName, ok := grpc.MethodFromServerStream(serverStream) if !ok { return grpc.Errorf(codes.Internal, "lowLevelServerStream not exists in context") } // We require that the director's returned context inherits from the serverStream.Context(). outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName) if err != nil { return err } clientCtx, clientCancel := context.WithCancel(outgoingCtx) // TODO(mwitkow): Add a `forwarded` header to metadata, https://en.wikipedia.org/wiki/X-Forwarded-For. clientStream, err := grpc.NewClientStream(clientCtx, clientStreamDescForProxying, backendConn, fullMethodName) if err != nil { return err } // Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate. // Channels do not have to be closed, it is just a control flow mechanism, see // https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ s2cErrChan := s.forwardServerToClient(serverStream, clientStream) c2sErrChan := s.forwardClientToServer(clientStream, serverStream) // We don't know which side is going to stop sending first, so we need a select between the two. for i := 0; i < 2; i++ { select { case s2cErr := <-s2cErrChan: if s2cErr == io.EOF { // this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./ // the clientStream>serverStream may continue pumping though. clientStream.CloseSend() break } else { // however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need // to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and // exit with an error to the stack clientCancel() return grpc.Errorf(codes.Internal, "failed proxying s2c: %v", s2cErr) } case c2sErr := <-c2sErrChan: // This happens when the clientStream has nothing else to offer (io.EOF), returned a gRPC error. In those two // cases we may have received Trailers as part of the call. In case of other errors (stream closed) the trailers // will be nil. serverStream.SetTrailer(clientStream.Trailer()) // c2sErr will contain RPC error from client code. If not io.EOF return the RPC error as server stream error. if c2sErr != io.EOF { return c2sErr } return nil } } return grpc.Errorf(codes.Internal, "gRPC proxying should never reach this stage.") }
[ "func", "(", "s", "*", "handler", ")", "handler", "(", "srv", "interface", "{", "}", ",", "serverStream", "grpc", ".", "ServerStream", ")", "error", "{", "// little bit of gRPC internals never hurt anyone", "fullMethodName", ",", "ok", ":=", "grpc", ".", "MethodFromServerStream", "(", "serverStream", ")", "\n", "if", "!", "ok", "{", "return", "grpc", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ")", "\n", "}", "\n", "// We require that the director's returned context inherits from the serverStream.Context().", "outgoingCtx", ",", "backendConn", ",", "err", ":=", "s", ".", "director", "(", "serverStream", ".", "Context", "(", ")", ",", "fullMethodName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "clientCtx", ",", "clientCancel", ":=", "context", ".", "WithCancel", "(", "outgoingCtx", ")", "\n", "// TODO(mwitkow): Add a `forwarded` header to metadata, https://en.wikipedia.org/wiki/X-Forwarded-For.", "clientStream", ",", "err", ":=", "grpc", ".", "NewClientStream", "(", "clientCtx", ",", "clientStreamDescForProxying", ",", "backendConn", ",", "fullMethodName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate.", "// Channels do not have to be closed, it is just a control flow mechanism, see", "// https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ", "s2cErrChan", ":=", "s", ".", "forwardServerToClient", "(", "serverStream", ",", "clientStream", ")", "\n", "c2sErrChan", ":=", "s", ".", "forwardClientToServer", "(", "clientStream", ",", "serverStream", ")", "\n", "// We don't know which side is going to stop sending first, so we need a select between the two.", "for", "i", ":=", "0", ";", "i", "<", "2", ";", "i", "++", "{", "select", "{", "case", "s2cErr", ":=", "<-", "s2cErrChan", ":", "if", "s2cErr", "==", "io", ".", "EOF", "{", "// this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./", "// the clientStream>serverStream may continue pumping though.", "clientStream", ".", "CloseSend", "(", ")", "\n", "break", "\n", "}", "else", "{", "// however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need", "// to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and", "// exit with an error to the stack", "clientCancel", "(", ")", "\n", "return", "grpc", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "s2cErr", ")", "\n", "}", "\n", "case", "c2sErr", ":=", "<-", "c2sErrChan", ":", "// This happens when the clientStream has nothing else to offer (io.EOF), returned a gRPC error. In those two", "// cases we may have received Trailers as part of the call. In case of other errors (stream closed) the trailers", "// will be nil.", "serverStream", ".", "SetTrailer", "(", "clientStream", ".", "Trailer", "(", ")", ")", "\n", "// c2sErr will contain RPC error from client code. If not io.EOF return the RPC error as server stream error.", "if", "c2sErr", "!=", "io", ".", "EOF", "{", "return", "c2sErr", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "grpc", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ")", "\n", "}" ]
// handler is where the real magic of proxying happens. // It is invoked like any gRPC server stream and uses the gRPC server framing to get and receive bytes from the wire, // forwarding it to a ClientStream established against the relevant ClientConn.
[ "handler", "is", "where", "the", "real", "magic", "of", "proxying", "happens", ".", "It", "is", "invoked", "like", "any", "gRPC", "server", "stream", "and", "uses", "the", "gRPC", "server", "framing", "to", "get", "and", "receive", "bytes", "from", "the", "wire", "forwarding", "it", "to", "a", "ClientStream", "established", "against", "the", "relevant", "ClientConn", "." ]
0f1106ef9c766333b9acb4b81e705da4bade7215
https://github.com/mwitkow/grpc-proxy/blob/0f1106ef9c766333b9acb4b81e705da4bade7215/proxy/handler.go#L60-L112
20,131
couchbase/moss
store_footer.go
AddRef
func (f *Footer) AddRef() { f.m.Lock() f.refs++ f.m.Unlock() }
go
func (f *Footer) AddRef() { f.m.Lock() f.refs++ f.m.Unlock() }
[ "func", "(", "f", "*", "Footer", ")", "AddRef", "(", ")", "{", "f", ".", "m", ".", "Lock", "(", ")", "\n", "f", ".", "refs", "++", "\n", "f", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// AddRef increases the ref count on this footer
[ "AddRef", "increases", "the", "ref", "count", "on", "this", "footer" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_footer.go#L408-L412
20,132
couchbase/moss
store_footer.go
DecRef
func (f *Footer) DecRef() { f.m.Lock() f.refs-- if f.refs <= 0 { f.SegmentLocs.DecRef() f.SegmentLocs = nil f.ss = nil } f.m.Unlock() }
go
func (f *Footer) DecRef() { f.m.Lock() f.refs-- if f.refs <= 0 { f.SegmentLocs.DecRef() f.SegmentLocs = nil f.ss = nil } f.m.Unlock() }
[ "func", "(", "f", "*", "Footer", ")", "DecRef", "(", ")", "{", "f", ".", "m", ".", "Lock", "(", ")", "\n", "f", ".", "refs", "--", "\n", "if", "f", ".", "refs", "<=", "0", "{", "f", ".", "SegmentLocs", ".", "DecRef", "(", ")", "\n", "f", ".", "SegmentLocs", "=", "nil", "\n", "f", ".", "ss", "=", "nil", "\n", "}", "\n", "f", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// DecRef decreases the ref count on this footer
[ "DecRef", "decreases", "the", "ref", "count", "on", "this", "footer" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_footer.go#L415-L424
20,133
couchbase/moss
store_footer.go
Length
func (f *Footer) Length() uint64 { jBuf, err := json.Marshal(f) if err != nil { return 0 } footerLen := footerBegLen + len(jBuf) + footerEndLen return uint64(footerLen) }
go
func (f *Footer) Length() uint64 { jBuf, err := json.Marshal(f) if err != nil { return 0 } footerLen := footerBegLen + len(jBuf) + footerEndLen return uint64(footerLen) }
[ "func", "(", "f", "*", "Footer", ")", "Length", "(", ")", "uint64", "{", "jBuf", ",", "err", ":=", "json", ".", "Marshal", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n\n", "footerLen", ":=", "footerBegLen", "+", "len", "(", "jBuf", ")", "+", "footerEndLen", "\n", "return", "uint64", "(", "footerLen", ")", "\n", "}" ]
// Length returns the length of this footer
[ "Length", "returns", "the", "length", "of", "this", "footer" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_footer.go#L427-L435
20,134
couchbase/moss
collection_stats.go
Stats
func (m *collection) Stats() (*CollectionStats, error) { rv := &CollectionStats{} m.stats.AtomicCopyTo(rv) m.m.Lock() m.statsSegmentsLOCKED(rv) m.m.Unlock() return rv, nil }
go
func (m *collection) Stats() (*CollectionStats, error) { rv := &CollectionStats{} m.stats.AtomicCopyTo(rv) m.m.Lock() m.statsSegmentsLOCKED(rv) m.m.Unlock() return rv, nil }
[ "func", "(", "m", "*", "collection", ")", "Stats", "(", ")", "(", "*", "CollectionStats", ",", "error", ")", "{", "rv", ":=", "&", "CollectionStats", "{", "}", "\n\n", "m", ".", "stats", ".", "AtomicCopyTo", "(", "rv", ")", "\n\n", "m", ".", "m", ".", "Lock", "(", ")", "\n", "m", ".", "statsSegmentsLOCKED", "(", "rv", ")", "\n", "m", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "rv", ",", "nil", "\n", "}" ]
// Stats returns stats for this collection.
[ "Stats", "returns", "stats", "for", "this", "collection", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection_stats.go#L22-L32
20,135
couchbase/moss
collection_stats.go
statsSegmentsLOCKED
func (m *collection) statsSegmentsLOCKED(rv *CollectionStats) { var sssDirtyTop *SegmentStackStats var sssDirtyMid *SegmentStackStats var sssDirtyBase *SegmentStackStats var sssClean *SegmentStackStats if m.stackDirtyTop != nil { sssDirtyTop = m.stackDirtyTop.Stats() } if m.stackDirtyMid != nil { sssDirtyMid = m.stackDirtyMid.Stats() } if m.stackDirtyBase != nil { sssDirtyBase = m.stackDirtyBase.Stats() } if m.stackClean != nil { sssClean = m.stackClean.Stats() } sssDirty := &SegmentStackStats{} sssDirtyTop.AddTo(sssDirty) sssDirtyMid.AddTo(sssDirty) sssDirtyBase.AddTo(sssDirty) rv.CurDirtyOps = sssDirty.CurOps rv.CurDirtyBytes = sssDirty.CurBytes rv.CurDirtySegments = sssDirty.CurSegments if sssDirtyTop != nil { rv.CurDirtyTopOps = sssDirtyTop.CurOps rv.CurDirtyTopBytes = sssDirtyTop.CurBytes rv.CurDirtyTopSegments = sssDirtyTop.CurSegments } if sssDirtyMid != nil { rv.CurDirtyMidOps = sssDirtyMid.CurOps rv.CurDirtyMidBytes = sssDirtyMid.CurBytes rv.CurDirtyMidSegments = sssDirtyMid.CurSegments } if sssDirtyBase != nil { rv.CurDirtyBaseOps = sssDirtyBase.CurOps rv.CurDirtyBaseBytes = sssDirtyBase.CurBytes rv.CurDirtyBaseSegments = sssDirtyBase.CurSegments } if sssClean != nil { rv.CurCleanOps = sssClean.CurOps rv.CurCleanBytes = sssClean.CurBytes rv.CurCleanSegments = sssClean.CurSegments } }
go
func (m *collection) statsSegmentsLOCKED(rv *CollectionStats) { var sssDirtyTop *SegmentStackStats var sssDirtyMid *SegmentStackStats var sssDirtyBase *SegmentStackStats var sssClean *SegmentStackStats if m.stackDirtyTop != nil { sssDirtyTop = m.stackDirtyTop.Stats() } if m.stackDirtyMid != nil { sssDirtyMid = m.stackDirtyMid.Stats() } if m.stackDirtyBase != nil { sssDirtyBase = m.stackDirtyBase.Stats() } if m.stackClean != nil { sssClean = m.stackClean.Stats() } sssDirty := &SegmentStackStats{} sssDirtyTop.AddTo(sssDirty) sssDirtyMid.AddTo(sssDirty) sssDirtyBase.AddTo(sssDirty) rv.CurDirtyOps = sssDirty.CurOps rv.CurDirtyBytes = sssDirty.CurBytes rv.CurDirtySegments = sssDirty.CurSegments if sssDirtyTop != nil { rv.CurDirtyTopOps = sssDirtyTop.CurOps rv.CurDirtyTopBytes = sssDirtyTop.CurBytes rv.CurDirtyTopSegments = sssDirtyTop.CurSegments } if sssDirtyMid != nil { rv.CurDirtyMidOps = sssDirtyMid.CurOps rv.CurDirtyMidBytes = sssDirtyMid.CurBytes rv.CurDirtyMidSegments = sssDirtyMid.CurSegments } if sssDirtyBase != nil { rv.CurDirtyBaseOps = sssDirtyBase.CurOps rv.CurDirtyBaseBytes = sssDirtyBase.CurBytes rv.CurDirtyBaseSegments = sssDirtyBase.CurSegments } if sssClean != nil { rv.CurCleanOps = sssClean.CurOps rv.CurCleanBytes = sssClean.CurBytes rv.CurCleanSegments = sssClean.CurSegments } }
[ "func", "(", "m", "*", "collection", ")", "statsSegmentsLOCKED", "(", "rv", "*", "CollectionStats", ")", "{", "var", "sssDirtyTop", "*", "SegmentStackStats", "\n", "var", "sssDirtyMid", "*", "SegmentStackStats", "\n", "var", "sssDirtyBase", "*", "SegmentStackStats", "\n", "var", "sssClean", "*", "SegmentStackStats", "\n\n", "if", "m", ".", "stackDirtyTop", "!=", "nil", "{", "sssDirtyTop", "=", "m", ".", "stackDirtyTop", ".", "Stats", "(", ")", "\n", "}", "\n\n", "if", "m", ".", "stackDirtyMid", "!=", "nil", "{", "sssDirtyMid", "=", "m", ".", "stackDirtyMid", ".", "Stats", "(", ")", "\n", "}", "\n\n", "if", "m", ".", "stackDirtyBase", "!=", "nil", "{", "sssDirtyBase", "=", "m", ".", "stackDirtyBase", ".", "Stats", "(", ")", "\n", "}", "\n\n", "if", "m", ".", "stackClean", "!=", "nil", "{", "sssClean", "=", "m", ".", "stackClean", ".", "Stats", "(", ")", "\n", "}", "\n\n", "sssDirty", ":=", "&", "SegmentStackStats", "{", "}", "\n", "sssDirtyTop", ".", "AddTo", "(", "sssDirty", ")", "\n", "sssDirtyMid", ".", "AddTo", "(", "sssDirty", ")", "\n", "sssDirtyBase", ".", "AddTo", "(", "sssDirty", ")", "\n\n", "rv", ".", "CurDirtyOps", "=", "sssDirty", ".", "CurOps", "\n", "rv", ".", "CurDirtyBytes", "=", "sssDirty", ".", "CurBytes", "\n", "rv", ".", "CurDirtySegments", "=", "sssDirty", ".", "CurSegments", "\n\n", "if", "sssDirtyTop", "!=", "nil", "{", "rv", ".", "CurDirtyTopOps", "=", "sssDirtyTop", ".", "CurOps", "\n", "rv", ".", "CurDirtyTopBytes", "=", "sssDirtyTop", ".", "CurBytes", "\n", "rv", ".", "CurDirtyTopSegments", "=", "sssDirtyTop", ".", "CurSegments", "\n", "}", "\n\n", "if", "sssDirtyMid", "!=", "nil", "{", "rv", ".", "CurDirtyMidOps", "=", "sssDirtyMid", ".", "CurOps", "\n", "rv", ".", "CurDirtyMidBytes", "=", "sssDirtyMid", ".", "CurBytes", "\n", "rv", ".", "CurDirtyMidSegments", "=", "sssDirtyMid", ".", "CurSegments", "\n", "}", "\n\n", "if", "sssDirtyBase", "!=", "nil", "{", "rv", ".", "CurDirtyBaseOps", "=", "sssDirtyBase", ".", "CurOps", "\n", "rv", ".", "CurDirtyBaseBytes", "=", "sssDirtyBase", ".", "CurBytes", "\n", "rv", ".", "CurDirtyBaseSegments", "=", "sssDirtyBase", ".", "CurSegments", "\n", "}", "\n\n", "if", "sssClean", "!=", "nil", "{", "rv", ".", "CurCleanOps", "=", "sssClean", ".", "CurOps", "\n", "rv", ".", "CurCleanBytes", "=", "sssClean", ".", "CurBytes", "\n", "rv", ".", "CurCleanSegments", "=", "sssClean", ".", "CurSegments", "\n", "}", "\n", "}" ]
// statsSegmentsLOCKED retrieves stats related to segments.
[ "statsSegmentsLOCKED", "retrieves", "stats", "related", "to", "segments", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection_stats.go#L41-L95
20,136
couchbase/moss
store.go
buildNewFooter
func (s *Store) buildNewFooter(storeFooter *Footer, ss *segmentStack) *Footer { footer := &Footer{refs: 1, incarNum: ss.incarNum} numSegmentLocs := len(ss.a) var segmentLocs []SegmentLoc if storeFooter != nil { numSegmentLocs += len(storeFooter.SegmentLocs) segmentLocs = make([]SegmentLoc, 0, numSegmentLocs) segmentLocs = append(segmentLocs, storeFooter.SegmentLocs...) footer.PrevFooterOffset = storeFooter.filePos } else { segmentLocs = make([]SegmentLoc, 0, numSegmentLocs) } footer.SegmentLocs = segmentLocs // Now process the child collections recursively. for cName, childStack := range ss.childSegStacks { var storeChildFooter *Footer if storeFooter != nil && storeFooter.ChildFooters != nil { var exists bool storeChildFooter, exists = storeFooter.ChildFooters[cName] if exists { if storeChildFooter.incarNum != childStack.incarNum { // This is a special case of deletion & recreate where an // existing child collection has been deleted and quickly // recreated. Here we drop the existing store footer's // segments that correspond to the prior incarnation. storeChildFooter = nil } } } childFooter := s.buildNewFooter(storeChildFooter, childStack) if len(footer.ChildFooters) == 0 { footer.ChildFooters = make(map[string]*Footer) } footer.ChildFooters[cName] = childFooter } // As a deleted Child collection does not feature in the source // segmentStack, its corresponding Footer would simply get dropped. return footer }
go
func (s *Store) buildNewFooter(storeFooter *Footer, ss *segmentStack) *Footer { footer := &Footer{refs: 1, incarNum: ss.incarNum} numSegmentLocs := len(ss.a) var segmentLocs []SegmentLoc if storeFooter != nil { numSegmentLocs += len(storeFooter.SegmentLocs) segmentLocs = make([]SegmentLoc, 0, numSegmentLocs) segmentLocs = append(segmentLocs, storeFooter.SegmentLocs...) footer.PrevFooterOffset = storeFooter.filePos } else { segmentLocs = make([]SegmentLoc, 0, numSegmentLocs) } footer.SegmentLocs = segmentLocs // Now process the child collections recursively. for cName, childStack := range ss.childSegStacks { var storeChildFooter *Footer if storeFooter != nil && storeFooter.ChildFooters != nil { var exists bool storeChildFooter, exists = storeFooter.ChildFooters[cName] if exists { if storeChildFooter.incarNum != childStack.incarNum { // This is a special case of deletion & recreate where an // existing child collection has been deleted and quickly // recreated. Here we drop the existing store footer's // segments that correspond to the prior incarnation. storeChildFooter = nil } } } childFooter := s.buildNewFooter(storeChildFooter, childStack) if len(footer.ChildFooters) == 0 { footer.ChildFooters = make(map[string]*Footer) } footer.ChildFooters[cName] = childFooter } // As a deleted Child collection does not feature in the source // segmentStack, its corresponding Footer would simply get dropped. return footer }
[ "func", "(", "s", "*", "Store", ")", "buildNewFooter", "(", "storeFooter", "*", "Footer", ",", "ss", "*", "segmentStack", ")", "*", "Footer", "{", "footer", ":=", "&", "Footer", "{", "refs", ":", "1", ",", "incarNum", ":", "ss", ".", "incarNum", "}", "\n\n", "numSegmentLocs", ":=", "len", "(", "ss", ".", "a", ")", "\n", "var", "segmentLocs", "[", "]", "SegmentLoc", "\n", "if", "storeFooter", "!=", "nil", "{", "numSegmentLocs", "+=", "len", "(", "storeFooter", ".", "SegmentLocs", ")", "\n", "segmentLocs", "=", "make", "(", "[", "]", "SegmentLoc", ",", "0", ",", "numSegmentLocs", ")", "\n", "segmentLocs", "=", "append", "(", "segmentLocs", ",", "storeFooter", ".", "SegmentLocs", "...", ")", "\n", "footer", ".", "PrevFooterOffset", "=", "storeFooter", ".", "filePos", "\n", "}", "else", "{", "segmentLocs", "=", "make", "(", "[", "]", "SegmentLoc", ",", "0", ",", "numSegmentLocs", ")", "\n", "}", "\n", "footer", ".", "SegmentLocs", "=", "segmentLocs", "\n\n", "// Now process the child collections recursively.", "for", "cName", ",", "childStack", ":=", "range", "ss", ".", "childSegStacks", "{", "var", "storeChildFooter", "*", "Footer", "\n", "if", "storeFooter", "!=", "nil", "&&", "storeFooter", ".", "ChildFooters", "!=", "nil", "{", "var", "exists", "bool", "\n", "storeChildFooter", ",", "exists", "=", "storeFooter", ".", "ChildFooters", "[", "cName", "]", "\n", "if", "exists", "{", "if", "storeChildFooter", ".", "incarNum", "!=", "childStack", ".", "incarNum", "{", "// This is a special case of deletion & recreate where an", "// existing child collection has been deleted and quickly", "// recreated. Here we drop the existing store footer's", "// segments that correspond to the prior incarnation.", "storeChildFooter", "=", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "childFooter", ":=", "s", ".", "buildNewFooter", "(", "storeChildFooter", ",", "childStack", ")", "\n", "if", "len", "(", "footer", ".", "ChildFooters", ")", "==", "0", "{", "footer", ".", "ChildFooters", "=", "make", "(", "map", "[", "string", "]", "*", "Footer", ")", "\n", "}", "\n", "footer", ".", "ChildFooters", "[", "cName", "]", "=", "childFooter", "\n", "}", "\n\n", "// As a deleted Child collection does not feature in the source", "// segmentStack, its corresponding Footer would simply get dropped.", "return", "footer", "\n", "}" ]
// buildNewFooter will construct a new Footer for the store by combining // the given storeFooter's segmentLocs with that of the incoming snapshot.
[ "buildNewFooter", "will", "construct", "a", "new", "Footer", "for", "the", "store", "by", "combining", "the", "given", "storeFooter", "s", "segmentLocs", "with", "that", "of", "the", "incoming", "snapshot", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store.go#L178-L220
20,137
couchbase/moss
store.go
persistSegments
func (s *Store) persistSegments(ss *segmentStack, footer *Footer, file File, fref *FileRef) error { // First persist the child segments recursively. for cName, childSegStack := range ss.childSegStacks { err := s.persistSegments(childSegStack, footer.ChildFooters[cName], file, fref) if err != nil { return err } } for _, segment := range ss.a { if segment.Len() <= 0 { // With multiple child collections it is possible that some child // collections segments are empty. Ok to skip these empty segments. continue } segmentLoc, err := s.persistSegment(file, segment, s.options) if err != nil { return err } footer.SegmentLocs = append(footer.SegmentLocs, segmentLoc) } return nil }
go
func (s *Store) persistSegments(ss *segmentStack, footer *Footer, file File, fref *FileRef) error { // First persist the child segments recursively. for cName, childSegStack := range ss.childSegStacks { err := s.persistSegments(childSegStack, footer.ChildFooters[cName], file, fref) if err != nil { return err } } for _, segment := range ss.a { if segment.Len() <= 0 { // With multiple child collections it is possible that some child // collections segments are empty. Ok to skip these empty segments. continue } segmentLoc, err := s.persistSegment(file, segment, s.options) if err != nil { return err } footer.SegmentLocs = append(footer.SegmentLocs, segmentLoc) } return nil }
[ "func", "(", "s", "*", "Store", ")", "persistSegments", "(", "ss", "*", "segmentStack", ",", "footer", "*", "Footer", ",", "file", "File", ",", "fref", "*", "FileRef", ")", "error", "{", "// First persist the child segments recursively.", "for", "cName", ",", "childSegStack", ":=", "range", "ss", ".", "childSegStacks", "{", "err", ":=", "s", ".", "persistSegments", "(", "childSegStack", ",", "footer", ".", "ChildFooters", "[", "cName", "]", ",", "file", ",", "fref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "segment", ":=", "range", "ss", ".", "a", "{", "if", "segment", ".", "Len", "(", ")", "<=", "0", "{", "// With multiple child collections it is possible that some child", "// collections segments are empty. Ok to skip these empty segments.", "continue", "\n", "}", "\n\n", "segmentLoc", ",", "err", ":=", "s", ".", "persistSegment", "(", "file", ",", "segment", ",", "s", ".", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "footer", ".", "SegmentLocs", "=", "append", "(", "footer", ".", "SegmentLocs", ",", "segmentLoc", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// persistSegments will recursively write out all the segments of the // current collection as well as any of its child collections.
[ "persistSegments", "will", "recursively", "write", "out", "all", "the", "segments", "of", "the", "current", "collection", "as", "well", "as", "any", "of", "its", "child", "collections", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store.go#L224-L251
20,138
couchbase/moss
store.go
removeFileOnClose
func (s *Store) removeFileOnClose(fref *FileRef) (os.FileInfo, error) { finfo, err := fref.file.Stat() if err != nil { return nil, err } if len(finfo.Name()) > 0 { fref.OnAfterClose(func() { fileName := finfo.Name() go func() { s.m.Lock() delete(s.fileRefMap, fileName) s.m.Unlock() err := os.Remove(path.Join(s.dir, fileName)) if err != nil { if s.options.CollectionOptions.Log != nil { s.options.CollectionOptions.Log( "store: error deleting file %s, err: %v", fileName, err) } } }() }) } return finfo, nil }
go
func (s *Store) removeFileOnClose(fref *FileRef) (os.FileInfo, error) { finfo, err := fref.file.Stat() if err != nil { return nil, err } if len(finfo.Name()) > 0 { fref.OnAfterClose(func() { fileName := finfo.Name() go func() { s.m.Lock() delete(s.fileRefMap, fileName) s.m.Unlock() err := os.Remove(path.Join(s.dir, fileName)) if err != nil { if s.options.CollectionOptions.Log != nil { s.options.CollectionOptions.Log( "store: error deleting file %s, err: %v", fileName, err) } } }() }) } return finfo, nil }
[ "func", "(", "s", "*", "Store", ")", "removeFileOnClose", "(", "fref", "*", "FileRef", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "finfo", ",", "err", ":=", "fref", ".", "file", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "finfo", ".", "Name", "(", ")", ")", ">", "0", "{", "fref", ".", "OnAfterClose", "(", "func", "(", ")", "{", "fileName", ":=", "finfo", ".", "Name", "(", ")", "\n", "go", "func", "(", ")", "{", "s", ".", "m", ".", "Lock", "(", ")", "\n", "delete", "(", "s", ".", "fileRefMap", ",", "fileName", ")", "\n", "s", ".", "m", ".", "Unlock", "(", ")", "\n", "err", ":=", "os", ".", "Remove", "(", "path", ".", "Join", "(", "s", ".", "dir", ",", "fileName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "s", ".", "options", ".", "CollectionOptions", ".", "Log", "!=", "nil", "{", "s", ".", "options", ".", "CollectionOptions", ".", "Log", "(", "\"", "\"", ",", "fileName", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "}", ")", "\n", "}", "\n\n", "return", "finfo", ",", "nil", "\n", "}" ]
// removeFileOnClose will setup the callback to wipe out the file safely // when all references to it are closed.
[ "removeFileOnClose", "will", "setup", "the", "callback", "to", "wipe", "out", "the", "file", "safely", "when", "all", "references", "to", "it", "are", "closed", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store.go#L314-L340
20,139
couchbase/moss
store.go
pageOffset
func pageOffset(pos, pageSize int64) int64 { rem := pos % pageSize if rem != 0 { return pos - rem } return pos }
go
func pageOffset(pos, pageSize int64) int64 { rem := pos % pageSize if rem != 0 { return pos - rem } return pos }
[ "func", "pageOffset", "(", "pos", ",", "pageSize", "int64", ")", "int64", "{", "rem", ":=", "pos", "%", "pageSize", "\n", "if", "rem", "!=", "0", "{", "return", "pos", "-", "rem", "\n", "}", "\n", "return", "pos", "\n", "}" ]
// pageOffset returns the page offset for a given pos.
[ "pageOffset", "returns", "the", "page", "offset", "for", "a", "given", "pos", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store.go#L510-L516
20,140
couchbase/moss
store_stats.go
Stats
func (s *Store) Stats() (map[string]interface{}, error) { finfos, err := ioutil.ReadDir(s.dir) if err != nil { return nil, err } var numBytesUsedDisk uint64 for _, finfo := range finfos { if !finfo.IsDir() { numBytesUsedDisk += uint64(finfo.Size()) } } s.m.Lock() totPersists := s.totPersists totCompactions := s.totCompactions totCompactionsPartial := s.totCompactionsPartial numLastCompactionBeforeBytes := s.numLastCompactionBeforeBytes numLastCompactionAfterBytes := s.numLastCompactionAfterBytes totCompactionDecreaseBytes := s.totCompactionDecreaseBytes totCompactionIncreaseBytes := s.totCompactionIncreaseBytes maxCompactionDecreaseBytes := s.maxCompactionDecreaseBytes maxCompactionIncreaseBytes := s.maxCompactionIncreaseBytes totCompactionBeforeBytes := s.totCompactionBeforeBytes totCompactionWrittenBytes := s.totCompactionWrittenBytes s.m.Unlock() footer, err := s.snapshot() if err != nil { return nil, err } var numSegments uint64 if footer != nil { footer.m.Lock() if footer.ss != nil { numSegments = uint64(len(footer.ss.a)) } footer.m.Unlock() } footer.Close() files, numFilesOpen := s.allFiles() return map[string]interface{}{ "num_bytes_used_disk": numBytesUsedDisk, "total_persists": totPersists, "total_compactions": totCompactions, "total_compactions_partial": totCompactionsPartial, "total_compaction_before_bytes": totCompactionBeforeBytes, "total_compaction_written_bytes": totCompactionWrittenBytes, "num_segments": numSegments, "num_last_compaction_before_bytes": numLastCompactionBeforeBytes, "num_last_compaction_after_bytes": numLastCompactionAfterBytes, "total_compaction_decrease_bytes": totCompactionDecreaseBytes, "total_compaction_increase_bytes": totCompactionIncreaseBytes, "max_compaction_decrease_bytes": maxCompactionDecreaseBytes, "max_compaction_increase_bytes": maxCompactionIncreaseBytes, "num_files": len(files), "num_files_open": numFilesOpen, "files": files, }, nil }
go
func (s *Store) Stats() (map[string]interface{}, error) { finfos, err := ioutil.ReadDir(s.dir) if err != nil { return nil, err } var numBytesUsedDisk uint64 for _, finfo := range finfos { if !finfo.IsDir() { numBytesUsedDisk += uint64(finfo.Size()) } } s.m.Lock() totPersists := s.totPersists totCompactions := s.totCompactions totCompactionsPartial := s.totCompactionsPartial numLastCompactionBeforeBytes := s.numLastCompactionBeforeBytes numLastCompactionAfterBytes := s.numLastCompactionAfterBytes totCompactionDecreaseBytes := s.totCompactionDecreaseBytes totCompactionIncreaseBytes := s.totCompactionIncreaseBytes maxCompactionDecreaseBytes := s.maxCompactionDecreaseBytes maxCompactionIncreaseBytes := s.maxCompactionIncreaseBytes totCompactionBeforeBytes := s.totCompactionBeforeBytes totCompactionWrittenBytes := s.totCompactionWrittenBytes s.m.Unlock() footer, err := s.snapshot() if err != nil { return nil, err } var numSegments uint64 if footer != nil { footer.m.Lock() if footer.ss != nil { numSegments = uint64(len(footer.ss.a)) } footer.m.Unlock() } footer.Close() files, numFilesOpen := s.allFiles() return map[string]interface{}{ "num_bytes_used_disk": numBytesUsedDisk, "total_persists": totPersists, "total_compactions": totCompactions, "total_compactions_partial": totCompactionsPartial, "total_compaction_before_bytes": totCompactionBeforeBytes, "total_compaction_written_bytes": totCompactionWrittenBytes, "num_segments": numSegments, "num_last_compaction_before_bytes": numLastCompactionBeforeBytes, "num_last_compaction_after_bytes": numLastCompactionAfterBytes, "total_compaction_decrease_bytes": totCompactionDecreaseBytes, "total_compaction_increase_bytes": totCompactionIncreaseBytes, "max_compaction_decrease_bytes": maxCompactionDecreaseBytes, "max_compaction_increase_bytes": maxCompactionIncreaseBytes, "num_files": len(files), "num_files_open": numFilesOpen, "files": files, }, nil }
[ "func", "(", "s", "*", "Store", ")", "Stats", "(", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "finfos", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "s", ".", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "numBytesUsedDisk", "uint64", "\n", "for", "_", ",", "finfo", ":=", "range", "finfos", "{", "if", "!", "finfo", ".", "IsDir", "(", ")", "{", "numBytesUsedDisk", "+=", "uint64", "(", "finfo", ".", "Size", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "s", ".", "m", ".", "Lock", "(", ")", "\n", "totPersists", ":=", "s", ".", "totPersists", "\n", "totCompactions", ":=", "s", ".", "totCompactions", "\n", "totCompactionsPartial", ":=", "s", ".", "totCompactionsPartial", "\n", "numLastCompactionBeforeBytes", ":=", "s", ".", "numLastCompactionBeforeBytes", "\n", "numLastCompactionAfterBytes", ":=", "s", ".", "numLastCompactionAfterBytes", "\n", "totCompactionDecreaseBytes", ":=", "s", ".", "totCompactionDecreaseBytes", "\n", "totCompactionIncreaseBytes", ":=", "s", ".", "totCompactionIncreaseBytes", "\n", "maxCompactionDecreaseBytes", ":=", "s", ".", "maxCompactionDecreaseBytes", "\n", "maxCompactionIncreaseBytes", ":=", "s", ".", "maxCompactionIncreaseBytes", "\n", "totCompactionBeforeBytes", ":=", "s", ".", "totCompactionBeforeBytes", "\n", "totCompactionWrittenBytes", ":=", "s", ".", "totCompactionWrittenBytes", "\n", "s", ".", "m", ".", "Unlock", "(", ")", "\n\n", "footer", ",", "err", ":=", "s", ".", "snapshot", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "numSegments", "uint64", "\n", "if", "footer", "!=", "nil", "{", "footer", ".", "m", ".", "Lock", "(", ")", "\n", "if", "footer", ".", "ss", "!=", "nil", "{", "numSegments", "=", "uint64", "(", "len", "(", "footer", ".", "ss", ".", "a", ")", ")", "\n", "}", "\n", "footer", ".", "m", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "footer", ".", "Close", "(", ")", "\n\n", "files", ",", "numFilesOpen", ":=", "s", ".", "allFiles", "(", ")", "\n\n", "return", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "numBytesUsedDisk", ",", "\"", "\"", ":", "totPersists", ",", "\"", "\"", ":", "totCompactions", ",", "\"", "\"", ":", "totCompactionsPartial", ",", "\"", "\"", ":", "totCompactionBeforeBytes", ",", "\"", "\"", ":", "totCompactionWrittenBytes", ",", "\"", "\"", ":", "numSegments", ",", "\"", "\"", ":", "numLastCompactionBeforeBytes", ",", "\"", "\"", ":", "numLastCompactionAfterBytes", ",", "\"", "\"", ":", "totCompactionDecreaseBytes", ",", "\"", "\"", ":", "totCompactionIncreaseBytes", ",", "\"", "\"", ":", "maxCompactionDecreaseBytes", ",", "\"", "\"", ":", "maxCompactionIncreaseBytes", ",", "\"", "\"", ":", "len", "(", "files", ")", ",", "\"", "\"", ":", "numFilesOpen", ",", "\"", "\"", ":", "files", ",", "}", ",", "nil", "\n", "}" ]
// Stats returns a map of stats.
[ "Stats", "returns", "a", "map", "of", "stats", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_stats.go#L21-L84
20,141
couchbase/moss
store_stats.go
Histograms
func (s *Store) Histograms() ghistogram.Histograms { histogramsSnapshot := make(ghistogram.Histograms) histogramsSnapshot.AddAll(s.histograms) return histogramsSnapshot }
go
func (s *Store) Histograms() ghistogram.Histograms { histogramsSnapshot := make(ghistogram.Histograms) histogramsSnapshot.AddAll(s.histograms) return histogramsSnapshot }
[ "func", "(", "s", "*", "Store", ")", "Histograms", "(", ")", "ghistogram", ".", "Histograms", "{", "histogramsSnapshot", ":=", "make", "(", "ghistogram", ".", "Histograms", ")", "\n", "histogramsSnapshot", ".", "AddAll", "(", "s", ".", "histograms", ")", "\n", "return", "histogramsSnapshot", "\n", "}" ]
// Histograms returns a snapshot of the histograms for this store.
[ "Histograms", "returns", "a", "snapshot", "of", "the", "histograms", "for", "this", "store", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_stats.go#L87-L91
20,142
couchbase/moss
collection.go
Close
func (m *collection) Close() error { m.fireEvent(EventKindCloseStart, 0) startTime := time.Now() defer func() { m.fireEvent(EventKindClose, time.Now().Sub(startTime)) }() atomic.AddUint64(&m.stats.TotCloseBeg, 1) m.m.Lock() m.invalidateLatestSnapshotLOCKED() close(m.stopCh) m.stackDirtyTopCond.Broadcast() // Awake all ExecuteBatch()'ers. m.stackDirtyBaseCond.Broadcast() // Awake persister. if !m.options.ReadOnly { m.m.Unlock() <-m.doneMergerCh atomic.AddUint64(&m.stats.TotCloseMergerDone, 1) <-m.donePersisterCh atomic.AddUint64(&m.stats.TotClosePersisterDone, 1) m.m.Lock() } if m.lowerLevelSnapshot != nil { atomic.AddUint64(&m.stats.TotCloseLowerLevelBeg, 1) m.lowerLevelSnapshot.Close() m.lowerLevelSnapshot = nil atomic.AddUint64(&m.stats.TotCloseLowerLevelEnd, 1) } stackDirtyTopPrev := m.stackDirtyTop m.stackDirtyTop = nil stackDirtyMidPrev := m.stackDirtyMid m.stackDirtyMid = nil stackDirtyBasePrev := m.stackDirtyBase m.stackDirtyBase = nil stackCleanPrev := m.stackClean m.stackClean = nil m.m.Unlock() stackDirtyTopPrev.Close() stackDirtyMidPrev.Close() stackDirtyBasePrev.Close() stackCleanPrev.Close() atomic.AddUint64(&m.stats.TotCloseEnd, 1) return nil }
go
func (m *collection) Close() error { m.fireEvent(EventKindCloseStart, 0) startTime := time.Now() defer func() { m.fireEvent(EventKindClose, time.Now().Sub(startTime)) }() atomic.AddUint64(&m.stats.TotCloseBeg, 1) m.m.Lock() m.invalidateLatestSnapshotLOCKED() close(m.stopCh) m.stackDirtyTopCond.Broadcast() // Awake all ExecuteBatch()'ers. m.stackDirtyBaseCond.Broadcast() // Awake persister. if !m.options.ReadOnly { m.m.Unlock() <-m.doneMergerCh atomic.AddUint64(&m.stats.TotCloseMergerDone, 1) <-m.donePersisterCh atomic.AddUint64(&m.stats.TotClosePersisterDone, 1) m.m.Lock() } if m.lowerLevelSnapshot != nil { atomic.AddUint64(&m.stats.TotCloseLowerLevelBeg, 1) m.lowerLevelSnapshot.Close() m.lowerLevelSnapshot = nil atomic.AddUint64(&m.stats.TotCloseLowerLevelEnd, 1) } stackDirtyTopPrev := m.stackDirtyTop m.stackDirtyTop = nil stackDirtyMidPrev := m.stackDirtyMid m.stackDirtyMid = nil stackDirtyBasePrev := m.stackDirtyBase m.stackDirtyBase = nil stackCleanPrev := m.stackClean m.stackClean = nil m.m.Unlock() stackDirtyTopPrev.Close() stackDirtyMidPrev.Close() stackDirtyBasePrev.Close() stackCleanPrev.Close() atomic.AddUint64(&m.stats.TotCloseEnd, 1) return nil }
[ "func", "(", "m", "*", "collection", ")", "Close", "(", ")", "error", "{", "m", ".", "fireEvent", "(", "EventKindCloseStart", ",", "0", ")", "\n", "startTime", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "func", "(", ")", "{", "m", ".", "fireEvent", "(", "EventKindClose", ",", "time", ".", "Now", "(", ")", ".", "Sub", "(", "startTime", ")", ")", "\n", "}", "(", ")", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotCloseBeg", ",", "1", ")", "\n\n", "m", ".", "m", ".", "Lock", "(", ")", "\n\n", "m", ".", "invalidateLatestSnapshotLOCKED", "(", ")", "\n\n", "close", "(", "m", ".", "stopCh", ")", "\n\n", "m", ".", "stackDirtyTopCond", ".", "Broadcast", "(", ")", "// Awake all ExecuteBatch()'ers.", "\n", "m", ".", "stackDirtyBaseCond", ".", "Broadcast", "(", ")", "// Awake persister.", "\n\n", "if", "!", "m", ".", "options", ".", "ReadOnly", "{", "m", ".", "m", ".", "Unlock", "(", ")", "\n\n", "<-", "m", ".", "doneMergerCh", "\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotCloseMergerDone", ",", "1", ")", "\n\n", "<-", "m", ".", "donePersisterCh", "\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotClosePersisterDone", ",", "1", ")", "\n\n", "m", ".", "m", ".", "Lock", "(", ")", "\n", "}", "\n\n", "if", "m", ".", "lowerLevelSnapshot", "!=", "nil", "{", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotCloseLowerLevelBeg", ",", "1", ")", "\n", "m", ".", "lowerLevelSnapshot", ".", "Close", "(", ")", "\n", "m", ".", "lowerLevelSnapshot", "=", "nil", "\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotCloseLowerLevelEnd", ",", "1", ")", "\n", "}", "\n\n", "stackDirtyTopPrev", ":=", "m", ".", "stackDirtyTop", "\n", "m", ".", "stackDirtyTop", "=", "nil", "\n\n", "stackDirtyMidPrev", ":=", "m", ".", "stackDirtyMid", "\n", "m", ".", "stackDirtyMid", "=", "nil", "\n\n", "stackDirtyBasePrev", ":=", "m", ".", "stackDirtyBase", "\n", "m", ".", "stackDirtyBase", "=", "nil", "\n\n", "stackCleanPrev", ":=", "m", ".", "stackClean", "\n", "m", ".", "stackClean", "=", "nil", "\n\n", "m", ".", "m", ".", "Unlock", "(", ")", "\n\n", "stackDirtyTopPrev", ".", "Close", "(", ")", "\n", "stackDirtyMidPrev", ".", "Close", "(", ")", "\n", "stackDirtyBasePrev", ".", "Close", "(", ")", "\n", "stackCleanPrev", ".", "Close", "(", ")", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotCloseEnd", ",", "1", ")", "\n\n", "return", "nil", "\n", "}" ]
// Close synchronously stops background goroutines.
[ "Close", "synchronously", "stops", "background", "goroutines", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L125-L184
20,143
couchbase/moss
collection.go
Snapshot
func (m *collection) Snapshot() (rv Snapshot, err error) { m.m.Lock() rv = reuseSnapshot(m.latestSnapshot) if rv == nil { // No cached snapshot. rv, err = m.newSnapshotLOCKED() if err == nil { // collection holds 1 ref count for its cached snapshot copy. m.latestSnapshot = reuseSnapshot(rv) } } m.m.Unlock() return }
go
func (m *collection) Snapshot() (rv Snapshot, err error) { m.m.Lock() rv = reuseSnapshot(m.latestSnapshot) if rv == nil { // No cached snapshot. rv, err = m.newSnapshotLOCKED() if err == nil { // collection holds 1 ref count for its cached snapshot copy. m.latestSnapshot = reuseSnapshot(rv) } } m.m.Unlock() return }
[ "func", "(", "m", "*", "collection", ")", "Snapshot", "(", ")", "(", "rv", "Snapshot", ",", "err", "error", ")", "{", "m", ".", "m", ".", "Lock", "(", ")", "\n", "rv", "=", "reuseSnapshot", "(", "m", ".", "latestSnapshot", ")", "\n", "if", "rv", "==", "nil", "{", "// No cached snapshot.", "rv", ",", "err", "=", "m", ".", "newSnapshotLOCKED", "(", ")", "\n", "if", "err", "==", "nil", "{", "// collection holds 1 ref count for its cached snapshot copy.", "m", ".", "latestSnapshot", "=", "reuseSnapshot", "(", "rv", ")", "\n", "}", "\n", "}", "\n", "m", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "\n", "}" ]
// Snapshot returns a stable snapshot of the key-value entries.
[ "Snapshot", "returns", "a", "stable", "snapshot", "of", "the", "key", "-", "value", "entries", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L214-L227
20,144
couchbase/moss
collection.go
newSnapshotLOCKED
func (m *collection) newSnapshotLOCKED() (Snapshot, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotSnapshotBeg, 1) rv, _, _, _, _ := m.snapshot(0, nil, true) // collection lock already held. atomic.AddUint64(&m.stats.TotSnapshotEnd, 1) return rv, nil }
go
func (m *collection) newSnapshotLOCKED() (Snapshot, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotSnapshotBeg, 1) rv, _, _, _, _ := m.snapshot(0, nil, true) // collection lock already held. atomic.AddUint64(&m.stats.TotSnapshotEnd, 1) return rv, nil }
[ "func", "(", "m", "*", "collection", ")", "newSnapshotLOCKED", "(", ")", "(", "Snapshot", ",", "error", ")", "{", "if", "m", ".", "isClosed", "(", ")", "{", "return", "nil", ",", "ErrClosed", "\n", "}", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotSnapshotBeg", ",", "1", ")", "\n\n", "rv", ",", "_", ",", "_", ",", "_", ",", "_", ":=", "m", ".", "snapshot", "(", "0", ",", "nil", ",", "true", ")", "// collection lock already held.", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotSnapshotEnd", ",", "1", ")", "\n\n", "return", "rv", ",", "nil", "\n", "}" ]
// newSnapshotLOCKED creates a new stable snapshot of the key-value // entries.
[ "newSnapshotLOCKED", "creates", "a", "new", "stable", "snapshot", "of", "the", "key", "-", "value", "entries", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L240-L252
20,145
couchbase/moss
collection.go
Get
func (m *collection) Get(key []byte, readOptions ReadOptions) ([]byte, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotGet, 1) val, err := m.get(key, readOptions) if err != nil { atomic.AddUint64(&m.stats.TotGetErr, 1) } return val, err }
go
func (m *collection) Get(key []byte, readOptions ReadOptions) ([]byte, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotGet, 1) val, err := m.get(key, readOptions) if err != nil { atomic.AddUint64(&m.stats.TotGetErr, 1) } return val, err }
[ "func", "(", "m", "*", "collection", ")", "Get", "(", "key", "[", "]", "byte", ",", "readOptions", "ReadOptions", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "m", ".", "isClosed", "(", ")", "{", "return", "nil", ",", "ErrClosed", "\n", "}", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotGet", ",", "1", ")", "\n\n", "val", ",", "err", ":=", "m", ".", "get", "(", "key", ",", "readOptions", ")", "\n\n", "if", "err", "!=", "nil", "{", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotGetErr", ",", "1", ")", "\n", "}", "\n\n", "return", "val", ",", "err", "\n", "}" ]
// Get retrieves a value by iterating over all the segments within // the collection, if the key is not found a nil val is returned.
[ "Get", "retrieves", "a", "value", "by", "iterating", "over", "all", "the", "segments", "within", "the", "collection", "if", "the", "key", "is", "not", "found", "a", "nil", "val", "is", "returned", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L256-L270
20,146
couchbase/moss
collection.go
NewBatch
func (m *collection) NewBatch(totalOps, totalKeyValBytes int) ( Batch, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotNewBatch, 1) atomic.AddUint64(&m.stats.TotNewBatchTotalOps, uint64(totalOps)) atomic.AddUint64(&m.stats.TotNewBatchTotalKeyValBytes, uint64(totalKeyValBytes)) return newBatch(m, BatchOptions{totalOps, totalKeyValBytes}) }
go
func (m *collection) NewBatch(totalOps, totalKeyValBytes int) ( Batch, error) { if m.isClosed() { return nil, ErrClosed } atomic.AddUint64(&m.stats.TotNewBatch, 1) atomic.AddUint64(&m.stats.TotNewBatchTotalOps, uint64(totalOps)) atomic.AddUint64(&m.stats.TotNewBatchTotalKeyValBytes, uint64(totalKeyValBytes)) return newBatch(m, BatchOptions{totalOps, totalKeyValBytes}) }
[ "func", "(", "m", "*", "collection", ")", "NewBatch", "(", "totalOps", ",", "totalKeyValBytes", "int", ")", "(", "Batch", ",", "error", ")", "{", "if", "m", ".", "isClosed", "(", ")", "{", "return", "nil", ",", "ErrClosed", "\n", "}", "\n\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotNewBatch", ",", "1", ")", "\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotNewBatchTotalOps", ",", "uint64", "(", "totalOps", ")", ")", "\n", "atomic", ".", "AddUint64", "(", "&", "m", ".", "stats", ".", "TotNewBatchTotalKeyValBytes", ",", "uint64", "(", "totalKeyValBytes", ")", ")", "\n\n", "return", "newBatch", "(", "m", ",", "BatchOptions", "{", "totalOps", ",", "totalKeyValBytes", "}", ")", "\n", "}" ]
// NewBatch returns a new Batch instance with hinted amount of // resources expected to be required.
[ "NewBatch", "returns", "a", "new", "Batch", "instance", "with", "hinted", "amount", "of", "resources", "expected", "to", "be", "required", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L274-L285
20,147
couchbase/moss
collection.go
appendChildLLSnapshot
func (m *collection) appendChildLLSnapshot(dst *segmentStack, src Snapshot) *segmentStack { if m.incarNum != 0 { dst.lowerLevelSnapshot = NewSnapshotWrapper(src, nil) } for cName, childCollection := range m.childCollections { dstChildStack := childCollection.getOrInitChildStack(dst, cName) var childSnap Snapshot if src != nil { childSnap, _ = src.ChildCollectionSnapshot(cName) } dst.childSegStacks[cName] = childCollection.appendChildLLSnapshot(dstChildStack, childSnap) } return dst }
go
func (m *collection) appendChildLLSnapshot(dst *segmentStack, src Snapshot) *segmentStack { if m.incarNum != 0 { dst.lowerLevelSnapshot = NewSnapshotWrapper(src, nil) } for cName, childCollection := range m.childCollections { dstChildStack := childCollection.getOrInitChildStack(dst, cName) var childSnap Snapshot if src != nil { childSnap, _ = src.ChildCollectionSnapshot(cName) } dst.childSegStacks[cName] = childCollection.appendChildLLSnapshot(dstChildStack, childSnap) } return dst }
[ "func", "(", "m", "*", "collection", ")", "appendChildLLSnapshot", "(", "dst", "*", "segmentStack", ",", "src", "Snapshot", ")", "*", "segmentStack", "{", "if", "m", ".", "incarNum", "!=", "0", "{", "dst", ".", "lowerLevelSnapshot", "=", "NewSnapshotWrapper", "(", "src", ",", "nil", ")", "\n", "}", "\n\n", "for", "cName", ",", "childCollection", ":=", "range", "m", ".", "childCollections", "{", "dstChildStack", ":=", "childCollection", ".", "getOrInitChildStack", "(", "dst", ",", "cName", ")", "\n\n", "var", "childSnap", "Snapshot", "\n", "if", "src", "!=", "nil", "{", "childSnap", ",", "_", "=", "src", ".", "ChildCollectionSnapshot", "(", "cName", ")", "\n", "}", "\n\n", "dst", ".", "childSegStacks", "[", "cName", "]", "=", "childCollection", ".", "appendChildLLSnapshot", "(", "dstChildStack", ",", "childSnap", ")", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// appendChildLLSnapshot recursively appends lower level child snapshots.
[ "appendChildLLSnapshot", "recursively", "appends", "lower", "level", "child", "snapshots", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L708-L727
20,148
couchbase/moss
collection.go
appendChildStacks
func (m *collection) appendChildStacks(dst, src *segmentStack) *segmentStack { if src == nil { return dst } dst.a = append(dst.a, src.a...) for cName, srcChildStack := range src.childSegStacks { childCollection, exists := m.childCollections[cName] if !exists || // This child collection was dropped recently, OR // this child collection was recreated quickly. childCollection.incarNum != srcChildStack.incarNum { continue } dstChildStack := childCollection.getOrInitChildStack(dst, cName) dst.childSegStacks[cName] = childCollection.appendChildStacks(dstChildStack, srcChildStack) } return dst }
go
func (m *collection) appendChildStacks(dst, src *segmentStack) *segmentStack { if src == nil { return dst } dst.a = append(dst.a, src.a...) for cName, srcChildStack := range src.childSegStacks { childCollection, exists := m.childCollections[cName] if !exists || // This child collection was dropped recently, OR // this child collection was recreated quickly. childCollection.incarNum != srcChildStack.incarNum { continue } dstChildStack := childCollection.getOrInitChildStack(dst, cName) dst.childSegStacks[cName] = childCollection.appendChildStacks(dstChildStack, srcChildStack) } return dst }
[ "func", "(", "m", "*", "collection", ")", "appendChildStacks", "(", "dst", ",", "src", "*", "segmentStack", ")", "*", "segmentStack", "{", "if", "src", "==", "nil", "{", "return", "dst", "\n", "}", "\n\n", "dst", ".", "a", "=", "append", "(", "dst", ".", "a", ",", "src", ".", "a", "...", ")", "\n\n", "for", "cName", ",", "srcChildStack", ":=", "range", "src", ".", "childSegStacks", "{", "childCollection", ",", "exists", ":=", "m", ".", "childCollections", "[", "cName", "]", "\n", "if", "!", "exists", "||", "// This child collection was dropped recently, OR", "// this child collection was recreated quickly.", "childCollection", ".", "incarNum", "!=", "srcChildStack", ".", "incarNum", "{", "continue", "\n", "}", "\n\n", "dstChildStack", ":=", "childCollection", ".", "getOrInitChildStack", "(", "dst", ",", "cName", ")", "\n\n", "dst", ".", "childSegStacks", "[", "cName", "]", "=", "childCollection", ".", "appendChildStacks", "(", "dstChildStack", ",", "srcChildStack", ")", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// appendChildStacks recursively appends child segment stacks.
[ "appendChildStacks", "recursively", "appends", "child", "segment", "stacks", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/collection.go#L730-L752
20,149
couchbase/moss
segment.go
nextDelta
func (c *segmentCursor) nextDelta(delta int) error { c.curr += delta if c.curr >= c.end { return ErrIteratorDone } return nil }
go
func (c *segmentCursor) nextDelta(delta int) error { c.curr += delta if c.curr >= c.end { return ErrIteratorDone } return nil }
[ "func", "(", "c", "*", "segmentCursor", ")", "nextDelta", "(", "delta", "int", ")", "error", "{", "c", ".", "curr", "+=", "delta", "\n", "if", "c", ".", "curr", ">=", "c", ".", "end", "{", "return", "ErrIteratorDone", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// nextDelta advances the cursor position by 'delta' steps.
[ "nextDelta", "advances", "the", "cursor", "position", "by", "delta", "steps", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment.go#L370-L376
20,150
couchbase/moss
segment.go
currentKey
func (c *segmentCursor) currentKey() (idx int, key []byte) { if c.curr >= c.start && c.curr < c.end { idx = c.curr _, key, _ = c.s.getOperationKeyVal(c.curr) } return }
go
func (c *segmentCursor) currentKey() (idx int, key []byte) { if c.curr >= c.start && c.curr < c.end { idx = c.curr _, key, _ = c.s.getOperationKeyVal(c.curr) } return }
[ "func", "(", "c", "*", "segmentCursor", ")", "currentKey", "(", ")", "(", "idx", "int", ",", "key", "[", "]", "byte", ")", "{", "if", "c", ".", "curr", ">=", "c", ".", "start", "&&", "c", ".", "curr", "<", "c", ".", "end", "{", "idx", "=", "c", ".", "curr", "\n", "_", ",", "key", ",", "_", "=", "c", ".", "s", ".", "getOperationKeyVal", "(", "c", ".", "curr", ")", "\n", "}", "\n", "return", "\n", "}" ]
// currentKey returns the array position and the key pointed to by the cursor.
[ "currentKey", "returns", "the", "array", "position", "and", "the", "key", "pointed", "to", "by", "the", "cursor", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment.go#L379-L385
20,151
couchbase/moss
segment.go
searchIndex
func (a *segment) searchIndex(key []byte) (int, int) { if a.index != nil { // Check the in-memory index for a more accurate window. return a.index.lookup(key) } return 0, a.Len() }
go
func (a *segment) searchIndex(key []byte) (int, int) { if a.index != nil { // Check the in-memory index for a more accurate window. return a.index.lookup(key) } return 0, a.Len() }
[ "func", "(", "a", "*", "segment", ")", "searchIndex", "(", "key", "[", "]", "byte", ")", "(", "int", ",", "int", ")", "{", "if", "a", ".", "index", "!=", "nil", "{", "// Check the in-memory index for a more accurate window.", "return", "a", ".", "index", ".", "lookup", "(", "key", ")", "\n", "}", "\n\n", "return", "0", ",", "a", ".", "Len", "(", ")", "\n", "}" ]
// Searches for the key within the in-memory index of the segment // if available. Returns left and right positions between which // the key likely exists.
[ "Searches", "for", "the", "key", "within", "the", "in", "-", "memory", "index", "of", "the", "segment", "if", "available", ".", "Returns", "left", "and", "right", "positions", "between", "which", "the", "key", "likely", "exists", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment.go#L417-L424
20,152
couchbase/moss
util_merge.go
FullMerge
func (mo *MergeOperatorStringAppend) FullMerge(key, existingValue []byte, operands [][]byte) ([]byte, bool) { mo.m.Lock() mo.numFull++ mo.m.Unlock() s := string(existingValue) for _, operand := range operands { s = s + mo.Sep + string(operand) } return []byte(s), true }
go
func (mo *MergeOperatorStringAppend) FullMerge(key, existingValue []byte, operands [][]byte) ([]byte, bool) { mo.m.Lock() mo.numFull++ mo.m.Unlock() s := string(existingValue) for _, operand := range operands { s = s + mo.Sep + string(operand) } return []byte(s), true }
[ "func", "(", "mo", "*", "MergeOperatorStringAppend", ")", "FullMerge", "(", "key", ",", "existingValue", "[", "]", "byte", ",", "operands", "[", "]", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "bool", ")", "{", "mo", ".", "m", ".", "Lock", "(", ")", "\n", "mo", ".", "numFull", "++", "\n", "mo", ".", "m", ".", "Unlock", "(", ")", "\n\n", "s", ":=", "string", "(", "existingValue", ")", "\n", "for", "_", ",", "operand", ":=", "range", "operands", "{", "s", "=", "s", "+", "mo", ".", "Sep", "+", "string", "(", "operand", ")", "\n", "}", "\n", "return", "[", "]", "byte", "(", "s", ")", ",", "true", "\n", "}" ]
// FullMerge performs the full merge of a string append operation
[ "FullMerge", "performs", "the", "full", "merge", "of", "a", "string", "append", "operation" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/util_merge.go#L33-L44
20,153
couchbase/moss
util_merge.go
PartialMerge
func (mo *MergeOperatorStringAppend) PartialMerge(key, leftOperand, rightOperand []byte) ([]byte, bool) { mo.m.Lock() mo.numPartial++ mo.m.Unlock() return []byte(string(leftOperand) + mo.Sep + string(rightOperand)), true }
go
func (mo *MergeOperatorStringAppend) PartialMerge(key, leftOperand, rightOperand []byte) ([]byte, bool) { mo.m.Lock() mo.numPartial++ mo.m.Unlock() return []byte(string(leftOperand) + mo.Sep + string(rightOperand)), true }
[ "func", "(", "mo", "*", "MergeOperatorStringAppend", ")", "PartialMerge", "(", "key", ",", "leftOperand", ",", "rightOperand", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "bool", ")", "{", "mo", ".", "m", ".", "Lock", "(", ")", "\n", "mo", ".", "numPartial", "++", "\n", "mo", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "[", "]", "byte", "(", "string", "(", "leftOperand", ")", "+", "mo", ".", "Sep", "+", "string", "(", "rightOperand", ")", ")", ",", "true", "\n", "}" ]
// PartialMerge performs the partial merge of a string append operation
[ "PartialMerge", "performs", "the", "partial", "merge", "of", "a", "string", "append", "operation" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/util_merge.go#L47-L54
20,154
couchbase/moss
file.go
OnAfterClose
func (r *FileRef) OnAfterClose(cb func()) { r.m.Lock() r.afterCloseCallbacks = append(r.afterCloseCallbacks, cb) r.m.Unlock() }
go
func (r *FileRef) OnAfterClose(cb func()) { r.m.Lock() r.afterCloseCallbacks = append(r.afterCloseCallbacks, cb) r.m.Unlock() }
[ "func", "(", "r", "*", "FileRef", ")", "OnAfterClose", "(", "cb", "func", "(", ")", ")", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "r", ".", "afterCloseCallbacks", "=", "append", "(", "r", ".", "afterCloseCallbacks", ",", "cb", ")", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// OnAfterClose registers event callback func's that are invoked after the // file is closed.
[ "OnAfterClose", "registers", "event", "callback", "func", "s", "that", "are", "invoked", "after", "the", "file", "is", "closed", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/file.go#L70-L74
20,155
couchbase/moss
file.go
AddRef
func (r *FileRef) AddRef() File { if r == nil { return nil } r.m.Lock() r.refs++ file := r.file r.m.Unlock() return file }
go
func (r *FileRef) AddRef() File { if r == nil { return nil } r.m.Lock() r.refs++ file := r.file r.m.Unlock() return file }
[ "func", "(", "r", "*", "FileRef", ")", "AddRef", "(", ")", "File", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "r", ".", "m", ".", "Lock", "(", ")", "\n", "r", ".", "refs", "++", "\n", "file", ":=", "r", ".", "file", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "file", "\n", "}" ]
// AddRef increases the ref-count on the file ref.
[ "AddRef", "increases", "the", "ref", "-", "count", "on", "the", "file", "ref", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/file.go#L77-L88
20,156
couchbase/moss
file.go
DecRef
func (r *FileRef) DecRef() (err error) { if r == nil { return nil } r.m.Lock() r.refs-- if r.refs <= 0 { for _, cb := range r.beforeCloseCallbacks { cb() } r.beforeCloseCallbacks = nil err = r.file.Close() for _, cb := range r.afterCloseCallbacks { cb() } r.afterCloseCallbacks = nil r.file = nil } r.m.Unlock() return err }
go
func (r *FileRef) DecRef() (err error) { if r == nil { return nil } r.m.Lock() r.refs-- if r.refs <= 0 { for _, cb := range r.beforeCloseCallbacks { cb() } r.beforeCloseCallbacks = nil err = r.file.Close() for _, cb := range r.afterCloseCallbacks { cb() } r.afterCloseCallbacks = nil r.file = nil } r.m.Unlock() return err }
[ "func", "(", "r", "*", "FileRef", ")", "DecRef", "(", ")", "(", "err", "error", ")", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "r", ".", "m", ".", "Lock", "(", ")", "\n\n", "r", ".", "refs", "--", "\n", "if", "r", ".", "refs", "<=", "0", "{", "for", "_", ",", "cb", ":=", "range", "r", ".", "beforeCloseCallbacks", "{", "cb", "(", ")", "\n", "}", "\n", "r", ".", "beforeCloseCallbacks", "=", "nil", "\n\n", "err", "=", "r", ".", "file", ".", "Close", "(", ")", "\n\n", "for", "_", ",", "cb", ":=", "range", "r", ".", "afterCloseCallbacks", "{", "cb", "(", ")", "\n", "}", "\n", "r", ".", "afterCloseCallbacks", "=", "nil", "\n\n", "r", ".", "file", "=", "nil", "\n", "}", "\n\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "err", "\n", "}" ]
// DecRef decreases the ref-count on the file ref, and closing the // underlying file when the ref-count reaches zero.
[ "DecRef", "decreases", "the", "ref", "-", "count", "on", "the", "file", "ref", "and", "closing", "the", "underlying", "file", "when", "the", "ref", "-", "count", "reaches", "zero", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/file.go#L92-L119
20,157
couchbase/moss
file.go
FetchRefCount
func (r *FileRef) FetchRefCount() int { if r == nil { return 0 } r.m.Lock() ref := r.refs r.m.Unlock() return ref }
go
func (r *FileRef) FetchRefCount() int { if r == nil { return 0 } r.m.Lock() ref := r.refs r.m.Unlock() return ref }
[ "func", "(", "r", "*", "FileRef", ")", "FetchRefCount", "(", ")", "int", "{", "if", "r", "==", "nil", "{", "return", "0", "\n", "}", "\n\n", "r", ".", "m", ".", "Lock", "(", ")", "\n", "ref", ":=", "r", ".", "refs", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n\n", "return", "ref", "\n", "}" ]
// FetchRefCount fetches the ref-count on the file ref.
[ "FetchRefCount", "fetches", "the", "ref", "-", "count", "on", "the", "file", "ref", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/file.go#L129-L139
20,158
couchbase/moss
file.go
ToOsFile
func ToOsFile(f File) *os.File { if osFile, ok := f.(*os.File); ok { return osFile } if osFile2, ok := f.(OsFile); ok { return osFile2.OsFile() } return nil }
go
func ToOsFile(f File) *os.File { if osFile, ok := f.(*os.File); ok { return osFile } if osFile2, ok := f.(OsFile); ok { return osFile2.OsFile() } return nil }
[ "func", "ToOsFile", "(", "f", "File", ")", "*", "os", ".", "File", "{", "if", "osFile", ",", "ok", ":=", "f", ".", "(", "*", "os", ".", "File", ")", ";", "ok", "{", "return", "osFile", "\n", "}", "\n", "if", "osFile2", ",", "ok", ":=", "f", ".", "(", "OsFile", ")", ";", "ok", "{", "return", "osFile2", ".", "OsFile", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ToOsFile provides the underlying os.File for a File, if available.
[ "ToOsFile", "provides", "the", "underlying", "os", ".", "File", "for", "a", "File", "if", "available", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/file.go#L149-L157
20,159
couchbase/moss
segment_index.go
add
func (s *segmentKeysIndex) add(keyIdx int, key []byte) bool { if s.numKeys >= s.numIndexableKeys { // All keys that can be indexed already have been, // return false indicating that there's no room for // anymore. return false } if len(key) > (len(s.data) - s.numKeyBytes) { // No room for any more keys. return false } if keyIdx%(s.hop) != 0 { // Key does not satisfy the hop condition. return true } s.offsets[s.numKeys] = uint32(s.numKeyBytes) copy(s.data[s.numKeyBytes:], key) s.numKeys++ s.numKeyBytes += len(key) return true }
go
func (s *segmentKeysIndex) add(keyIdx int, key []byte) bool { if s.numKeys >= s.numIndexableKeys { // All keys that can be indexed already have been, // return false indicating that there's no room for // anymore. return false } if len(key) > (len(s.data) - s.numKeyBytes) { // No room for any more keys. return false } if keyIdx%(s.hop) != 0 { // Key does not satisfy the hop condition. return true } s.offsets[s.numKeys] = uint32(s.numKeyBytes) copy(s.data[s.numKeyBytes:], key) s.numKeys++ s.numKeyBytes += len(key) return true }
[ "func", "(", "s", "*", "segmentKeysIndex", ")", "add", "(", "keyIdx", "int", ",", "key", "[", "]", "byte", ")", "bool", "{", "if", "s", ".", "numKeys", ">=", "s", ".", "numIndexableKeys", "{", "// All keys that can be indexed already have been,", "// return false indicating that there's no room for", "// anymore.", "return", "false", "\n", "}", "\n\n", "if", "len", "(", "key", ")", ">", "(", "len", "(", "s", ".", "data", ")", "-", "s", ".", "numKeyBytes", ")", "{", "// No room for any more keys.", "return", "false", "\n", "}", "\n\n", "if", "keyIdx", "%", "(", "s", ".", "hop", ")", "!=", "0", "{", "// Key does not satisfy the hop condition.", "return", "true", "\n", "}", "\n\n", "s", ".", "offsets", "[", "s", ".", "numKeys", "]", "=", "uint32", "(", "s", ".", "numKeyBytes", ")", "\n", "copy", "(", "s", ".", "data", "[", "s", ".", "numKeyBytes", ":", "]", ",", "key", ")", "\n", "s", ".", "numKeys", "++", "\n", "s", ".", "numKeyBytes", "+=", "len", "(", "key", ")", "\n\n", "return", "true", "\n", "}" ]
// Adds a qualified entry to the index. Returns true if space // still available, false otherwise.
[ "Adds", "a", "qualified", "entry", "to", "the", "index", ".", "Returns", "true", "if", "space", "still", "available", "false", "otherwise", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment_index.go#L72-L96
20,160
couchbase/moss
segment_index.go
lookup
func (s *segmentKeysIndex) lookup(key []byte) (leftPos int, rightPos int) { i, j := 0, s.numKeys if i == j || s.numKeys < 2 { // The index either wasn't used or isn't of any use. rightPos = s.srcKeyCount return } // If key smaller than the first key, return early. keyStart := s.offsets[0] keyEnd := s.offsets[1] cmp := bytes.Compare(key, s.data[keyStart:keyEnd]) if cmp < 0 { return } indexOfLastKey := s.numKeys - 1 // If key larger than last key, return early. keyStart = s.offsets[indexOfLastKey] keyEnd = uint32(s.numKeyBytes) cmp = bytes.Compare(s.data[keyStart:keyEnd], key) if cmp < 0 { leftPos = (indexOfLastKey) * s.hop rightPos = s.srcKeyCount return } for i < j { h := i + (j-i)/2 keyStart = s.offsets[h] if h < indexOfLastKey { keyEnd = s.offsets[h+1] } else { keyEnd = uint32(s.numKeyBytes) } cmp = bytes.Compare(s.data[keyStart:keyEnd], key) if cmp == 0 { leftPos = h * s.hop rightPos = leftPos + 1 return // Direct hit. } else if cmp < 0 { if i == h { break } i = h } else { j = h } } leftPos = i * s.hop rightPos = j * s.hop return }
go
func (s *segmentKeysIndex) lookup(key []byte) (leftPos int, rightPos int) { i, j := 0, s.numKeys if i == j || s.numKeys < 2 { // The index either wasn't used or isn't of any use. rightPos = s.srcKeyCount return } // If key smaller than the first key, return early. keyStart := s.offsets[0] keyEnd := s.offsets[1] cmp := bytes.Compare(key, s.data[keyStart:keyEnd]) if cmp < 0 { return } indexOfLastKey := s.numKeys - 1 // If key larger than last key, return early. keyStart = s.offsets[indexOfLastKey] keyEnd = uint32(s.numKeyBytes) cmp = bytes.Compare(s.data[keyStart:keyEnd], key) if cmp < 0 { leftPos = (indexOfLastKey) * s.hop rightPos = s.srcKeyCount return } for i < j { h := i + (j-i)/2 keyStart = s.offsets[h] if h < indexOfLastKey { keyEnd = s.offsets[h+1] } else { keyEnd = uint32(s.numKeyBytes) } cmp = bytes.Compare(s.data[keyStart:keyEnd], key) if cmp == 0 { leftPos = h * s.hop rightPos = leftPos + 1 return // Direct hit. } else if cmp < 0 { if i == h { break } i = h } else { j = h } } leftPos = i * s.hop rightPos = j * s.hop return }
[ "func", "(", "s", "*", "segmentKeysIndex", ")", "lookup", "(", "key", "[", "]", "byte", ")", "(", "leftPos", "int", ",", "rightPos", "int", ")", "{", "i", ",", "j", ":=", "0", ",", "s", ".", "numKeys", "\n\n", "if", "i", "==", "j", "||", "s", ".", "numKeys", "<", "2", "{", "// The index either wasn't used or isn't of any use.", "rightPos", "=", "s", ".", "srcKeyCount", "\n", "return", "\n", "}", "\n\n", "// If key smaller than the first key, return early.", "keyStart", ":=", "s", ".", "offsets", "[", "0", "]", "\n", "keyEnd", ":=", "s", ".", "offsets", "[", "1", "]", "\n", "cmp", ":=", "bytes", ".", "Compare", "(", "key", ",", "s", ".", "data", "[", "keyStart", ":", "keyEnd", "]", ")", "\n", "if", "cmp", "<", "0", "{", "return", "\n", "}", "\n\n", "indexOfLastKey", ":=", "s", ".", "numKeys", "-", "1", "\n\n", "// If key larger than last key, return early.", "keyStart", "=", "s", ".", "offsets", "[", "indexOfLastKey", "]", "\n", "keyEnd", "=", "uint32", "(", "s", ".", "numKeyBytes", ")", "\n", "cmp", "=", "bytes", ".", "Compare", "(", "s", ".", "data", "[", "keyStart", ":", "keyEnd", "]", ",", "key", ")", "\n", "if", "cmp", "<", "0", "{", "leftPos", "=", "(", "indexOfLastKey", ")", "*", "s", ".", "hop", "\n", "rightPos", "=", "s", ".", "srcKeyCount", "\n", "return", "\n", "}", "\n\n", "for", "i", "<", "j", "{", "h", ":=", "i", "+", "(", "j", "-", "i", ")", "/", "2", "\n\n", "keyStart", "=", "s", ".", "offsets", "[", "h", "]", "\n", "if", "h", "<", "indexOfLastKey", "{", "keyEnd", "=", "s", ".", "offsets", "[", "h", "+", "1", "]", "\n", "}", "else", "{", "keyEnd", "=", "uint32", "(", "s", ".", "numKeyBytes", ")", "\n", "}", "\n\n", "cmp", "=", "bytes", ".", "Compare", "(", "s", ".", "data", "[", "keyStart", ":", "keyEnd", "]", ",", "key", ")", "\n", "if", "cmp", "==", "0", "{", "leftPos", "=", "h", "*", "s", ".", "hop", "\n", "rightPos", "=", "leftPos", "+", "1", "\n", "return", "// Direct hit.", "\n", "}", "else", "if", "cmp", "<", "0", "{", "if", "i", "==", "h", "{", "break", "\n", "}", "\n", "i", "=", "h", "\n", "}", "else", "{", "j", "=", "h", "\n", "}", "\n", "}", "\n\n", "leftPos", "=", "i", "*", "s", ".", "hop", "\n", "rightPos", "=", "j", "*", "s", ".", "hop", "\n\n", "return", "\n", "}" ]
// Fetches the range of offsets between which the key exists, // if present at all. The returned leftPos and rightPos can // directly be used as the left and right extreme cursors // while binary searching over the source segment.
[ "Fetches", "the", "range", "of", "offsets", "between", "which", "the", "key", "exists", "if", "present", "at", "all", ".", "The", "returned", "leftPos", "and", "rightPos", "can", "directly", "be", "used", "as", "the", "left", "and", "right", "extreme", "cursors", "while", "binary", "searching", "over", "the", "source", "segment", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment_index.go#L102-L160
20,161
couchbase/moss
segment_stack.go
AddTo
func (sss *SegmentStackStats) AddTo(dest *SegmentStackStats) { if sss == nil { return } dest.CurOps += sss.CurOps dest.CurBytes += sss.CurBytes dest.CurSegments += sss.CurSegments }
go
func (sss *SegmentStackStats) AddTo(dest *SegmentStackStats) { if sss == nil { return } dest.CurOps += sss.CurOps dest.CurBytes += sss.CurBytes dest.CurSegments += sss.CurSegments }
[ "func", "(", "sss", "*", "SegmentStackStats", ")", "AddTo", "(", "dest", "*", "SegmentStackStats", ")", "{", "if", "sss", "==", "nil", "{", "return", "\n", "}", "\n\n", "dest", ".", "CurOps", "+=", "sss", ".", "CurOps", "\n", "dest", ".", "CurBytes", "+=", "sss", ".", "CurBytes", "\n", "dest", ".", "CurSegments", "+=", "sss", ".", "CurSegments", "\n", "}" ]
// AddTo adds the values from this SegmentStackStats to the dest // SegmentStackStats.
[ "AddTo", "adds", "the", "values", "from", "this", "SegmentStackStats", "to", "the", "dest", "SegmentStackStats", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment_stack.go#L177-L185
20,162
couchbase/moss
segment_stack.go
Stats
func (ss *segmentStack) Stats() *SegmentStackStats { rv := &SegmentStackStats{CurSegments: uint64(len(ss.a))} for _, seg := range ss.a { rv.CurOps += uint64(seg.Len()) nk, nv := seg.NumKeyValBytes() rv.CurBytes += nk + nv } return rv }
go
func (ss *segmentStack) Stats() *SegmentStackStats { rv := &SegmentStackStats{CurSegments: uint64(len(ss.a))} for _, seg := range ss.a { rv.CurOps += uint64(seg.Len()) nk, nv := seg.NumKeyValBytes() rv.CurBytes += nk + nv } return rv }
[ "func", "(", "ss", "*", "segmentStack", ")", "Stats", "(", ")", "*", "SegmentStackStats", "{", "rv", ":=", "&", "SegmentStackStats", "{", "CurSegments", ":", "uint64", "(", "len", "(", "ss", ".", "a", ")", ")", "}", "\n", "for", "_", ",", "seg", ":=", "range", "ss", ".", "a", "{", "rv", ".", "CurOps", "+=", "uint64", "(", "seg", ".", "Len", "(", ")", ")", "\n", "nk", ",", "nv", ":=", "seg", ".", "NumKeyValBytes", "(", ")", "\n", "rv", ".", "CurBytes", "+=", "nk", "+", "nv", "\n", "}", "\n", "return", "rv", "\n", "}" ]
// Stats returns the stats for this segment stack.
[ "Stats", "returns", "the", "stats", "for", "this", "segment", "stack", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment_stack.go#L188-L196
20,163
couchbase/moss
segment_stack.go
ensureFullySorted
func (ss *segmentStack) ensureFullySorted() { ss.ensureSorted(0, len(ss.a)-1) for _, childSnapshot := range ss.childSegStacks { childSnapshot.ensureFullySorted() } }
go
func (ss *segmentStack) ensureFullySorted() { ss.ensureSorted(0, len(ss.a)-1) for _, childSnapshot := range ss.childSegStacks { childSnapshot.ensureFullySorted() } }
[ "func", "(", "ss", "*", "segmentStack", ")", "ensureFullySorted", "(", ")", "{", "ss", ".", "ensureSorted", "(", "0", ",", "len", "(", "ss", ".", "a", ")", "-", "1", ")", "\n", "for", "_", ",", "childSnapshot", ":=", "range", "ss", ".", "childSegStacks", "{", "childSnapshot", ".", "ensureFullySorted", "(", ")", "\n", "}", "\n", "}" ]
// ensureFullySorted recursively ensures that all child segmentStacks // are sorted from 0 to end.
[ "ensureFullySorted", "recursively", "ensures", "that", "all", "child", "segmentStacks", "are", "sorted", "from", "0", "to", "end", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/segment_stack.go#L226-L231
20,164
couchbase/moss
wrap.go
Get
func (w *SnapshotWrapper) Get(key []byte, readOptions ReadOptions) ( []byte, error) { return w.ss.Get(key, readOptions) }
go
func (w *SnapshotWrapper) Get(key []byte, readOptions ReadOptions) ( []byte, error) { return w.ss.Get(key, readOptions) }
[ "func", "(", "w", "*", "SnapshotWrapper", ")", "Get", "(", "key", "[", "]", "byte", ",", "readOptions", "ReadOptions", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "w", ".", "ss", ".", "Get", "(", "key", ",", "readOptions", ")", "\n", "}" ]
// Get returns the key from the underlying snapshot.
[ "Get", "returns", "the", "key", "from", "the", "underlying", "snapshot", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/wrap.go#L93-L96
20,165
couchbase/moss
wrap.go
StartIterator
func (w *SnapshotWrapper) StartIterator( startKeyInclusive, endKeyExclusive []byte, iteratorOptions IteratorOptions, ) (Iterator, error) { return w.ss.StartIterator(startKeyInclusive, endKeyExclusive, iteratorOptions) }
go
func (w *SnapshotWrapper) StartIterator( startKeyInclusive, endKeyExclusive []byte, iteratorOptions IteratorOptions, ) (Iterator, error) { return w.ss.StartIterator(startKeyInclusive, endKeyExclusive, iteratorOptions) }
[ "func", "(", "w", "*", "SnapshotWrapper", ")", "StartIterator", "(", "startKeyInclusive", ",", "endKeyExclusive", "[", "]", "byte", ",", "iteratorOptions", "IteratorOptions", ",", ")", "(", "Iterator", ",", "error", ")", "{", "return", "w", ".", "ss", ".", "StartIterator", "(", "startKeyInclusive", ",", "endKeyExclusive", ",", "iteratorOptions", ")", "\n", "}" ]
// StartIterator initiates a start iterator over the underlying snapshot.
[ "StartIterator", "initiates", "a", "start", "iterator", "over", "the", "underlying", "snapshot", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/wrap.go#L99-L105
20,166
couchbase/moss
store_api.go
AddRef
func (slocs SegmentLocs) AddRef() { for _, sloc := range slocs { if sloc.mref != nil { sloc.mref.AddRef() } } }
go
func (slocs SegmentLocs) AddRef() { for _, sloc := range slocs { if sloc.mref != nil { sloc.mref.AddRef() } } }
[ "func", "(", "slocs", "SegmentLocs", ")", "AddRef", "(", ")", "{", "for", "_", ",", "sloc", ":=", "range", "slocs", "{", "if", "sloc", ".", "mref", "!=", "nil", "{", "sloc", ".", "mref", ".", "AddRef", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// AddRef increases the ref count on each SegmentLoc in this SegmentLocs
[ "AddRef", "increases", "the", "ref", "count", "on", "each", "SegmentLoc", "in", "this", "SegmentLocs" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_api.go#L200-L206
20,167
couchbase/moss
store_api.go
DecRef
func (slocs SegmentLocs) DecRef() { for _, sloc := range slocs { if sloc.mref != nil { sloc.mref.DecRef() } } }
go
func (slocs SegmentLocs) DecRef() { for _, sloc := range slocs { if sloc.mref != nil { sloc.mref.DecRef() } } }
[ "func", "(", "slocs", "SegmentLocs", ")", "DecRef", "(", ")", "{", "for", "_", ",", "sloc", ":=", "range", "slocs", "{", "if", "sloc", ".", "mref", "!=", "nil", "{", "sloc", ".", "mref", ".", "DecRef", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// DecRef decreases the ref count on each SegmentLoc in this SegmentLocs
[ "DecRef", "decreases", "the", "ref", "count", "on", "each", "SegmentLoc", "in", "this", "SegmentLocs" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_api.go#L209-L215
20,168
couchbase/moss
store_api.go
AddRef
func (s *Store) AddRef() { s.m.Lock() s.refs++ s.m.Unlock() }
go
func (s *Store) AddRef() { s.m.Lock() s.refs++ s.m.Unlock() }
[ "func", "(", "s", "*", "Store", ")", "AddRef", "(", ")", "{", "s", ".", "m", ".", "Lock", "(", ")", "\n", "s", ".", "refs", "++", "\n", "s", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// AddRef increases the ref count on this store
[ "AddRef", "increases", "the", "ref", "count", "on", "this", "store" ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_api.go#L280-L284
20,169
couchbase/moss
store_api.go
Close
func (s *Store) Close() error { s.m.Lock() defer s.m.Unlock() s.refs-- if s.refs > 0 || s.footer == nil { return nil } footer := s.footer s.footer = nil return footer.Close() }
go
func (s *Store) Close() error { s.m.Lock() defer s.m.Unlock() s.refs-- if s.refs > 0 || s.footer == nil { return nil } footer := s.footer s.footer = nil return footer.Close() }
[ "func", "(", "s", "*", "Store", ")", "Close", "(", ")", "error", "{", "s", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "m", ".", "Unlock", "(", ")", "\n\n", "s", ".", "refs", "--", "\n", "if", "s", ".", "refs", ">", "0", "||", "s", ".", "footer", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "footer", ":=", "s", ".", "footer", "\n", "s", ".", "footer", "=", "nil", "\n\n", "return", "footer", ".", "Close", "(", ")", "\n", "}" ]
// Close decreases the ref count on this store, and if the count is 0 // proceeds to actually close the store.
[ "Close", "decreases", "the", "ref", "count", "on", "this", "store", "and", "if", "the", "count", "is", "0", "proceeds", "to", "actually", "close", "the", "store", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_api.go#L288-L301
20,170
couchbase/moss
store_api.go
CloseEx
func (s *Store) CloseEx(options StoreCloseExOptions) error { if options.Abort { close(s.abortCh) } return s.Close() }
go
func (s *Store) CloseEx(options StoreCloseExOptions) error { if options.Abort { close(s.abortCh) } return s.Close() }
[ "func", "(", "s", "*", "Store", ")", "CloseEx", "(", "options", "StoreCloseExOptions", ")", "error", "{", "if", "options", ".", "Abort", "{", "close", "(", "s", ".", "abortCh", ")", "\n", "}", "\n", "return", "s", ".", "Close", "(", ")", "\n", "}" ]
// CloseEx provides more advanced closing options.
[ "CloseEx", "provides", "more", "advanced", "closing", "options", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/store_api.go#L304-L309
20,171
couchbase/moss
smat.go
delta
func delta(cb func(c *smatContext)) func(ctx smat.Context) (next smat.State, err error) { return func(ctx smat.Context) (next smat.State, err error) { c := ctx.(*smatContext) cb(c) if c.curBatch < 0 { c.curBatch = 1000 } if c.curSnapshot < 0 { c.curSnapshot = 1000 } if c.curIterator < 0 { c.curIterator = 1000 } if c.curKey < 0 { c.curKey = 1000 } return running, nil } }
go
func delta(cb func(c *smatContext)) func(ctx smat.Context) (next smat.State, err error) { return func(ctx smat.Context) (next smat.State, err error) { c := ctx.(*smatContext) cb(c) if c.curBatch < 0 { c.curBatch = 1000 } if c.curSnapshot < 0 { c.curSnapshot = 1000 } if c.curIterator < 0 { c.curIterator = 1000 } if c.curKey < 0 { c.curKey = 1000 } return running, nil } }
[ "func", "delta", "(", "cb", "func", "(", "c", "*", "smatContext", ")", ")", "func", "(", "ctx", "smat", ".", "Context", ")", "(", "next", "smat", ".", "State", ",", "err", "error", ")", "{", "return", "func", "(", "ctx", "smat", ".", "Context", ")", "(", "next", "smat", ".", "State", ",", "err", "error", ")", "{", "c", ":=", "ctx", ".", "(", "*", "smatContext", ")", "\n", "cb", "(", "c", ")", "\n", "if", "c", ".", "curBatch", "<", "0", "{", "c", ".", "curBatch", "=", "1000", "\n", "}", "\n", "if", "c", ".", "curSnapshot", "<", "0", "{", "c", ".", "curSnapshot", "=", "1000", "\n", "}", "\n", "if", "c", ".", "curIterator", "<", "0", "{", "c", ".", "curIterator", "=", "1000", "\n", "}", "\n", "if", "c", ".", "curKey", "<", "0", "{", "c", ".", "curKey", "=", "1000", "\n", "}", "\n", "return", "running", ",", "nil", "\n", "}", "\n", "}" ]
// Creates an action func based on a callback, used for moving the curXxxx properties.
[ "Creates", "an", "action", "func", "based", "on", "a", "callback", "used", "for", "moving", "the", "curXxxx", "properties", "." ]
a0cae174c4987cb28c071e0796e25b58834108d8
https://github.com/couchbase/moss/blob/a0cae174c4987cb28c071e0796e25b58834108d8/smat.go#L142-L160
20,172
qiangxue/fasthttp-routing
router.go
HandleRequest
func (r *Router) HandleRequest(ctx *fasthttp.RequestCtx) { c := r.pool.Get().(*Context) c.init(ctx) c.handlers, c.pnames = r.find(string(ctx.Method()), string(ctx.Path()), c.pvalues) if err := c.Next(); err != nil { r.handleError(c, err) } r.pool.Put(c) }
go
func (r *Router) HandleRequest(ctx *fasthttp.RequestCtx) { c := r.pool.Get().(*Context) c.init(ctx) c.handlers, c.pnames = r.find(string(ctx.Method()), string(ctx.Path()), c.pvalues) if err := c.Next(); err != nil { r.handleError(c, err) } r.pool.Put(c) }
[ "func", "(", "r", "*", "Router", ")", "HandleRequest", "(", "ctx", "*", "fasthttp", ".", "RequestCtx", ")", "{", "c", ":=", "r", ".", "pool", ".", "Get", "(", ")", ".", "(", "*", "Context", ")", "\n", "c", ".", "init", "(", "ctx", ")", "\n", "c", ".", "handlers", ",", "c", ".", "pnames", "=", "r", ".", "find", "(", "string", "(", "ctx", ".", "Method", "(", ")", ")", ",", "string", "(", "ctx", ".", "Path", "(", ")", ")", ",", "c", ".", "pvalues", ")", "\n", "if", "err", ":=", "c", ".", "Next", "(", ")", ";", "err", "!=", "nil", "{", "r", ".", "handleError", "(", "c", ",", "err", ")", "\n", "}", "\n", "r", ".", "pool", ".", "Put", "(", "c", ")", "\n", "}" ]
// HandleRequest handles the HTTP request.
[ "HandleRequest", "handles", "the", "HTTP", "request", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/router.go#L71-L79
20,173
qiangxue/fasthttp-routing
router.go
handleError
func (r *Router) handleError(c *Context, err error) { if httpError, ok := err.(HTTPError); ok { c.Error(httpError.Error(), httpError.StatusCode()) } else { c.Error(err.Error(), http.StatusInternalServerError) } }
go
func (r *Router) handleError(c *Context, err error) { if httpError, ok := err.(HTTPError); ok { c.Error(httpError.Error(), httpError.StatusCode()) } else { c.Error(err.Error(), http.StatusInternalServerError) } }
[ "func", "(", "r", "*", "Router", ")", "handleError", "(", "c", "*", "Context", ",", "err", "error", ")", "{", "if", "httpError", ",", "ok", ":=", "err", ".", "(", "HTTPError", ")", ";", "ok", "{", "c", ".", "Error", "(", "httpError", ".", "Error", "(", ")", ",", "httpError", ".", "StatusCode", "(", ")", ")", "\n", "}", "else", "{", "c", ".", "Error", "(", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "}", "\n", "}" ]
// handleError is the error handler for handling any unhandled errors.
[ "handleError", "is", "the", "error", "handler", "for", "handling", "any", "unhandled", "errors", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/router.go#L101-L107
20,174
qiangxue/fasthttp-routing
group.go
Patch
func (r *RouteGroup) Patch(path string, handlers ...Handler) *Route { return newRoute(path, r).Patch(handlers...) }
go
func (r *RouteGroup) Patch(path string, handlers ...Handler) *Route { return newRoute(path, r).Patch(handlers...) }
[ "func", "(", "r", "*", "RouteGroup", ")", "Patch", "(", "path", "string", ",", "handlers", "...", "Handler", ")", "*", "Route", "{", "return", "newRoute", "(", "path", ",", "r", ")", ".", "Patch", "(", "handlers", "...", ")", "\n", "}" ]
// Patch adds a PATCH route to the router with the given route path and handlers.
[ "Patch", "adds", "a", "PATCH", "route", "to", "the", "router", "with", "the", "given", "route", "path", "and", "handlers", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/group.go#L43-L45
20,175
qiangxue/fasthttp-routing
context.go
URL
func (c *Context) URL(route string, pairs ...interface{}) string { if r := c.router.routes[route]; r != nil { return r.URL(pairs...) } return "" }
go
func (c *Context) URL(route string, pairs ...interface{}) string { if r := c.router.routes[route]; r != nil { return r.URL(pairs...) } return "" }
[ "func", "(", "c", "*", "Context", ")", "URL", "(", "route", "string", ",", "pairs", "...", "interface", "{", "}", ")", "string", "{", "if", "r", ":=", "c", ".", "router", ".", "routes", "[", "route", "]", ";", "r", "!=", "nil", "{", "return", "r", ".", "URL", "(", "pairs", "...", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// URL creates a URL using the named route and the parameter values. // The parameters should be given in the sequence of name1, value1, name2, value2, and so on. // If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL. // Parameter values will be properly URL encoded. // The method returns an empty string if the URL creation fails.
[ "URL", "creates", "a", "URL", "using", "the", "named", "route", "and", "the", "parameter", "values", ".", "The", "parameters", "should", "be", "given", "in", "the", "sequence", "of", "name1", "value1", "name2", "value2", "and", "so", "on", ".", "If", "a", "parameter", "in", "the", "route", "is", "not", "provided", "a", "value", "the", "parameter", "token", "will", "remain", "in", "the", "resulting", "URL", ".", "Parameter", "values", "will", "be", "properly", "URL", "encoded", ".", "The", "method", "returns", "an", "empty", "string", "if", "the", "URL", "creation", "fails", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/context.go#L86-L91
20,176
qiangxue/fasthttp-routing
context.go
Serialize
func Serialize(data interface{}) (bytes []byte, err error) { switch data.(type) { case []byte: return data.([]byte), nil case string: return []byte(data.(string)), nil default: if data != nil { return []byte(fmt.Sprint(data)), nil } } return nil, nil }
go
func Serialize(data interface{}) (bytes []byte, err error) { switch data.(type) { case []byte: return data.([]byte), nil case string: return []byte(data.(string)), nil default: if data != nil { return []byte(fmt.Sprint(data)), nil } } return nil, nil }
[ "func", "Serialize", "(", "data", "interface", "{", "}", ")", "(", "bytes", "[", "]", "byte", ",", "err", "error", ")", "{", "switch", "data", ".", "(", "type", ")", "{", "case", "[", "]", "byte", ":", "return", "data", ".", "(", "[", "]", "byte", ")", ",", "nil", "\n", "case", "string", ":", "return", "[", "]", "byte", "(", "data", ".", "(", "string", ")", ")", ",", "nil", "\n", "default", ":", "if", "data", "!=", "nil", "{", "return", "[", "]", "byte", "(", "fmt", ".", "Sprint", "(", "data", ")", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// Serialize converts the given data into a byte array. // If the data is neither a byte array nor a string, it will call fmt.Sprint to convert it into a string.
[ "Serialize", "converts", "the", "given", "data", "into", "a", "byte", "array", ".", "If", "the", "data", "is", "neither", "a", "byte", "array", "nor", "a", "string", "it", "will", "call", "fmt", ".", "Sprint", "to", "convert", "it", "into", "a", "string", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/context.go#L114-L126
20,177
qiangxue/fasthttp-routing
route.go
add
func (r *Route) add(method string, handlers []Handler) *Route { hh := combineHandlers(r.group.handlers, handlers) r.group.router.add(method, r.path, hh) return r }
go
func (r *Route) add(method string, handlers []Handler) *Route { hh := combineHandlers(r.group.handlers, handlers) r.group.router.add(method, r.path, hh) return r }
[ "func", "(", "r", "*", "Route", ")", "add", "(", "method", "string", ",", "handlers", "[", "]", "Handler", ")", "*", "Route", "{", "hh", ":=", "combineHandlers", "(", "r", ".", "group", ".", "handlers", ",", "handlers", ")", "\n", "r", ".", "group", ".", "router", ".", "add", "(", "method", ",", "r", ".", "path", ",", "hh", ")", "\n", "return", "r", "\n", "}" ]
// add registers the route, the specified HTTP method and the handlers to the router. // The handlers will be combined with the handlers of the route group.
[ "add", "registers", "the", "route", "the", "specified", "HTTP", "method", "and", "the", "handlers", "to", "the", "router", ".", "The", "handlers", "will", "be", "combined", "with", "the", "handlers", "of", "the", "route", "group", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/route.go#L122-L126
20,178
qiangxue/fasthttp-routing
route.go
buildURLTemplate
func buildURLTemplate(path string) string { template, start, end := "", -1, -1 for i := 0; i < len(path); i++ { if path[i] == '<' && start < 0 { start = i } else if path[i] == '>' && start >= 0 { name := path[start+1 : i] for j := start + 1; j < i; j++ { if path[j] == ':' { name = path[start+1 : j] break } } template += path[end+1:start] + "<" + name + ">" end = i start = -1 } } if end < 0 { template = path } else if end < len(path)-1 { template += path[end+1:] } return template }
go
func buildURLTemplate(path string) string { template, start, end := "", -1, -1 for i := 0; i < len(path); i++ { if path[i] == '<' && start < 0 { start = i } else if path[i] == '>' && start >= 0 { name := path[start+1 : i] for j := start + 1; j < i; j++ { if path[j] == ':' { name = path[start+1 : j] break } } template += path[end+1:start] + "<" + name + ">" end = i start = -1 } } if end < 0 { template = path } else if end < len(path)-1 { template += path[end+1:] } return template }
[ "func", "buildURLTemplate", "(", "path", "string", ")", "string", "{", "template", ",", "start", ",", "end", ":=", "\"", "\"", ",", "-", "1", ",", "-", "1", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "path", ")", ";", "i", "++", "{", "if", "path", "[", "i", "]", "==", "'<'", "&&", "start", "<", "0", "{", "start", "=", "i", "\n", "}", "else", "if", "path", "[", "i", "]", "==", "'>'", "&&", "start", ">=", "0", "{", "name", ":=", "path", "[", "start", "+", "1", ":", "i", "]", "\n", "for", "j", ":=", "start", "+", "1", ";", "j", "<", "i", ";", "j", "++", "{", "if", "path", "[", "j", "]", "==", "':'", "{", "name", "=", "path", "[", "start", "+", "1", ":", "j", "]", "\n", "break", "\n", "}", "\n", "}", "\n", "template", "+=", "path", "[", "end", "+", "1", ":", "start", "]", "+", "\"", "\"", "+", "name", "+", "\"", "\"", "\n", "end", "=", "i", "\n", "start", "=", "-", "1", "\n", "}", "\n", "}", "\n", "if", "end", "<", "0", "{", "template", "=", "path", "\n", "}", "else", "if", "end", "<", "len", "(", "path", ")", "-", "1", "{", "template", "+=", "path", "[", "end", "+", "1", ":", "]", "\n", "}", "\n", "return", "template", "\n", "}" ]
// buildURLTemplate converts a route pattern into a URL template by removing regular expressions in parameter tokens.
[ "buildURLTemplate", "converts", "a", "route", "pattern", "into", "a", "URL", "template", "by", "removing", "regular", "expressions", "in", "parameter", "tokens", "." ]
6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71
https://github.com/qiangxue/fasthttp-routing/blob/6ccdc2a18d8712f842de50ddcb8c9a3d025ddc71/route.go#L129-L153
20,179
gen2brain/beeep
beep_unix.go
ioctl
func ioctl(fd, name, data uintptr) error { _, _, e := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(name), uintptr(data)) if e != 0 { return e } return nil }
go
func ioctl(fd, name, data uintptr) error { _, _, e := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(name), uintptr(data)) if e != 0 { return e } return nil }
[ "func", "ioctl", "(", "fd", ",", "name", ",", "data", "uintptr", ")", "error", "{", "_", ",", "_", ",", "e", ":=", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "fd", ",", "uintptr", "(", "name", ")", ",", "uintptr", "(", "data", ")", ")", "\n", "if", "e", "!=", "0", "{", "return", "e", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ioctl system call manipulates the underlying device parameters of special files.
[ "ioctl", "system", "call", "manipulates", "the", "underlying", "device", "parameters", "of", "special", "files", "." ]
aa3d7c1499fd45bc0160d65471e4a182dce73570
https://github.com/gen2brain/beeep/blob/aa3d7c1499fd45bc0160d65471e4a182dce73570/beep_unix.go#L43-L50
20,180
gen2brain/beeep
notify_js.go
Notify
func Notify(title, message, appIcon string) (err error) { defer func() { e := recover() if e == nil { return } if e, ok := e.(*js.Error); ok { err = e } else { panic(e) } }() n := js.Global().Get("Notification") opts := js.Global().Get("Object").Invoke() opts.Set("body", message) opts.Set("icon", pathAbs(appIcon)) if n.Get("permission").String() == "granted" { n.New(js.ValueOf(title), opts) } else { var f js.Callback f = js.NewCallback(func(args []js.Value) { if args[0].String() == "granted" { n.New(js.ValueOf(title), opts) } f.Release() }) n.Call("requestPermission", f) } return }
go
func Notify(title, message, appIcon string) (err error) { defer func() { e := recover() if e == nil { return } if e, ok := e.(*js.Error); ok { err = e } else { panic(e) } }() n := js.Global().Get("Notification") opts := js.Global().Get("Object").Invoke() opts.Set("body", message) opts.Set("icon", pathAbs(appIcon)) if n.Get("permission").String() == "granted" { n.New(js.ValueOf(title), opts) } else { var f js.Callback f = js.NewCallback(func(args []js.Value) { if args[0].String() == "granted" { n.New(js.ValueOf(title), opts) } f.Release() }) n.Call("requestPermission", f) } return }
[ "func", "Notify", "(", "title", ",", "message", ",", "appIcon", "string", ")", "(", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "e", ":=", "recover", "(", ")", "\n\n", "if", "e", "==", "nil", "{", "return", "\n", "}", "\n\n", "if", "e", ",", "ok", ":=", "e", ".", "(", "*", "js", ".", "Error", ")", ";", "ok", "{", "err", "=", "e", "\n", "}", "else", "{", "panic", "(", "e", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "n", ":=", "js", ".", "Global", "(", ")", ".", "Get", "(", "\"", "\"", ")", "\n\n", "opts", ":=", "js", ".", "Global", "(", ")", ".", "Get", "(", "\"", "\"", ")", ".", "Invoke", "(", ")", "\n", "opts", ".", "Set", "(", "\"", "\"", ",", "message", ")", "\n", "opts", ".", "Set", "(", "\"", "\"", ",", "pathAbs", "(", "appIcon", ")", ")", "\n\n", "if", "n", ".", "Get", "(", "\"", "\"", ")", ".", "String", "(", ")", "==", "\"", "\"", "{", "n", ".", "New", "(", "js", ".", "ValueOf", "(", "title", ")", ",", "opts", ")", "\n", "}", "else", "{", "var", "f", "js", ".", "Callback", "\n", "f", "=", "js", ".", "NewCallback", "(", "func", "(", "args", "[", "]", "js", ".", "Value", ")", "{", "if", "args", "[", "0", "]", ".", "String", "(", ")", "==", "\"", "\"", "{", "n", ".", "New", "(", "js", ".", "ValueOf", "(", "title", ")", ",", "opts", ")", "\n", "}", "\n", "f", ".", "Release", "(", ")", "\n", "}", ")", "\n\n", "n", ".", "Call", "(", "\"", "\"", ",", "f", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Notify sends desktop notification. // // On Web, in Firefox it just works, in Chrome you must call it from some "user gesture" like `onclick`, // and you must use TLS certificate, it doesn't work with plain http.
[ "Notify", "sends", "desktop", "notification", ".", "On", "Web", "in", "Firefox", "it", "just", "works", "in", "Chrome", "you", "must", "call", "it", "from", "some", "user", "gesture", "like", "onclick", "and", "you", "must", "use", "TLS", "certificate", "it", "doesn", "t", "work", "with", "plain", "http", "." ]
aa3d7c1499fd45bc0160d65471e4a182dce73570
https://github.com/gen2brain/beeep/blob/aa3d7c1499fd45bc0160d65471e4a182dce73570/notify_js.go#L13-L49
20,181
gen2brain/beeep
alert_js.go
Alert
func Alert(title, message, appIcon string) error { if err := Notify(title, message, appIcon); err != nil { return err } return Beep(DefaultFreq, DefaultDuration) }
go
func Alert(title, message, appIcon string) error { if err := Notify(title, message, appIcon); err != nil { return err } return Beep(DefaultFreq, DefaultDuration) }
[ "func", "Alert", "(", "title", ",", "message", ",", "appIcon", "string", ")", "error", "{", "if", "err", ":=", "Notify", "(", "title", ",", "message", ",", "appIcon", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "Beep", "(", "DefaultFreq", ",", "DefaultDuration", ")", "\n", "}" ]
// Alert displays a desktop notification and plays a beep.
[ "Alert", "displays", "a", "desktop", "notification", "and", "plays", "a", "beep", "." ]
aa3d7c1499fd45bc0160d65471e4a182dce73570
https://github.com/gen2brain/beeep/blob/aa3d7c1499fd45bc0160d65471e4a182dce73570/alert_js.go#L6-L11
20,182
gen2brain/beeep
notify_unix.go
Notify
func Notify(title, message, appIcon string) error { appIcon = pathAbs(appIcon) cmd := func() error { send, err := exec.LookPath("sw-notify-send") if err != nil { send, err = exec.LookPath("notify-send") if err != nil { return err } } c := exec.Command(send, title, message, "-i", appIcon) return c.Start() } knotify := func() error { send, err := exec.LookPath("kdialog") if err != nil { return err } c := exec.Command(send, "--title", title, "--passivepopup", message, "10", "--icon", appIcon) return c.Start() } conn, err := dbus.SessionBus() if err != nil { return cmd() } defer conn.Close() obj := conn.Object("org.freedesktop.Notifications", dbus.ObjectPath("/org/freedesktop/Notifications")) call := obj.Call("org.freedesktop.Notifications.Notify", 0, "", uint32(0), appIcon, title, message, []string{}, map[string]dbus.Variant{}, int32(-1)) if call.Err != nil { e := cmd() if e != nil { e := knotify() if e != nil { return errors.New("beeep: " + call.Err.Error() + "; " + e.Error()) } } } return nil }
go
func Notify(title, message, appIcon string) error { appIcon = pathAbs(appIcon) cmd := func() error { send, err := exec.LookPath("sw-notify-send") if err != nil { send, err = exec.LookPath("notify-send") if err != nil { return err } } c := exec.Command(send, title, message, "-i", appIcon) return c.Start() } knotify := func() error { send, err := exec.LookPath("kdialog") if err != nil { return err } c := exec.Command(send, "--title", title, "--passivepopup", message, "10", "--icon", appIcon) return c.Start() } conn, err := dbus.SessionBus() if err != nil { return cmd() } defer conn.Close() obj := conn.Object("org.freedesktop.Notifications", dbus.ObjectPath("/org/freedesktop/Notifications")) call := obj.Call("org.freedesktop.Notifications.Notify", 0, "", uint32(0), appIcon, title, message, []string{}, map[string]dbus.Variant{}, int32(-1)) if call.Err != nil { e := cmd() if e != nil { e := knotify() if e != nil { return errors.New("beeep: " + call.Err.Error() + "; " + e.Error()) } } } return nil }
[ "func", "Notify", "(", "title", ",", "message", ",", "appIcon", "string", ")", "error", "{", "appIcon", "=", "pathAbs", "(", "appIcon", ")", "\n\n", "cmd", ":=", "func", "(", ")", "error", "{", "send", ",", "err", ":=", "exec", ".", "LookPath", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "send", ",", "err", "=", "exec", ".", "LookPath", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "c", ":=", "exec", ".", "Command", "(", "send", ",", "title", ",", "message", ",", "\"", "\"", ",", "appIcon", ")", "\n", "return", "c", ".", "Start", "(", ")", "\n", "}", "\n\n", "knotify", ":=", "func", "(", ")", "error", "{", "send", ",", "err", ":=", "exec", ".", "LookPath", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "c", ":=", "exec", ".", "Command", "(", "send", ",", "\"", "\"", ",", "title", ",", "\"", "\"", ",", "message", ",", "\"", "\"", ",", "\"", "\"", ",", "appIcon", ")", "\n", "return", "c", ".", "Start", "(", ")", "\n", "}", "\n\n", "conn", ",", "err", ":=", "dbus", ".", "SessionBus", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cmd", "(", ")", "\n", "}", "\n\n", "defer", "conn", ".", "Close", "(", ")", "\n\n", "obj", ":=", "conn", ".", "Object", "(", "\"", "\"", ",", "dbus", ".", "ObjectPath", "(", "\"", "\"", ")", ")", "\n\n", "call", ":=", "obj", ".", "Call", "(", "\"", "\"", ",", "0", ",", "\"", "\"", ",", "uint32", "(", "0", ")", ",", "appIcon", ",", "title", ",", "message", ",", "[", "]", "string", "{", "}", ",", "map", "[", "string", "]", "dbus", ".", "Variant", "{", "}", ",", "int32", "(", "-", "1", ")", ")", "\n", "if", "call", ".", "Err", "!=", "nil", "{", "e", ":=", "cmd", "(", ")", "\n", "if", "e", "!=", "nil", "{", "e", ":=", "knotify", "(", ")", "\n", "if", "e", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "call", ".", "Err", ".", "Error", "(", ")", "+", "\"", "\"", "+", "e", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Notify sends desktop notification. // // On Linux it tries to send notification via D-Bus and it will fallback to `notify-send` binary.
[ "Notify", "sends", "desktop", "notification", ".", "On", "Linux", "it", "tries", "to", "send", "notification", "via", "D", "-", "Bus", "and", "it", "will", "fallback", "to", "notify", "-", "send", "binary", "." ]
aa3d7c1499fd45bc0160d65471e4a182dce73570
https://github.com/gen2brain/beeep/blob/aa3d7c1499fd45bc0160d65471e4a182dce73570/notify_unix.go#L15-L61
20,183
gen2brain/beeep
notify_windows.go
Notify
func Notify(title, message, appIcon string) error { if isWindows10 { return toastNotify(title, message, appIcon) } err := baloonNotify(title, message, appIcon, false) if err != nil { e := msgNotify(title, message) if e != nil { return errors.New("beeep: " + err.Error() + "; " + e.Error()) } } return nil }
go
func Notify(title, message, appIcon string) error { if isWindows10 { return toastNotify(title, message, appIcon) } err := baloonNotify(title, message, appIcon, false) if err != nil { e := msgNotify(title, message) if e != nil { return errors.New("beeep: " + err.Error() + "; " + e.Error()) } } return nil }
[ "func", "Notify", "(", "title", ",", "message", ",", "appIcon", "string", ")", "error", "{", "if", "isWindows10", "{", "return", "toastNotify", "(", "title", ",", "message", ",", "appIcon", ")", "\n", "}", "\n\n", "err", ":=", "baloonNotify", "(", "title", ",", "message", ",", "appIcon", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "e", ":=", "msgNotify", "(", "title", ",", "message", ")", "\n", "if", "e", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", "+", "\"", "\"", "+", "e", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n\n", "}" ]
// Notify sends desktop notification.
[ "Notify", "sends", "desktop", "notification", "." ]
aa3d7c1499fd45bc0160d65471e4a182dce73570
https://github.com/gen2brain/beeep/blob/aa3d7c1499fd45bc0160d65471e4a182dce73570/notify_windows.go#L42-L57
20,184
cbednarski/hostess
hostname.go
LooksLikeIPv6
func LooksLikeIPv6(ip string) bool { if !strings.Contains(ip, ":") { return false } return ipv6Pattern.MatchString(ip) }
go
func LooksLikeIPv6(ip string) bool { if !strings.Contains(ip, ":") { return false } return ipv6Pattern.MatchString(ip) }
[ "func", "LooksLikeIPv6", "(", "ip", "string", ")", "bool", "{", "if", "!", "strings", ".", "Contains", "(", "ip", ",", "\"", "\"", ")", "{", "return", "false", "\n", "}", "\n", "return", "ipv6Pattern", ".", "MatchString", "(", "ip", ")", "\n", "}" ]
// LooksLikeIPv6 returns true if the IP looks like it's IPv6. This does not // validate whether the string is a valid IP address.
[ "LooksLikeIPv6", "returns", "true", "if", "the", "IP", "looks", "like", "it", "s", "IPv6", ".", "This", "does", "not", "validate", "whether", "the", "string", "is", "a", "valid", "IP", "address", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostname.go#L21-L26
20,185
cbednarski/hostess
hostname.go
NewHostname
func NewHostname(domain, ip string, enabled bool) (*Hostname, error) { if !LooksLikeIPv4(ip) && !LooksLikeIPv6(ip) { return nil, fmt.Errorf("Unable to parse IP address %q", ip) } IP := net.ParseIP(ip) return &Hostname{domain, IP, enabled, LooksLikeIPv6(ip)}, nil }
go
func NewHostname(domain, ip string, enabled bool) (*Hostname, error) { if !LooksLikeIPv4(ip) && !LooksLikeIPv6(ip) { return nil, fmt.Errorf("Unable to parse IP address %q", ip) } IP := net.ParseIP(ip) return &Hostname{domain, IP, enabled, LooksLikeIPv6(ip)}, nil }
[ "func", "NewHostname", "(", "domain", ",", "ip", "string", ",", "enabled", "bool", ")", "(", "*", "Hostname", ",", "error", ")", "{", "if", "!", "LooksLikeIPv4", "(", "ip", ")", "&&", "!", "LooksLikeIPv6", "(", "ip", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ip", ")", "\n", "}", "\n", "IP", ":=", "net", ".", "ParseIP", "(", "ip", ")", "\n", "return", "&", "Hostname", "{", "domain", ",", "IP", ",", "enabled", ",", "LooksLikeIPv6", "(", "ip", ")", "}", ",", "nil", "\n", "}" ]
// NewHostname creates a new Hostname struct and automatically sets the IPv6 // field based on the IP you pass in.
[ "NewHostname", "creates", "a", "new", "Hostname", "struct", "and", "automatically", "sets", "the", "IPv6", "field", "based", "on", "the", "IP", "you", "pass", "in", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostname.go#L44-L50
20,186
cbednarski/hostess
hostname.go
MustHostname
func MustHostname(domain, ip string, enabled bool) *Hostname { hostname, err := NewHostname(domain, ip, enabled) if err != nil { panic(err) } return hostname }
go
func MustHostname(domain, ip string, enabled bool) *Hostname { hostname, err := NewHostname(domain, ip, enabled) if err != nil { panic(err) } return hostname }
[ "func", "MustHostname", "(", "domain", ",", "ip", "string", ",", "enabled", "bool", ")", "*", "Hostname", "{", "hostname", ",", "err", ":=", "NewHostname", "(", "domain", ",", "ip", ",", "enabled", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "hostname", "\n", "}" ]
// MustHostname calls NewHostname but panics if there is an error parsing it.
[ "MustHostname", "calls", "NewHostname", "but", "panics", "if", "there", "is", "an", "error", "parsing", "it", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostname.go#L53-L59
20,187
cbednarski/hostess
hostname.go
Equal
func (h *Hostname) Equal(n *Hostname) bool { return h.Domain == n.Domain && h.IP.Equal(n.IP) }
go
func (h *Hostname) Equal(n *Hostname) bool { return h.Domain == n.Domain && h.IP.Equal(n.IP) }
[ "func", "(", "h", "*", "Hostname", ")", "Equal", "(", "n", "*", "Hostname", ")", "bool", "{", "return", "h", ".", "Domain", "==", "n", ".", "Domain", "&&", "h", ".", "IP", ".", "Equal", "(", "n", ".", "IP", ")", "\n", "}" ]
// Equal compares two Hostnames. Note that only the Domain and IP fields are // compared because Enabled is transient state, and IPv6 should be set // automatically based on IP.
[ "Equal", "compares", "two", "Hostnames", ".", "Note", "that", "only", "the", "Domain", "and", "IP", "fields", "are", "compared", "because", "Enabled", "is", "transient", "state", "and", "IPv6", "should", "be", "set", "automatically", "based", "on", "IP", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostname.go#L64-L66
20,188
cbednarski/hostess
hostname.go
EqualIP
func (h *Hostname) EqualIP(ip net.IP) bool { return h.IP.Equal(ip) }
go
func (h *Hostname) EqualIP(ip net.IP) bool { return h.IP.Equal(ip) }
[ "func", "(", "h", "*", "Hostname", ")", "EqualIP", "(", "ip", "net", ".", "IP", ")", "bool", "{", "return", "h", ".", "IP", ".", "Equal", "(", "ip", ")", "\n", "}" ]
// EqualIP compares an IP against this Hostname.
[ "EqualIP", "compares", "an", "IP", "against", "this", "Hostname", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/hostname.go#L69-L71
20,189
cbednarski/hostess
commands.go
AnyBool
func AnyBool(c *cli.Context, key string) bool { return c.Bool(key) || c.GlobalBool(key) }
go
func AnyBool(c *cli.Context, key string) bool { return c.Bool(key) || c.GlobalBool(key) }
[ "func", "AnyBool", "(", "c", "*", "cli", ".", "Context", ",", "key", "string", ")", "bool", "{", "return", "c", ".", "Bool", "(", "key", ")", "||", "c", ".", "GlobalBool", "(", "key", ")", "\n", "}" ]
// AnyBool checks whether a boolean CLI flag is set either globally or on this // individual command. This provides more flexible flag parsing behavior.
[ "AnyBool", "checks", "whether", "a", "boolean", "CLI", "flag", "is", "set", "either", "globally", "or", "on", "this", "individual", "command", ".", "This", "provides", "more", "flexible", "flag", "parsing", "behavior", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L15-L17
20,190
cbednarski/hostess
commands.go
MaybeErrorln
func MaybeErrorln(c *cli.Context, message string) { if !AnyBool(c, "s") { os.Stderr.WriteString(fmt.Sprintf("%s\n", message)) } }
go
func MaybeErrorln(c *cli.Context, message string) { if !AnyBool(c, "s") { os.Stderr.WriteString(fmt.Sprintf("%s\n", message)) } }
[ "func", "MaybeErrorln", "(", "c", "*", "cli", ".", "Context", ",", "message", "string", ")", "{", "if", "!", "AnyBool", "(", "c", ",", "\"", "\"", ")", "{", "os", ".", "Stderr", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "message", ")", ")", "\n", "}", "\n", "}" ]
// MaybeErrorln will print an error message unless -s is passed
[ "MaybeErrorln", "will", "print", "an", "error", "message", "unless", "-", "s", "is", "passed" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L24-L28
20,191
cbednarski/hostess
commands.go
MaybeError
func MaybeError(c *cli.Context, message string) { MaybeErrorln(c, message) os.Exit(1) }
go
func MaybeError(c *cli.Context, message string) { MaybeErrorln(c, message) os.Exit(1) }
[ "func", "MaybeError", "(", "c", "*", "cli", ".", "Context", ",", "message", "string", ")", "{", "MaybeErrorln", "(", "c", ",", "message", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}" ]
// MaybeError will print an error message unless -s is passed and then exit
[ "MaybeError", "will", "print", "an", "error", "message", "unless", "-", "s", "is", "passed", "and", "then", "exit" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L31-L34
20,192
cbednarski/hostess
commands.go
MaybePrintln
func MaybePrintln(c *cli.Context, message string) { if !AnyBool(c, "q") && !AnyBool(c, "s") { fmt.Println(message) } }
go
func MaybePrintln(c *cli.Context, message string) { if !AnyBool(c, "q") && !AnyBool(c, "s") { fmt.Println(message) } }
[ "func", "MaybePrintln", "(", "c", "*", "cli", ".", "Context", ",", "message", "string", ")", "{", "if", "!", "AnyBool", "(", "c", ",", "\"", "\"", ")", "&&", "!", "AnyBool", "(", "c", ",", "\"", "\"", ")", "{", "fmt", ".", "Println", "(", "message", ")", "\n", "}", "\n", "}" ]
// MaybePrintln will print a message unless -q or -s is passed
[ "MaybePrintln", "will", "print", "a", "message", "unless", "-", "q", "or", "-", "s", "is", "passed" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L37-L41
20,193
cbednarski/hostess
commands.go
MaybeLoadHostFile
func MaybeLoadHostFile(c *cli.Context) *Hostfile { hostsfile, errs := LoadHostfile() if len(errs) > 0 && !AnyBool(c, "f") { for _, err := range errs { MaybeErrorln(c, err.Error()) } MaybeError(c, "Errors while parsing hostsfile. Try hostess fix") } return hostsfile }
go
func MaybeLoadHostFile(c *cli.Context) *Hostfile { hostsfile, errs := LoadHostfile() if len(errs) > 0 && !AnyBool(c, "f") { for _, err := range errs { MaybeErrorln(c, err.Error()) } MaybeError(c, "Errors while parsing hostsfile. Try hostess fix") } return hostsfile }
[ "func", "MaybeLoadHostFile", "(", "c", "*", "cli", ".", "Context", ")", "*", "Hostfile", "{", "hostsfile", ",", "errs", ":=", "LoadHostfile", "(", ")", "\n", "if", "len", "(", "errs", ")", ">", "0", "&&", "!", "AnyBool", "(", "c", ",", "\"", "\"", ")", "{", "for", "_", ",", "err", ":=", "range", "errs", "{", "MaybeErrorln", "(", "c", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "MaybeError", "(", "c", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "hostsfile", "\n", "}" ]
// MaybeLoadHostFile will try to load, parse, and return a Hostfile. If we // encounter errors we will terminate, unless -f is passed.
[ "MaybeLoadHostFile", "will", "try", "to", "load", "parse", "and", "return", "a", "Hostfile", ".", "If", "we", "encounter", "errors", "we", "will", "terminate", "unless", "-", "f", "is", "passed", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L45-L54
20,194
cbednarski/hostess
commands.go
AlwaysLoadHostFile
func AlwaysLoadHostFile(c *cli.Context) *Hostfile { hostsfile, errs := LoadHostfile() if len(errs) > 0 { for _, err := range errs { MaybeErrorln(c, err.Error()) } } return hostsfile }
go
func AlwaysLoadHostFile(c *cli.Context) *Hostfile { hostsfile, errs := LoadHostfile() if len(errs) > 0 { for _, err := range errs { MaybeErrorln(c, err.Error()) } } return hostsfile }
[ "func", "AlwaysLoadHostFile", "(", "c", "*", "cli", ".", "Context", ")", "*", "Hostfile", "{", "hostsfile", ",", "errs", ":=", "LoadHostfile", "(", ")", "\n", "if", "len", "(", "errs", ")", ">", "0", "{", "for", "_", ",", "err", ":=", "range", "errs", "{", "MaybeErrorln", "(", "c", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "hostsfile", "\n", "}" ]
// AlwaysLoadHostFile will load, parse, and return a Hostfile. If we encouter // errors they will be printed to the terminal, but we'll try to continue.
[ "AlwaysLoadHostFile", "will", "load", "parse", "and", "return", "a", "Hostfile", ".", "If", "we", "encouter", "errors", "they", "will", "be", "printed", "to", "the", "terminal", "but", "we", "ll", "try", "to", "continue", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L58-L66
20,195
cbednarski/hostess
commands.go
MaybeSaveHostFile
func MaybeSaveHostFile(c *cli.Context, hostfile *Hostfile) { // If -n is passed, no-op and output the resultant hosts file to stdout. // Otherwise it's for real and we're going to write it. if AnyBool(c, "n") { fmt.Printf("%s", hostfile.Format()) } else { err := hostfile.Save() if err != nil { MaybeError(c, ErrCantWriteHostFile.Error()) } } }
go
func MaybeSaveHostFile(c *cli.Context, hostfile *Hostfile) { // If -n is passed, no-op and output the resultant hosts file to stdout. // Otherwise it's for real and we're going to write it. if AnyBool(c, "n") { fmt.Printf("%s", hostfile.Format()) } else { err := hostfile.Save() if err != nil { MaybeError(c, ErrCantWriteHostFile.Error()) } } }
[ "func", "MaybeSaveHostFile", "(", "c", "*", "cli", ".", "Context", ",", "hostfile", "*", "Hostfile", ")", "{", "// If -n is passed, no-op and output the resultant hosts file to stdout.", "// Otherwise it's for real and we're going to write it.", "if", "AnyBool", "(", "c", ",", "\"", "\"", ")", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "hostfile", ".", "Format", "(", ")", ")", "\n", "}", "else", "{", "err", ":=", "hostfile", ".", "Save", "(", ")", "\n", "if", "err", "!=", "nil", "{", "MaybeError", "(", "c", ",", "ErrCantWriteHostFile", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// MaybeSaveHostFile will output or write the Hostfile, or exit 1 and error.
[ "MaybeSaveHostFile", "will", "output", "or", "write", "the", "Hostfile", "or", "exit", "1", "and", "error", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L69-L80
20,196
cbednarski/hostess
commands.go
StrPadRight
func StrPadRight(s string, l int) string { r := l - len(s) if r < 0 { r = 0 } return s + strings.Repeat(" ", r) }
go
func StrPadRight(s string, l int) string { r := l - len(s) if r < 0 { r = 0 } return s + strings.Repeat(" ", r) }
[ "func", "StrPadRight", "(", "s", "string", ",", "l", "int", ")", "string", "{", "r", ":=", "l", "-", "len", "(", "s", ")", "\n", "if", "r", "<", "0", "{", "r", "=", "0", "\n", "}", "\n", "return", "s", "+", "strings", ".", "Repeat", "(", "\"", "\"", ",", "r", ")", "\n", "}" ]
// StrPadRight adds spaces to the right of a string until it reaches l length. // If the input string is already that long, do nothing.
[ "StrPadRight", "adds", "spaces", "to", "the", "right", "of", "a", "string", "until", "it", "reaches", "l", "length", ".", "If", "the", "input", "string", "is", "already", "that", "long", "do", "nothing", "." ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L84-L90
20,197
cbednarski/hostess
commands.go
Has
func Has(c *cli.Context) { if len(c.Args()) != 1 { MaybeError(c, "expected <hostname>") } domain := c.Args()[0] hostsfile := MaybeLoadHostFile(c) found := hostsfile.Hosts.ContainsDomain(domain) if found { MaybePrintln(c, fmt.Sprintf("Found %s in %s", domain, GetHostsPath())) } else { MaybeError(c, fmt.Sprintf("%s not found in %s", domain, GetHostsPath())) } }
go
func Has(c *cli.Context) { if len(c.Args()) != 1 { MaybeError(c, "expected <hostname>") } domain := c.Args()[0] hostsfile := MaybeLoadHostFile(c) found := hostsfile.Hosts.ContainsDomain(domain) if found { MaybePrintln(c, fmt.Sprintf("Found %s in %s", domain, GetHostsPath())) } else { MaybeError(c, fmt.Sprintf("%s not found in %s", domain, GetHostsPath())) } }
[ "func", "Has", "(", "c", "*", "cli", ".", "Context", ")", "{", "if", "len", "(", "c", ".", "Args", "(", ")", ")", "!=", "1", "{", "MaybeError", "(", "c", ",", "\"", "\"", ")", "\n", "}", "\n", "domain", ":=", "c", ".", "Args", "(", ")", "[", "0", "]", "\n", "hostsfile", ":=", "MaybeLoadHostFile", "(", "c", ")", "\n\n", "found", ":=", "hostsfile", ".", "Hosts", ".", "ContainsDomain", "(", "domain", ")", "\n", "if", "found", "{", "MaybePrintln", "(", "c", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "domain", ",", "GetHostsPath", "(", ")", ")", ")", "\n", "}", "else", "{", "MaybeError", "(", "c", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "domain", ",", "GetHostsPath", "(", ")", ")", ")", "\n", "}", "\n\n", "}" ]
// Has command indicates whether a hostname is present in the hosts file
[ "Has", "command", "indicates", "whether", "a", "hostname", "is", "present", "in", "the", "hosts", "file" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L158-L172
20,198
cbednarski/hostess
commands.go
Ls
func Ls(c *cli.Context) { hostsfile := AlwaysLoadHostFile(c) maxdomain := 0 maxip := 0 for _, hostname := range hostsfile.Hosts { dlen := len(hostname.Domain) if dlen > maxdomain { maxdomain = dlen } ilen := len(hostname.IP) if ilen > maxip { maxip = ilen } } for _, hostname := range hostsfile.Hosts { fmt.Printf("%s -> %s %s\n", StrPadRight(hostname.Domain, maxdomain), StrPadRight(hostname.IP.String(), maxip), hostname.FormatEnabled()) } }
go
func Ls(c *cli.Context) { hostsfile := AlwaysLoadHostFile(c) maxdomain := 0 maxip := 0 for _, hostname := range hostsfile.Hosts { dlen := len(hostname.Domain) if dlen > maxdomain { maxdomain = dlen } ilen := len(hostname.IP) if ilen > maxip { maxip = ilen } } for _, hostname := range hostsfile.Hosts { fmt.Printf("%s -> %s %s\n", StrPadRight(hostname.Domain, maxdomain), StrPadRight(hostname.IP.String(), maxip), hostname.FormatEnabled()) } }
[ "func", "Ls", "(", "c", "*", "cli", ".", "Context", ")", "{", "hostsfile", ":=", "AlwaysLoadHostFile", "(", "c", ")", "\n", "maxdomain", ":=", "0", "\n", "maxip", ":=", "0", "\n", "for", "_", ",", "hostname", ":=", "range", "hostsfile", ".", "Hosts", "{", "dlen", ":=", "len", "(", "hostname", ".", "Domain", ")", "\n", "if", "dlen", ">", "maxdomain", "{", "maxdomain", "=", "dlen", "\n", "}", "\n", "ilen", ":=", "len", "(", "hostname", ".", "IP", ")", "\n", "if", "ilen", ">", "maxip", "{", "maxip", "=", "ilen", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "hostname", ":=", "range", "hostsfile", ".", "Hosts", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "StrPadRight", "(", "hostname", ".", "Domain", ",", "maxdomain", ")", ",", "StrPadRight", "(", "hostname", ".", "IP", ".", "String", "(", ")", ",", "maxip", ")", ",", "hostname", ".", "FormatEnabled", "(", ")", ")", "\n", "}", "\n", "}" ]
// Ls command shows a list of hostnames in the hosts file
[ "Ls", "command", "shows", "a", "list", "of", "hostnames", "in", "the", "hosts", "file" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L204-L225
20,199
cbednarski/hostess
commands.go
Fix
func Fix(c *cli.Context) { hostsfile := AlwaysLoadHostFile(c) if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) { MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts; nothing to do", GetHostsPath())) os.Exit(0) } MaybeSaveHostFile(c, hostsfile) }
go
func Fix(c *cli.Context) { hostsfile := AlwaysLoadHostFile(c) if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) { MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts; nothing to do", GetHostsPath())) os.Exit(0) } MaybeSaveHostFile(c, hostsfile) }
[ "func", "Fix", "(", "c", "*", "cli", ".", "Context", ")", "{", "hostsfile", ":=", "AlwaysLoadHostFile", "(", "c", ")", "\n", "if", "bytes", ".", "Equal", "(", "hostsfile", ".", "GetData", "(", ")", ",", "hostsfile", ".", "Format", "(", ")", ")", "{", "MaybePrintln", "(", "c", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "GetHostsPath", "(", ")", ")", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "\n", "MaybeSaveHostFile", "(", "c", ",", "hostsfile", ")", "\n", "}" ]
// Fix command removes duplicates and conflicts from the hosts file
[ "Fix", "command", "removes", "duplicates", "and", "conflicts", "from", "the", "hosts", "file" ]
4c91c5787547219e13bce8e17bd1d0049e3918e6
https://github.com/cbednarski/hostess/blob/4c91c5787547219e13bce8e17bd1d0049e3918e6/commands.go#L238-L245