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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
150,800 | fabric8-services/fabric8-auth | authorization/role/repository/identity_role.go | query | func (m *GormIdentityRoleRepository) query(funcs ...func(*gorm.DB) *gorm.DB) ([]IdentityRole, error) {
defer goa.MeasureSince([]string{"goa", "db", "identity_role", "list"}, time.Now())
var rows []IdentityRole
err := m.db.Scopes(funcs...).Table(m.TableName()).Find(&rows).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, errs.WithStack(err)
}
log.Debug(nil, map[string]interface{}{
"identity_roles": rows,
}, "Identity query executed successfully!")
return rows, nil
} | go | func (m *GormIdentityRoleRepository) query(funcs ...func(*gorm.DB) *gorm.DB) ([]IdentityRole, error) {
defer goa.MeasureSince([]string{"goa", "db", "identity_role", "list"}, time.Now())
var rows []IdentityRole
err := m.db.Scopes(funcs...).Table(m.TableName()).Find(&rows).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, errs.WithStack(err)
}
log.Debug(nil, map[string]interface{}{
"identity_roles": rows,
}, "Identity query executed successfully!")
return rows, nil
} | [
"func",
"(",
"m",
"*",
"GormIdentityRoleRepository",
")",
"query",
"(",
"funcs",
"...",
"func",
"(",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
")",
"(",
"[",
"]",
"IdentityRole",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",... | // Query exposes an open ended Query model | [
"Query",
"exposes",
"an",
"open",
"ended",
"Query",
"model"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/role/repository/identity_role.go#L673-L685 |
150,801 | fabric8-services/fabric8-auth | authorization/role/repository/identity_role.go | identityRoleFilterByResource | func identityRoleFilterByResource(resourceID string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("resource_id = ?", resourceID)
}
} | go | func identityRoleFilterByResource(resourceID string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("resource_id = ?", resourceID)
}
} | [
"func",
"identityRoleFilterByResource",
"(",
"resourceID",
"string",
")",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
... | // IdentityRoleFilterByResource is a gorm filter for resource ID | [
"IdentityRoleFilterByResource",
"is",
"a",
"gorm",
"filter",
"for",
"resource",
"ID"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/role/repository/identity_role.go#L688-L692 |
150,802 | fabric8-services/fabric8-auth | authorization/role/repository/identity_role.go | identityRoleFilterByIdentityID | func identityRoleFilterByIdentityID(identityID uuid.UUID) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("identity_id = ?", identityID)
}
} | go | func identityRoleFilterByIdentityID(identityID uuid.UUID) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("identity_id = ?", identityID)
}
} | [
"func",
"identityRoleFilterByIdentityID",
"(",
"identityID",
"uuid",
".",
"UUID",
")",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{... | // IdentityRoleFilterByIdentityID is a gorm filter for Identity ID. | [
"IdentityRoleFilterByIdentityID",
"is",
"a",
"gorm",
"filter",
"for",
"Identity",
"ID",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/role/repository/identity_role.go#L695-L699 |
150,803 | fabric8-services/fabric8-auth | errors/errors.go | NewInternalErrorFromString | func NewInternalErrorFromString(ctx context.Context, errorMessage string) InternalError {
return InternalError{errors.New(errorMessage)}
} | go | func NewInternalErrorFromString(ctx context.Context, errorMessage string) InternalError {
return InternalError{errors.New(errorMessage)}
} | [
"func",
"NewInternalErrorFromString",
"(",
"ctx",
"context",
".",
"Context",
",",
"errorMessage",
"string",
")",
"InternalError",
"{",
"return",
"InternalError",
"{",
"errors",
".",
"New",
"(",
"errorMessage",
")",
"}",
"\n",
"}"
] | // NewInternalErrorFromString returns the custom defined error of type InternalError. | [
"NewInternalErrorFromString",
"returns",
"the",
"custom",
"defined",
"error",
"of",
"type",
"InternalError",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/errors/errors.go#L39-L41 |
150,804 | fabric8-services/fabric8-auth | errors/errors.go | NewBadParameterErrorFromString | func NewBadParameterErrorFromString(param string, actual interface{}, errorMessage string) BadParameterError {
return BadParameterError{parameter: param, value: actual, errorMessage: errorMessage}
} | go | func NewBadParameterErrorFromString(param string, actual interface{}, errorMessage string) BadParameterError {
return BadParameterError{parameter: param, value: actual, errorMessage: errorMessage}
} | [
"func",
"NewBadParameterErrorFromString",
"(",
"param",
"string",
",",
"actual",
"interface",
"{",
"}",
",",
"errorMessage",
"string",
")",
"BadParameterError",
"{",
"return",
"BadParameterError",
"{",
"parameter",
":",
"param",
",",
"value",
":",
"actual",
",",
... | // NewBadParameterErrorFromString returns the custom defined error of type BadParameterError. | [
"NewBadParameterErrorFromString",
"returns",
"the",
"custom",
"defined",
"error",
"of",
"type",
"BadParameterError",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/errors/errors.go#L177-L179 |
150,805 | fabric8-services/fabric8-auth | authentication/account/service/email_verification.go | NewEmailVerificationClient | func NewEmailVerificationClient(app application.Application) *EmailVerificationClient {
return &EmailVerificationClient{
app: app,
notification: app.NotificationService(),
}
} | go | func NewEmailVerificationClient(app application.Application) *EmailVerificationClient {
return &EmailVerificationClient{
app: app,
notification: app.NotificationService(),
}
} | [
"func",
"NewEmailVerificationClient",
"(",
"app",
"application",
".",
"Application",
")",
"*",
"EmailVerificationClient",
"{",
"return",
"&",
"EmailVerificationClient",
"{",
"app",
":",
"app",
",",
"notification",
":",
"app",
".",
"NotificationService",
"(",
")",
... | // NewEmailVerificationClient creates a new client for managing email verification. | [
"NewEmailVerificationClient",
"creates",
"a",
"new",
"client",
"for",
"managing",
"email",
"verification",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/email_verification.go#L31-L36 |
150,806 | fabric8-services/fabric8-auth | authentication/account/service/email_verification.go | SendVerificationCode | func (c *EmailVerificationClient) SendVerificationCode(ctx context.Context, req *goa.RequestData, identity repository.Identity) (*repository.VerificationCode, error) {
generatedCode := uuid.NewV4().String()
newVerificationCode := repository.VerificationCode{
User: identity.User,
Code: generatedCode,
}
log.Info(ctx, map[string]interface{}{
"email": identity.User.Email,
}, "verification code to be sent")
err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {
err := tr.VerificationCodes().Create(ctx, &newVerificationCode)
return err
})
if err != nil {
return nil, err
}
notificationCustomAttributes := map[string]interface{}{
"verifyURL": c.generateVerificationURL(ctx, req, generatedCode),
}
emailMessage := notification.NewUserEmailUpdated(identity.ID.String(), notificationCustomAttributes)
c.notification.SendMessageAsync(ctx, emailMessage)
return &newVerificationCode, err
} | go | func (c *EmailVerificationClient) SendVerificationCode(ctx context.Context, req *goa.RequestData, identity repository.Identity) (*repository.VerificationCode, error) {
generatedCode := uuid.NewV4().String()
newVerificationCode := repository.VerificationCode{
User: identity.User,
Code: generatedCode,
}
log.Info(ctx, map[string]interface{}{
"email": identity.User.Email,
}, "verification code to be sent")
err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {
err := tr.VerificationCodes().Create(ctx, &newVerificationCode)
return err
})
if err != nil {
return nil, err
}
notificationCustomAttributes := map[string]interface{}{
"verifyURL": c.generateVerificationURL(ctx, req, generatedCode),
}
emailMessage := notification.NewUserEmailUpdated(identity.ID.String(), notificationCustomAttributes)
c.notification.SendMessageAsync(ctx, emailMessage)
return &newVerificationCode, err
} | [
"func",
"(",
"c",
"*",
"EmailVerificationClient",
")",
"SendVerificationCode",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"goa",
".",
"RequestData",
",",
"identity",
"repository",
".",
"Identity",
")",
"(",
"*",
"repository",
".",
"VerificationCod... | // SendVerificationCode generates and sends out an email with verification code. | [
"SendVerificationCode",
"generates",
"and",
"sends",
"out",
"an",
"email",
"with",
"verification",
"code",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/email_verification.go#L39-L67 |
150,807 | fabric8-services/fabric8-auth | authentication/account/service/email_verification.go | VerifyCode | func (c *EmailVerificationClient) VerifyCode(ctx context.Context, code string) (*repository.VerificationCode, error) {
var verificationCode *repository.VerificationCode
log.Debug(ctx, map[string]interface{}{
"code": code,
}, "verification code to be validated")
err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {
verificationCodeList, err := tr.VerificationCodes().LoadByCode(ctx, code)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error looking up verification code")
return err
}
if verificationCodeList == nil || len(verificationCodeList) == 0 {
return errors.NewNotFoundError("code", code)
}
verificationCode = &verificationCodeList[0]
user := verificationCode.User
user.EmailVerified = true
err = tr.Users().Save(ctx, &user)
if err != nil {
return err
}
err = tr.VerificationCodes().Delete(ctx, verificationCode.ID)
return err
})
if err != nil {
log.Error(ctx, map[string]interface{}{
"code": code,
"err": err,
}, "verification failed")
}
return verificationCode, err
} | go | func (c *EmailVerificationClient) VerifyCode(ctx context.Context, code string) (*repository.VerificationCode, error) {
var verificationCode *repository.VerificationCode
log.Debug(ctx, map[string]interface{}{
"code": code,
}, "verification code to be validated")
err := transaction.Transactional(c.app, func(tr transaction.TransactionalResources) error {
verificationCodeList, err := tr.VerificationCodes().LoadByCode(ctx, code)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error looking up verification code")
return err
}
if verificationCodeList == nil || len(verificationCodeList) == 0 {
return errors.NewNotFoundError("code", code)
}
verificationCode = &verificationCodeList[0]
user := verificationCode.User
user.EmailVerified = true
err = tr.Users().Save(ctx, &user)
if err != nil {
return err
}
err = tr.VerificationCodes().Delete(ctx, verificationCode.ID)
return err
})
if err != nil {
log.Error(ctx, map[string]interface{}{
"code": code,
"err": err,
}, "verification failed")
}
return verificationCode, err
} | [
"func",
"(",
"c",
"*",
"EmailVerificationClient",
")",
"VerifyCode",
"(",
"ctx",
"context",
".",
"Context",
",",
"code",
"string",
")",
"(",
"*",
"repository",
".",
"VerificationCode",
",",
"error",
")",
"{",
"var",
"verificationCode",
"*",
"repository",
"."... | // VerifyCode validates whether the code is present in our database and returns a non-nil if yes. | [
"VerifyCode",
"validates",
"whether",
"the",
"code",
"is",
"present",
"in",
"our",
"database",
"and",
"returns",
"a",
"non",
"-",
"nil",
"if",
"yes",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/email_verification.go#L74-L115 |
150,808 | fabric8-services/fabric8-auth | authentication/account/worker/user_deactivation_worker.go | NewUserDeactivationWorker | func NewUserDeactivationWorker(ctx context.Context, app application.Application) UserDeactivationWorker {
w := &userDeactivationWorker{
worker.Worker{
Ctx: ctx,
App: app,
Owner: worker.GetLockOwner(ctx),
Name: "user-deactivation",
},
}
w.Do = w.deactivateUsers
return w
} | go | func NewUserDeactivationWorker(ctx context.Context, app application.Application) UserDeactivationWorker {
w := &userDeactivationWorker{
worker.Worker{
Ctx: ctx,
App: app,
Owner: worker.GetLockOwner(ctx),
Name: "user-deactivation",
},
}
w.Do = w.deactivateUsers
return w
} | [
"func",
"NewUserDeactivationWorker",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"application",
".",
"Application",
")",
"UserDeactivationWorker",
"{",
"w",
":=",
"&",
"userDeactivationWorker",
"{",
"worker",
".",
"Worker",
"{",
"Ctx",
":",
"ctx",
",",
... | // NewUserDeactivationWorker returns a new UserDeactivationWorker | [
"NewUserDeactivationWorker",
"returns",
"a",
"new",
"UserDeactivationWorker"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/worker/user_deactivation_worker.go#L26-L37 |
150,809 | fabric8-services/fabric8-auth | log/log.go | Info | func Info(ctx context.Context, fields map[string]interface{}, format string, args ...interface{}) {
if logger.Level >= log.InfoLevel {
entry := log.NewEntry(logger)
_, _, pName, _, err := extractCallerDetails()
if err == nil {
entry = entry.WithField("pkg", pName)
}
if ctx != nil {
entry = entry.WithField("req_id", ExtractRequestID(ctx))
identityID, err := extractIdentityID(ctx)
if err == nil { // Otherwise we don't use the identityID
entry = entry.WithField("identity_id", identityID)
}
}
if len(args) > 0 {
entry.WithFields(fields).Infof(format, args...)
} else {
entry.WithFields(fields).Infoln(format)
}
}
} | go | func Info(ctx context.Context, fields map[string]interface{}, format string, args ...interface{}) {
if logger.Level >= log.InfoLevel {
entry := log.NewEntry(logger)
_, _, pName, _, err := extractCallerDetails()
if err == nil {
entry = entry.WithField("pkg", pName)
}
if ctx != nil {
entry = entry.WithField("req_id", ExtractRequestID(ctx))
identityID, err := extractIdentityID(ctx)
if err == nil { // Otherwise we don't use the identityID
entry = entry.WithField("identity_id", identityID)
}
}
if len(args) > 0 {
entry.WithFields(fields).Infof(format, args...)
} else {
entry.WithFields(fields).Infoln(format)
}
}
} | [
"func",
"Info",
"(",
"ctx",
"context",
".",
"Context",
",",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"logger",
".",
"Level",
">=",
"log",
".",
"I... | // Info logs an info message that might contain the request id if provided by
// the context. In this function, the parameter fields enables to additional
// attributes to the message. The format and args input arguments are used to
// print a detailed information about the reasons of this log. | [
"Info",
"logs",
"an",
"info",
"message",
"that",
"might",
"contain",
"the",
"request",
"id",
"if",
"provided",
"by",
"the",
"context",
".",
"In",
"this",
"function",
"the",
"parameter",
"fields",
"enables",
"to",
"additional",
"attributes",
"to",
"the",
"mes... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/log/log.go#L170-L193 |
150,810 | fabric8-services/fabric8-auth | log/log.go | Debug | func Debug(ctx context.Context, fields map[string]interface{}, format string, args ...interface{}) {
if logger.Level >= log.DebugLevel {
entry := log.NewEntry(logger)
_, _, pName, _, err := extractCallerDetails()
if err == nil {
entry = entry.WithField("pkg", pName)
}
if ctx != nil {
entry = entry.WithField("req_id", ExtractRequestID(ctx))
identityID, err := extractIdentityID(ctx)
if err == nil {
entry = entry.WithField("identity_id", identityID)
}
}
if len(args) > 0 {
entry.WithFields(fields).Debugf(format, args...)
} else {
entry.WithFields(fields).Debugln(format)
}
}
} | go | func Debug(ctx context.Context, fields map[string]interface{}, format string, args ...interface{}) {
if logger.Level >= log.DebugLevel {
entry := log.NewEntry(logger)
_, _, pName, _, err := extractCallerDetails()
if err == nil {
entry = entry.WithField("pkg", pName)
}
if ctx != nil {
entry = entry.WithField("req_id", ExtractRequestID(ctx))
identityID, err := extractIdentityID(ctx)
if err == nil {
entry = entry.WithField("identity_id", identityID)
}
}
if len(args) > 0 {
entry.WithFields(fields).Debugf(format, args...)
} else {
entry.WithFields(fields).Debugln(format)
}
}
} | [
"func",
"Debug",
"(",
"ctx",
"context",
".",
"Context",
",",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"logger",
".",
"Level",
">=",
"log",
".",
"... | // Debug logs a debug message that might specifies the request id if provided by
// the context. In this function, the parameter fields enables to additional
// attributes to the message. The format and args input arguments are used to
// print a detailed information about the reasons of this log. | [
"Debug",
"logs",
"a",
"debug",
"message",
"that",
"might",
"specifies",
"the",
"request",
"id",
"if",
"provided",
"by",
"the",
"context",
".",
"In",
"this",
"function",
"the",
"parameter",
"fields",
"enables",
"to",
"additional",
"attributes",
"to",
"the",
"... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/log/log.go#L224-L247 |
150,811 | fabric8-services/fabric8-auth | authorization/authorization.go | CanHaveMembers | func CanHaveMembers(resourceTypeName string) bool {
return resourceTypeName == IdentityResourceTypeOrganization ||
resourceTypeName == IdentityResourceTypeTeam ||
resourceTypeName == IdentityResourceTypeGroup
} | go | func CanHaveMembers(resourceTypeName string) bool {
return resourceTypeName == IdentityResourceTypeOrganization ||
resourceTypeName == IdentityResourceTypeTeam ||
resourceTypeName == IdentityResourceTypeGroup
} | [
"func",
"CanHaveMembers",
"(",
"resourceTypeName",
"string",
")",
"bool",
"{",
"return",
"resourceTypeName",
"==",
"IdentityResourceTypeOrganization",
"||",
"resourceTypeName",
"==",
"IdentityResourceTypeTeam",
"||",
"resourceTypeName",
"==",
"IdentityResourceTypeGroup",
"\n"... | // CanHaveMembers returns a boolean indicating whether the specified resource type may have member Identities | [
"CanHaveMembers",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"specified",
"resource",
"type",
"may",
"have",
"member",
"Identities"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/authorization.go#L125-L129 |
150,812 | fabric8-services/fabric8-auth | authorization/authorization.go | ScopeForManagingRolesInResourceType | func ScopeForManagingRolesInResourceType(resourceType string) string {
switch resourceType {
case ResourceTypeSpace:
return ManageRoleAssignmentsInSpaceScope
case IdentityResourceTypeOrganization:
return ManageOrganizationMembersScope
case IdentityResourceTypeTeam:
return ManageTeamMembersScope
case IdentityResourceTypeGroup:
return ManageSecurityGroupMembersScope
case ResourceTypeSystem:
return ManageUserSystemScope
}
// a default which we can choose to change later
return ManageRoleAssignmentsInSpaceScope
} | go | func ScopeForManagingRolesInResourceType(resourceType string) string {
switch resourceType {
case ResourceTypeSpace:
return ManageRoleAssignmentsInSpaceScope
case IdentityResourceTypeOrganization:
return ManageOrganizationMembersScope
case IdentityResourceTypeTeam:
return ManageTeamMembersScope
case IdentityResourceTypeGroup:
return ManageSecurityGroupMembersScope
case ResourceTypeSystem:
return ManageUserSystemScope
}
// a default which we can choose to change later
return ManageRoleAssignmentsInSpaceScope
} | [
"func",
"ScopeForManagingRolesInResourceType",
"(",
"resourceType",
"string",
")",
"string",
"{",
"switch",
"resourceType",
"{",
"case",
"ResourceTypeSpace",
":",
"return",
"ManageRoleAssignmentsInSpaceScope",
"\n",
"case",
"IdentityResourceTypeOrganization",
":",
"return",
... | // ScopeForManagingRolesInResourceType returns the name of the scope that gives a user privileges to manage roles in a resource | [
"ScopeForManagingRolesInResourceType",
"returns",
"the",
"name",
"of",
"the",
"scope",
"that",
"gives",
"a",
"user",
"privileges",
"to",
"manage",
"roles",
"in",
"a",
"resource"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/authorization.go#L132-L147 |
150,813 | fabric8-services/fabric8-auth | authorization/authorization.go | ScopeForViewingRolesInResourceType | func ScopeForViewingRolesInResourceType(resourceType string) string {
switch resourceType {
case ResourceTypeSpace:
return ViewRoleAssignmentsInSpaceScope
case IdentityResourceTypeOrganization:
return ViewOrganizationMembersScope
case IdentityResourceTypeTeam:
return ViewTeamMembersScope
case IdentityResourceTypeGroup:
return ViewSecurityGroupMembersScope
}
// a default which we can choose to change later
return ViewRoleAssignmentsInSpaceScope
} | go | func ScopeForViewingRolesInResourceType(resourceType string) string {
switch resourceType {
case ResourceTypeSpace:
return ViewRoleAssignmentsInSpaceScope
case IdentityResourceTypeOrganization:
return ViewOrganizationMembersScope
case IdentityResourceTypeTeam:
return ViewTeamMembersScope
case IdentityResourceTypeGroup:
return ViewSecurityGroupMembersScope
}
// a default which we can choose to change later
return ViewRoleAssignmentsInSpaceScope
} | [
"func",
"ScopeForViewingRolesInResourceType",
"(",
"resourceType",
"string",
")",
"string",
"{",
"switch",
"resourceType",
"{",
"case",
"ResourceTypeSpace",
":",
"return",
"ViewRoleAssignmentsInSpaceScope",
"\n",
"case",
"IdentityResourceTypeOrganization",
":",
"return",
"V... | // ScopeForViewingRolesInResourceType returns the name of the scope that gives a user privileges to view roles in a resource | [
"ScopeForViewingRolesInResourceType",
"returns",
"the",
"name",
"of",
"the",
"scope",
"that",
"gives",
"a",
"user",
"privileges",
"to",
"view",
"roles",
"in",
"a",
"resource"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/authorization.go#L150-L163 |
150,814 | fabric8-services/fabric8-auth | authorization/authorization.go | AppendAssociation | func AppendAssociation(associations []IdentityAssociation, resourceID string, resourceName *string, parentResourceID *string,
identityID *uuid.UUID, member bool, role *string) []IdentityAssociation {
found := false
for i, assoc := range associations {
if assoc.ResourceID == resourceID {
found = true
if assoc.IdentityID == nil && identityID != nil {
id := *identityID
assoc.IdentityID = &id
}
if assoc.ParentResourceID == nil && parentResourceID != nil {
prID := *parentResourceID
assoc.ParentResourceID = &prID
}
if !assoc.Member && member {
assoc.Member = true
}
if role != nil {
roleFound := false
for _, r := range assoc.Roles {
if r == *role {
roleFound = true
break
}
}
if !roleFound {
assoc.Roles = append(assoc.Roles, *role)
}
}
associations[i] = assoc
break
}
}
if !found {
roles := []string{}
if role != nil {
roles = append(roles, *role)
}
var id *uuid.UUID
if identityID != nil {
value := *identityID
id = &value
}
var prID *string
if parentResourceID != nil {
value := *parentResourceID
prID = &value
}
associations = append(associations, IdentityAssociation{
ResourceID: resourceID,
ResourceName: *resourceName,
ParentResourceID: prID,
IdentityID: id,
Member: member,
Roles: roles,
})
}
return associations
} | go | func AppendAssociation(associations []IdentityAssociation, resourceID string, resourceName *string, parentResourceID *string,
identityID *uuid.UUID, member bool, role *string) []IdentityAssociation {
found := false
for i, assoc := range associations {
if assoc.ResourceID == resourceID {
found = true
if assoc.IdentityID == nil && identityID != nil {
id := *identityID
assoc.IdentityID = &id
}
if assoc.ParentResourceID == nil && parentResourceID != nil {
prID := *parentResourceID
assoc.ParentResourceID = &prID
}
if !assoc.Member && member {
assoc.Member = true
}
if role != nil {
roleFound := false
for _, r := range assoc.Roles {
if r == *role {
roleFound = true
break
}
}
if !roleFound {
assoc.Roles = append(assoc.Roles, *role)
}
}
associations[i] = assoc
break
}
}
if !found {
roles := []string{}
if role != nil {
roles = append(roles, *role)
}
var id *uuid.UUID
if identityID != nil {
value := *identityID
id = &value
}
var prID *string
if parentResourceID != nil {
value := *parentResourceID
prID = &value
}
associations = append(associations, IdentityAssociation{
ResourceID: resourceID,
ResourceName: *resourceName,
ParentResourceID: prID,
IdentityID: id,
Member: member,
Roles: roles,
})
}
return associations
} | [
"func",
"AppendAssociation",
"(",
"associations",
"[",
"]",
"IdentityAssociation",
",",
"resourceID",
"string",
",",
"resourceName",
"*",
"string",
",",
"parentResourceID",
"*",
"string",
",",
"identityID",
"*",
"uuid",
".",
"UUID",
",",
"member",
"bool",
",",
... | // AppendAssociation appends the association state specified by the parameter values to an existing IdentityAssociation array | [
"AppendAssociation",
"appends",
"the",
"association",
"state",
"specified",
"by",
"the",
"parameter",
"values",
"to",
"an",
"existing",
"IdentityAssociation",
"array"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/authorization.go#L178-L245 |
150,815 | fabric8-services/fabric8-auth | authorization/authorization.go | MergeAssociations | func MergeAssociations(associations []IdentityAssociation, merge []IdentityAssociation) []IdentityAssociation {
for _, merging := range merge {
found := false
for i, assoc := range associations {
// there is a match if the record to be merged has the same ResourceID (there must always be a resource)
if assoc.ResourceID == merging.ResourceID {
found = true
if !assoc.Member {
assoc.Member = merging.Member
}
if assoc.IdentityID == nil && merging.IdentityID != nil {
assoc.IdentityID = merging.IdentityID
}
for _, roleToMerge := range merging.Roles {
roleFound := false
for _, assocRole := range assoc.Roles {
if assocRole == roleToMerge {
roleFound = true
break
}
}
if !roleFound {
assoc.Roles = append(assoc.Roles, roleToMerge)
}
}
associations[i] = assoc
}
}
if !found {
associations = append(associations, merging)
}
}
return associations
} | go | func MergeAssociations(associations []IdentityAssociation, merge []IdentityAssociation) []IdentityAssociation {
for _, merging := range merge {
found := false
for i, assoc := range associations {
// there is a match if the record to be merged has the same ResourceID (there must always be a resource)
if assoc.ResourceID == merging.ResourceID {
found = true
if !assoc.Member {
assoc.Member = merging.Member
}
if assoc.IdentityID == nil && merging.IdentityID != nil {
assoc.IdentityID = merging.IdentityID
}
for _, roleToMerge := range merging.Roles {
roleFound := false
for _, assocRole := range assoc.Roles {
if assocRole == roleToMerge {
roleFound = true
break
}
}
if !roleFound {
assoc.Roles = append(assoc.Roles, roleToMerge)
}
}
associations[i] = assoc
}
}
if !found {
associations = append(associations, merging)
}
}
return associations
} | [
"func",
"MergeAssociations",
"(",
"associations",
"[",
"]",
"IdentityAssociation",
",",
"merge",
"[",
"]",
"IdentityAssociation",
")",
"[",
"]",
"IdentityAssociation",
"{",
"for",
"_",
",",
"merging",
":=",
"range",
"merge",
"{",
"found",
":=",
"false",
"\n",
... | // MergeAssociations merges two arrays of IdentityAssociation objects into one | [
"MergeAssociations",
"merges",
"two",
"arrays",
"of",
"IdentityAssociation",
"objects",
"into",
"one"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/authorization.go#L248-L289 |
150,816 | fabric8-services/fabric8-auth | controller/organization.go | NewOrganizationController | func NewOrganizationController(service *goa.Service, app application.Application) *OrganizationController {
return &OrganizationController{Controller: service.NewController("OrganizationController"), app: app}
} | go | func NewOrganizationController(service *goa.Service, app application.Application) *OrganizationController {
return &OrganizationController{Controller: service.NewController("OrganizationController"), app: app}
} | [
"func",
"NewOrganizationController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"app",
"application",
".",
"Application",
")",
"*",
"OrganizationController",
"{",
"return",
"&",
"OrganizationController",
"{",
"Controller",
":",
"service",
".",
"NewController",... | // NewOrganizationController creates an organization controller. | [
"NewOrganizationController",
"creates",
"an",
"organization",
"controller",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/organization.go#L24-L26 |
150,817 | fabric8-services/fabric8-auth | authentication/account/repository/user.go | UserFilterByEmailPrivacy | func UserFilterByEmailPrivacy(privateEmails bool) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where(fmt.Sprintf("email_private IS %v", privateEmails))
}
} | go | func UserFilterByEmailPrivacy(privateEmails bool) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where(fmt.Sprintf("email_private IS %v", privateEmails))
}
} | [
"func",
"UserFilterByEmailPrivacy",
"(",
"privateEmails",
"bool",
")",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db... | // UserFilterByEmailPrivacy is to be used to filter only public or only private emails | [
"UserFilterByEmailPrivacy",
"is",
"to",
"be",
"used",
"to",
"filter",
"only",
"public",
"or",
"only",
"private",
"emails"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/repository/user.go#L223-L227 |
150,818 | fabric8-services/fabric8-auth | authentication/account/service/user.go | NewUserService | func NewUserService(ctx servicecontext.ServiceContext, config UserServiceConfiguration) service.UserService {
return &userServiceImpl{
BaseService: base.NewBaseService(ctx),
config: config,
}
} | go | func NewUserService(ctx servicecontext.ServiceContext, config UserServiceConfiguration) service.UserService {
return &userServiceImpl{
BaseService: base.NewBaseService(ctx),
config: config,
}
} | [
"func",
"NewUserService",
"(",
"ctx",
"servicecontext",
".",
"ServiceContext",
",",
"config",
"UserServiceConfiguration",
")",
"service",
".",
"UserService",
"{",
"return",
"&",
"userServiceImpl",
"{",
"BaseService",
":",
"base",
".",
"NewBaseService",
"(",
"ctx",
... | // NewUserService creates a new service to manage users | [
"NewUserService",
"creates",
"a",
"new",
"service",
"to",
"manage",
"users"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L28-L33 |
150,819 | fabric8-services/fabric8-auth | authentication/account/service/user.go | ResetBan | func (s *userServiceImpl) ResetBan(ctx context.Context, user repository.User) error {
user.Banned = false
return s.ExecuteInTransaction(func() error {
return s.Repositories().Users().Save(ctx, &user)
})
} | go | func (s *userServiceImpl) ResetBan(ctx context.Context, user repository.User) error {
user.Banned = false
return s.ExecuteInTransaction(func() error {
return s.Repositories().Users().Save(ctx, &user)
})
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"ResetBan",
"(",
"ctx",
"context",
".",
"Context",
",",
"user",
"repository",
".",
"User",
")",
"error",
"{",
"user",
".",
"Banned",
"=",
"false",
"\n",
"return",
"s",
".",
"ExecuteInTransaction",
"(",
"func... | // ResetBanned sets User.Banned to false | [
"ResetBanned",
"sets",
"User",
".",
"Banned",
"to",
"false"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L51-L56 |
150,820 | fabric8-services/fabric8-auth | authentication/account/service/user.go | UserInfo | func (s *userServiceImpl) UserInfo(ctx context.Context, identityID uuid.UUID) (*repository.User, *repository.Identity, error) {
var identity *repository.Identity
err := s.ExecuteInTransaction(func() error {
var err error
identity, err = s.Repositories().Identities().LoadWithUser(ctx, identityID)
if err != nil {
return errors.NewUnauthorizedError(fmt.Sprintf("auth token contains id %s of unknown Identity\n", identityID))
}
return nil
})
if err != nil {
return nil, nil, err
}
log.Debug(ctx, map[string]interface{}{
"identity_id": identity.ID,
"user_id": identity.User.ID,
}, "loaded identity and user")
return &identity.User, identity, nil
} | go | func (s *userServiceImpl) UserInfo(ctx context.Context, identityID uuid.UUID) (*repository.User, *repository.Identity, error) {
var identity *repository.Identity
err := s.ExecuteInTransaction(func() error {
var err error
identity, err = s.Repositories().Identities().LoadWithUser(ctx, identityID)
if err != nil {
return errors.NewUnauthorizedError(fmt.Sprintf("auth token contains id %s of unknown Identity\n", identityID))
}
return nil
})
if err != nil {
return nil, nil, err
}
log.Debug(ctx, map[string]interface{}{
"identity_id": identity.ID,
"user_id": identity.User.ID,
}, "loaded identity and user")
return &identity.User, identity, nil
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"UserInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"identityID",
"uuid",
".",
"UUID",
")",
"(",
"*",
"repository",
".",
"User",
",",
"*",
"repository",
".",
"Identity",
",",
"error",
")",
"{",
"var",
... | // UserInfo gets user information given a context containing access_token | [
"UserInfo",
"gets",
"user",
"information",
"given",
"a",
"context",
"containing",
"access_token"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L74-L93 |
150,821 | fabric8-services/fabric8-auth | authentication/account/service/user.go | ListIdentitiesToDeactivate | func (s *userServiceImpl) ListIdentitiesToDeactivate(ctx context.Context, now func() time.Time) ([]repository.Identity, error) {
since := now().Add(-s.config.GetUserDeactivationInactivityPeriodDays()) // remove 'n' days from now (default: 31)
notification := now().Add(s.config.GetUserDeactivationInactivityNotificationPeriodDays() - s.config.GetUserDeactivationInactivityPeriodDays()) // make sure that the notification was sent at least `n` days earlier (default: 7)
limit := s.config.GetUserDeactivationFetchLimit()
return s.Repositories().Identities().ListIdentitiesToDeactivate(ctx, since, notification, limit)
} | go | func (s *userServiceImpl) ListIdentitiesToDeactivate(ctx context.Context, now func() time.Time) ([]repository.Identity, error) {
since := now().Add(-s.config.GetUserDeactivationInactivityPeriodDays()) // remove 'n' days from now (default: 31)
notification := now().Add(s.config.GetUserDeactivationInactivityNotificationPeriodDays() - s.config.GetUserDeactivationInactivityPeriodDays()) // make sure that the notification was sent at least `n` days earlier (default: 7)
limit := s.config.GetUserDeactivationFetchLimit()
return s.Repositories().Identities().ListIdentitiesToDeactivate(ctx, since, notification, limit)
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"ListIdentitiesToDeactivate",
"(",
"ctx",
"context",
".",
"Context",
",",
"now",
"func",
"(",
")",
"time",
".",
"Time",
")",
"(",
"[",
"]",
"repository",
".",
"Identity",
",",
"error",
")",
"{",
"since",
"... | // ListIdentitiesToDeactivate lists the identities to deactivate | [
"ListIdentitiesToDeactivate",
"lists",
"the",
"identities",
"to",
"deactivate"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L195-L201 |
150,822 | fabric8-services/fabric8-auth | authentication/account/service/user.go | RescheduleDeactivation | func (s *userServiceImpl) RescheduleDeactivation(ctx context.Context, identityID uuid.UUID) error {
rescheduledDeactivation := time.Now().Add(s.config.GetUserDeactivationRescheduleDelay())
err := s.ExecuteInTransaction(func() error {
return s.Repositories().Identities().BumpDeactivationSchedule(ctx, identityID, rescheduledDeactivation)
})
return err
} | go | func (s *userServiceImpl) RescheduleDeactivation(ctx context.Context, identityID uuid.UUID) error {
rescheduledDeactivation := time.Now().Add(s.config.GetUserDeactivationRescheduleDelay())
err := s.ExecuteInTransaction(func() error {
return s.Repositories().Identities().BumpDeactivationSchedule(ctx, identityID, rescheduledDeactivation)
})
return err
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"RescheduleDeactivation",
"(",
"ctx",
"context",
".",
"Context",
",",
"identityID",
"uuid",
".",
"UUID",
")",
"error",
"{",
"rescheduledDeactivation",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"s",
... | // RescheduleDeactivation sets the deactivation schedule to a configurable point of time in the future | [
"RescheduleDeactivation",
"sets",
"the",
"deactivation",
"schedule",
"to",
"a",
"configurable",
"point",
"of",
"time",
"in",
"the",
"future"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L310-L318 |
150,823 | fabric8-services/fabric8-auth | authentication/account/service/user.go | ContextIdentityIfExists | func (s *userServiceImpl) ContextIdentityIfExists(ctx context.Context) (uuid.UUID, error) {
identity, err := manager.ContextIdentity(ctx)
if err != nil {
return uuid.Nil, err
}
// Check if the identity exists
err = s.ExecuteInTransaction(func() error {
err := s.Repositories().Identities().CheckExists(ctx, identity.String())
if err != nil {
return errors.NewUnauthorizedError(err.Error())
}
return nil
})
if err != nil {
return uuid.Nil, err
}
return *identity, nil
} | go | func (s *userServiceImpl) ContextIdentityIfExists(ctx context.Context) (uuid.UUID, error) {
identity, err := manager.ContextIdentity(ctx)
if err != nil {
return uuid.Nil, err
}
// Check if the identity exists
err = s.ExecuteInTransaction(func() error {
err := s.Repositories().Identities().CheckExists(ctx, identity.String())
if err != nil {
return errors.NewUnauthorizedError(err.Error())
}
return nil
})
if err != nil {
return uuid.Nil, err
}
return *identity, nil
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"ContextIdentityIfExists",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"uuid",
".",
"UUID",
",",
"error",
")",
"{",
"identity",
",",
"err",
":=",
"manager",
".",
"ContextIdentity",
"(",
"ctx",
")",
"\n"... | // ContextIdentityIfExists returns the identity's ID found in given context if the identity exists in the Auth DB
// If it doesn't exist then an Unauthorized error is returned | [
"ContextIdentityIfExists",
"returns",
"the",
"identity",
"s",
"ID",
"found",
"in",
"given",
"context",
"if",
"the",
"identity",
"exists",
"in",
"the",
"Auth",
"DB",
"If",
"it",
"doesn",
"t",
"exist",
"then",
"an",
"Unauthorized",
"error",
"is",
"returned"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L322-L339 |
150,824 | fabric8-services/fabric8-auth | authentication/account/service/user.go | LoadContextIdentityAndUser | func (s *userServiceImpl) LoadContextIdentityAndUser(ctx context.Context) (*repository.Identity, error) {
identityID, err := manager.ContextIdentity(ctx)
if err != nil {
return nil, errors.NewUnauthorizedError(err.Error())
}
// Check if the identity exists
identity, err := s.Repositories().Identities().LoadWithUser(ctx, *identityID)
if err != nil {
return nil, errors.NewUnauthorizedError(err.Error())
}
return identity, err
} | go | func (s *userServiceImpl) LoadContextIdentityAndUser(ctx context.Context) (*repository.Identity, error) {
identityID, err := manager.ContextIdentity(ctx)
if err != nil {
return nil, errors.NewUnauthorizedError(err.Error())
}
// Check if the identity exists
identity, err := s.Repositories().Identities().LoadWithUser(ctx, *identityID)
if err != nil {
return nil, errors.NewUnauthorizedError(err.Error())
}
return identity, err
} | [
"func",
"(",
"s",
"*",
"userServiceImpl",
")",
"LoadContextIdentityAndUser",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"repository",
".",
"Identity",
",",
"error",
")",
"{",
"identityID",
",",
"err",
":=",
"manager",
".",
"ContextIdentity",
"(",
... | // LoadContextIdentityAndUser returns the identity found in given context if the identity exists in the Auth DB
// If no token present in the context then an Unauthorized error is returned
// If the identity represented by the token doesn't exist in the DB or not associated with any User then an Unauthorized error is returned | [
"LoadContextIdentityAndUser",
"returns",
"the",
"identity",
"found",
"in",
"given",
"context",
"if",
"the",
"identity",
"exists",
"in",
"the",
"Auth",
"DB",
"If",
"no",
"token",
"present",
"in",
"the",
"context",
"then",
"an",
"Unauthorized",
"error",
"is",
"r... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/account/service/user.go#L344-L356 |
150,825 | fabric8-services/fabric8-auth | authentication/provider/factory/identity_provider_factory.go | NewIdentityProviderFactory | func NewIdentityProviderFactory(context servicecontext.ServiceContext) service.IdentityProviderFactory {
factory := &identityProviderFactoryImpl{
BaseService: base.NewBaseService(context),
}
return factory
} | go | func NewIdentityProviderFactory(context servicecontext.ServiceContext) service.IdentityProviderFactory {
factory := &identityProviderFactoryImpl{
BaseService: base.NewBaseService(context),
}
return factory
} | [
"func",
"NewIdentityProviderFactory",
"(",
"context",
"servicecontext",
".",
"ServiceContext",
")",
"service",
".",
"IdentityProviderFactory",
"{",
"factory",
":=",
"&",
"identityProviderFactoryImpl",
"{",
"BaseService",
":",
"base",
".",
"NewBaseService",
"(",
"context... | // NewIdentityProviderFactory returns the default Oauth provider factory. | [
"NewIdentityProviderFactory",
"returns",
"the",
"default",
"Oauth",
"provider",
"factory",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/provider/factory/identity_provider_factory.go#L13-L18 |
150,826 | fabric8-services/fabric8-auth | authentication/provider/factory/identity_provider_factory.go | NewIdentityProvider | func (f *identityProviderFactoryImpl) NewIdentityProvider(ctx context.Context, config provider.IdentityProviderConfiguration) provider.IdentityProvider {
return provider.NewIdentityProvider(config)
} | go | func (f *identityProviderFactoryImpl) NewIdentityProvider(ctx context.Context, config provider.IdentityProviderConfiguration) provider.IdentityProvider {
return provider.NewIdentityProvider(config)
} | [
"func",
"(",
"f",
"*",
"identityProviderFactoryImpl",
")",
"NewIdentityProvider",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"provider",
".",
"IdentityProviderConfiguration",
")",
"provider",
".",
"IdentityProvider",
"{",
"return",
"provider",
".",
"NewId... | // NewIdentityProvider creates a new identity provider based on the specified configuration | [
"NewIdentityProvider",
"creates",
"a",
"new",
"identity",
"provider",
"based",
"on",
"the",
"specified",
"configuration"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/provider/factory/identity_provider_factory.go#L25-L27 |
150,827 | fabric8-services/fabric8-auth | cluster/service/cache.go | Start | func (c *cache) Start(ctx context.Context) error {
err := c.refreshCache(ctx)
if err != nil {
return err
}
c.stopCh = make(chan bool, 1)
go func() {
defer log.Info(nil, map[string]interface{}{}, "cluster cache refresher stopped")
log.Info(nil, map[string]interface{}{"interval": c.config.GetClusterCacheRefreshInterval()}, "cluster cache refresher started")
for {
select {
case <-c.refresher.C:
err := c.refreshCache(context.Background())
if err != nil {
log.Error(nil, map[string]interface{}{"err": err}, "failed to load the list of clusters during cache refresh")
}
case <-c.stopCh:
return
}
}
}()
return nil
} | go | func (c *cache) Start(ctx context.Context) error {
err := c.refreshCache(ctx)
if err != nil {
return err
}
c.stopCh = make(chan bool, 1)
go func() {
defer log.Info(nil, map[string]interface{}{}, "cluster cache refresher stopped")
log.Info(nil, map[string]interface{}{"interval": c.config.GetClusterCacheRefreshInterval()}, "cluster cache refresher started")
for {
select {
case <-c.refresher.C:
err := c.refreshCache(context.Background())
if err != nil {
log.Error(nil, map[string]interface{}{"err": err}, "failed to load the list of clusters during cache refresh")
}
case <-c.stopCh:
return
}
}
}()
return nil
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"err",
":=",
"c",
".",
"refreshCache",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"... | // start loads the list of clusters from Cluster Management Service into the cluster cache and initializes regular cache refreshing | [
"start",
"loads",
"the",
"list",
"of",
"clusters",
"from",
"Cluster",
"Management",
"Service",
"into",
"the",
"cluster",
"cache",
"and",
"initializes",
"regular",
"cache",
"refreshing"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/cluster/service/cache.go#L44-L67 |
150,828 | fabric8-services/fabric8-auth | cluster/service/cache.go | fetchClusters | func (c *cache) fetchClusters(ctx context.Context) (map[string]cluster.Cluster, error) {
signer := newJWTSASigner(ctx, c.config, c.options...)
cln, err := signer.createSignedClient()
if err != nil {
return nil, err
}
res, err := cln.ShowAuthClientClusters(goasupport.ForwardContextRequestID(ctx), clusterclient.ShowAuthClientClustersPath())
if err != nil {
return nil, err
}
defer rest.CloseResponse(res)
if res.StatusCode != http.StatusOK {
bodyString := rest.ReadBody(res.Body)
log.Error(ctx, map[string]interface{}{
"response_status": res.Status,
"response_body": bodyString,
}, "unable to get clusters from Cluster Management Service")
return nil, errors.Errorf("unable to get clusters from Cluster Management Service. Response status: %s. Response body: %s", res.Status, bodyString)
}
clusters, err := cln.DecodeFullClusterList(res)
if err != nil {
return nil, err
}
clusterMap := map[string]cluster.Cluster{}
if clusters.Data != nil {
for _, d := range clusters.Data {
cls := cluster.Cluster{
Name: d.Name,
APIURL: d.APIURL,
AppDNS: d.AppDNS,
ConsoleURL: d.ConsoleURL,
LoggingURL: d.LoggingURL,
MetricsURL: d.MetricsURL,
TokenProviderID: d.TokenProviderID,
AuthClientDefaultScope: d.AuthClientDefaultScope,
AuthClientID: d.AuthClientID,
AuthClientSecret: d.AuthClientSecret,
ServiceAccountUsername: d.ServiceAccountUsername,
ServiceAccountToken: d.ServiceAccountToken,
CapacityExhausted: d.CapacityExhausted,
}
clusterMap[rest.AddTrailingSlashToURL(cls.APIURL)] = cls
}
}
return clusterMap, nil
} | go | func (c *cache) fetchClusters(ctx context.Context) (map[string]cluster.Cluster, error) {
signer := newJWTSASigner(ctx, c.config, c.options...)
cln, err := signer.createSignedClient()
if err != nil {
return nil, err
}
res, err := cln.ShowAuthClientClusters(goasupport.ForwardContextRequestID(ctx), clusterclient.ShowAuthClientClustersPath())
if err != nil {
return nil, err
}
defer rest.CloseResponse(res)
if res.StatusCode != http.StatusOK {
bodyString := rest.ReadBody(res.Body)
log.Error(ctx, map[string]interface{}{
"response_status": res.Status,
"response_body": bodyString,
}, "unable to get clusters from Cluster Management Service")
return nil, errors.Errorf("unable to get clusters from Cluster Management Service. Response status: %s. Response body: %s", res.Status, bodyString)
}
clusters, err := cln.DecodeFullClusterList(res)
if err != nil {
return nil, err
}
clusterMap := map[string]cluster.Cluster{}
if clusters.Data != nil {
for _, d := range clusters.Data {
cls := cluster.Cluster{
Name: d.Name,
APIURL: d.APIURL,
AppDNS: d.AppDNS,
ConsoleURL: d.ConsoleURL,
LoggingURL: d.LoggingURL,
MetricsURL: d.MetricsURL,
TokenProviderID: d.TokenProviderID,
AuthClientDefaultScope: d.AuthClientDefaultScope,
AuthClientID: d.AuthClientID,
AuthClientSecret: d.AuthClientSecret,
ServiceAccountUsername: d.ServiceAccountUsername,
ServiceAccountToken: d.ServiceAccountToken,
CapacityExhausted: d.CapacityExhausted,
}
clusterMap[rest.AddTrailingSlashToURL(cls.APIURL)] = cls
}
}
return clusterMap, nil
} | [
"func",
"(",
"c",
"*",
"cache",
")",
"fetchClusters",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"string",
"]",
"cluster",
".",
"Cluster",
",",
"error",
")",
"{",
"signer",
":=",
"newJWTSASigner",
"(",
"ctx",
",",
"c",
".",
"config"... | // fetchClusters fetches a new list of clusters from Cluster Management Service | [
"fetchClusters",
"fetches",
"a",
"new",
"list",
"of",
"clusters",
"from",
"Cluster",
"Management",
"Service"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/cluster/service/cache.go#L93-L142 |
150,829 | fabric8-services/fabric8-auth | authorization/resourcetype/repository/resource_type_scope.go | List | func (m *GormResourceTypeScopeRepository) List(ctx context.Context, resourceType *ResourceType) ([]ResourceTypeScope, error) {
defer goa.MeasureSince([]string{"goa", "db", "resource_type_scope", "list"}, time.Now())
var rows []ResourceTypeScope
var err error
if resourceType != nil {
err = m.db.Where("resource_type_id = ?", resourceType.ResourceTypeID).Order("name").Find(&rows).Error
} else {
err = m.db.Order("name").Find(&rows).Error
}
if err != nil && err != gorm.ErrRecordNotFound {
return nil, errs.WithStack(err)
}
return rows, nil
} | go | func (m *GormResourceTypeScopeRepository) List(ctx context.Context, resourceType *ResourceType) ([]ResourceTypeScope, error) {
defer goa.MeasureSince([]string{"goa", "db", "resource_type_scope", "list"}, time.Now())
var rows []ResourceTypeScope
var err error
if resourceType != nil {
err = m.db.Where("resource_type_id = ?", resourceType.ResourceTypeID).Order("name").Find(&rows).Error
} else {
err = m.db.Order("name").Find(&rows).Error
}
if err != nil && err != gorm.ErrRecordNotFound {
return nil, errs.WithStack(err)
}
return rows, nil
} | [
"func",
"(",
"m",
"*",
"GormResourceTypeScopeRepository",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"resourceType",
"*",
"ResourceType",
")",
"(",
"[",
"]",
"ResourceTypeScope",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",... | // List return all resource type scopes | [
"List",
"return",
"all",
"resource",
"type",
"scopes"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resourcetype/repository/resource_type_scope.go#L189-L203 |
150,830 | fabric8-services/fabric8-auth | authorization/resourcetype/repository/resource_type_scope.go | LookupByResourceTypeAndScope | func (m *GormResourceTypeScopeRepository) LookupByResourceTypeAndScope(ctx context.Context, resourceTypeID uuid.UUID, name string) (*ResourceTypeScope, error) {
vals, err := m.Query(FilterByScopeName(name), FilterByResourceTypeID(resourceTypeID))
if len(vals) == 0 {
return nil, err
}
return &vals[0], err
} | go | func (m *GormResourceTypeScopeRepository) LookupByResourceTypeAndScope(ctx context.Context, resourceTypeID uuid.UUID, name string) (*ResourceTypeScope, error) {
vals, err := m.Query(FilterByScopeName(name), FilterByResourceTypeID(resourceTypeID))
if len(vals) == 0 {
return nil, err
}
return &vals[0], err
} | [
"func",
"(",
"m",
"*",
"GormResourceTypeScopeRepository",
")",
"LookupByResourceTypeAndScope",
"(",
"ctx",
"context",
".",
"Context",
",",
"resourceTypeID",
"uuid",
".",
"UUID",
",",
"name",
"string",
")",
"(",
"*",
"ResourceTypeScope",
",",
"error",
")",
"{",
... | // LookupByResourceTypeAndScope returns all resource type scopes filtered by name and scope. | [
"LookupByResourceTypeAndScope",
"returns",
"all",
"resource",
"type",
"scopes",
"filtered",
"by",
"name",
"and",
"scope",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resourcetype/repository/resource_type_scope.go#L206-L212 |
150,831 | fabric8-services/fabric8-auth | authorization/resourcetype/repository/resource_type_scope.go | FilterByScopeName | func FilterByScopeName(name string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("name = ?", name)
}
} | go | func FilterByScopeName(name string) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("name = ?", name)
}
} | [
"func",
"FilterByScopeName",
"(",
"name",
"string",
")",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db",
".",
"W... | // FilterByScopeName is a gorm filter by 'name' | [
"FilterByScopeName",
"is",
"a",
"gorm",
"filter",
"by",
"name"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resourcetype/repository/resource_type_scope.go#L230-L234 |
150,832 | fabric8-services/fabric8-auth | authorization/resourcetype/repository/resource_type_scope.go | FilterByResourceTypeID | func FilterByResourceTypeID(id uuid.UUID) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("resource_type_id = ?", id.String())
}
} | go | func FilterByResourceTypeID(id uuid.UUID) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
return db.Where("resource_type_id = ?", id.String())
}
} | [
"func",
"FilterByResourceTypeID",
"(",
"id",
"uuid",
".",
"UUID",
")",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
... | // FilterByResourceTypeID is a gorm filter by 'name' | [
"FilterByResourceTypeID",
"is",
"a",
"gorm",
"filter",
"by",
"name"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resourcetype/repository/resource_type_scope.go#L237-L241 |
150,833 | fabric8-services/fabric8-auth | controller/login.go | Login | func (c *LoginController) Login(ctx *app.LoginLoginContext) error {
// Generate a new unique state value
state := uuid.NewV4().String()
// Get the URL of the callback endpoint, the client will be redirected here after being redirected to the authentication provider
callbackURL := rest.AbsoluteURL(ctx.RequestData, client.CallbackLoginPath(), nil)
// Remove this: once we remove support for offline token completely
var scopes []string
if ctx.Scope != nil {
scopes = append(scopes, *ctx.Scope)
}
redirectURL, err := c.app.AuthenticationProviderService().GenerateAuthCodeURL(ctx, ctx.Redirect, ctx.APIClient,
&state, scopes, nil, ctx.RequestData.Header.Get("Referer"), callbackURL)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
ctx.ResponseData.Header().Set("Location", *redirectURL)
return ctx.TemporaryRedirect()
} | go | func (c *LoginController) Login(ctx *app.LoginLoginContext) error {
// Generate a new unique state value
state := uuid.NewV4().String()
// Get the URL of the callback endpoint, the client will be redirected here after being redirected to the authentication provider
callbackURL := rest.AbsoluteURL(ctx.RequestData, client.CallbackLoginPath(), nil)
// Remove this: once we remove support for offline token completely
var scopes []string
if ctx.Scope != nil {
scopes = append(scopes, *ctx.Scope)
}
redirectURL, err := c.app.AuthenticationProviderService().GenerateAuthCodeURL(ctx, ctx.Redirect, ctx.APIClient,
&state, scopes, nil, ctx.RequestData.Header.Get("Referer"), callbackURL)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
ctx.ResponseData.Header().Set("Location", *redirectURL)
return ctx.TemporaryRedirect()
} | [
"func",
"(",
"c",
"*",
"LoginController",
")",
"Login",
"(",
"ctx",
"*",
"app",
".",
"LoginLoginContext",
")",
"error",
"{",
"// Generate a new unique state value",
"state",
":=",
"uuid",
".",
"NewV4",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"// Get the U... | // Login runs the login action. | [
"Login",
"runs",
"the",
"login",
"action",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/login.go#L28-L48 |
150,834 | fabric8-services/fabric8-auth | authorization/token/service/token_service.go | NewTokenService | func NewTokenService(context servicecontext.ServiceContext, config TokenServiceConfiguration) service.TokenService {
tokenManager, err := manager.NewTokenManager(config)
if err != nil {
log.Panic(nil, map[string]interface{}{
"err": err,
}, "failed to create token manager")
}
return &tokenServiceImpl{
BaseService: base.NewBaseService(context),
config: config,
tokenManager: tokenManager,
}
} | go | func NewTokenService(context servicecontext.ServiceContext, config TokenServiceConfiguration) service.TokenService {
tokenManager, err := manager.NewTokenManager(config)
if err != nil {
log.Panic(nil, map[string]interface{}{
"err": err,
}, "failed to create token manager")
}
return &tokenServiceImpl{
BaseService: base.NewBaseService(context),
config: config,
tokenManager: tokenManager,
}
} | [
"func",
"NewTokenService",
"(",
"context",
"servicecontext",
".",
"ServiceContext",
",",
"config",
"TokenServiceConfiguration",
")",
"service",
".",
"TokenService",
"{",
"tokenManager",
",",
"err",
":=",
"manager",
".",
"NewTokenManager",
"(",
"config",
")",
"\n",
... | // NewTokenService returns a new Token Service | [
"NewTokenService",
"returns",
"a",
"new",
"Token",
"Service"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/token/service/token_service.go#L43-L56 |
150,835 | fabric8-services/fabric8-auth | authorization/token/service/token_service.go | RegisterToken | func (s *tokenServiceImpl) RegisterToken(ctx context.Context, identityID uuid.UUID, tokenString string, tokenType string,
privileges []tokenrepo.TokenPrivilege) (*tokenrepo.Token, error) {
// Parse the claims from the provided token string
tokenClaims, err := s.tokenManager.ParseToken(ctx, tokenString)
if err != nil {
log.Error(ctx, map[string]interface{}{"error": err}, "invalid token string could not be parsed")
return nil, errors.NewBadParameterErrorFromString("tokenString", tokenString,
"invalid token string could not be parsed")
}
// Extract the id from the refresh token
tokenID, err := uuid.FromString(tokenClaims.Id)
if err != nil {
log.Error(ctx, map[string]interface{}{"error": err}, "could not extract token ID from token string")
return nil, errors.NewBadParameterErrorFromString("tokenString", tokenString,
"could not extract token ID from token string")
}
expiryTime := time.Unix(tokenClaims.ExpiresAt, 0)
tkn := &tokenrepo.Token{
TokenID: tokenID,
IdentityID: identityID,
Status: 0,
TokenType: tokenType,
ExpiryTime: expiryTime,
}
// Persist the token record to the database
err = s.ExecuteInTransaction(func() error {
err = s.Repositories().TokenRepository().Create(ctx, tkn)
if err != nil {
return err
}
// If the access token is an RPT, register its permissions also
if privileges != nil && len(privileges) > 0 {
// Assign privileges to the token record, and persist them to the database
for _, tokenPriv := range privileges {
tokenPriv.TokenID = tokenID
err = s.Repositories().TokenRepository().CreatePrivilege(ctx, &tokenPriv)
if err != nil {
return err
}
}
}
return nil
})
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return tkn, nil
} | go | func (s *tokenServiceImpl) RegisterToken(ctx context.Context, identityID uuid.UUID, tokenString string, tokenType string,
privileges []tokenrepo.TokenPrivilege) (*tokenrepo.Token, error) {
// Parse the claims from the provided token string
tokenClaims, err := s.tokenManager.ParseToken(ctx, tokenString)
if err != nil {
log.Error(ctx, map[string]interface{}{"error": err}, "invalid token string could not be parsed")
return nil, errors.NewBadParameterErrorFromString("tokenString", tokenString,
"invalid token string could not be parsed")
}
// Extract the id from the refresh token
tokenID, err := uuid.FromString(tokenClaims.Id)
if err != nil {
log.Error(ctx, map[string]interface{}{"error": err}, "could not extract token ID from token string")
return nil, errors.NewBadParameterErrorFromString("tokenString", tokenString,
"could not extract token ID from token string")
}
expiryTime := time.Unix(tokenClaims.ExpiresAt, 0)
tkn := &tokenrepo.Token{
TokenID: tokenID,
IdentityID: identityID,
Status: 0,
TokenType: tokenType,
ExpiryTime: expiryTime,
}
// Persist the token record to the database
err = s.ExecuteInTransaction(func() error {
err = s.Repositories().TokenRepository().Create(ctx, tkn)
if err != nil {
return err
}
// If the access token is an RPT, register its permissions also
if privileges != nil && len(privileges) > 0 {
// Assign privileges to the token record, and persist them to the database
for _, tokenPriv := range privileges {
tokenPriv.TokenID = tokenID
err = s.Repositories().TokenRepository().CreatePrivilege(ctx, &tokenPriv)
if err != nil {
return err
}
}
}
return nil
})
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return tkn, nil
} | [
"func",
"(",
"s",
"*",
"tokenServiceImpl",
")",
"RegisterToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"identityID",
"uuid",
".",
"UUID",
",",
"tokenString",
"string",
",",
"tokenType",
"string",
",",
"privileges",
"[",
"]",
"tokenrepo",
".",
"TokenPri... | // RegisterToken creates a token record in the token repository for the specified token string | [
"RegisterToken",
"creates",
"a",
"token",
"record",
"in",
"the",
"token",
"repository",
"for",
"the",
"specified",
"token",
"string"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/token/service/token_service.go#L512-L568 |
150,836 | fabric8-services/fabric8-auth | authorization/token/service/token_service.go | SetStatusForAllIdentityTokens | func (s *tokenServiceImpl) SetStatusForAllIdentityTokens(ctx context.Context, identityID uuid.UUID, status int) error {
identity, err := s.Repositories().Identities().LoadWithUser(ctx, identityID)
if err != nil {
return err
}
// Load all tokens for the identity
tokens, err := s.Repositories().TokenRepository().ListForIdentity(ctx, identity.ID)
if err != nil {
return err
}
err = s.ExecuteInTransaction(func() error {
// Update all the token status flags
err = s.Repositories().TokenRepository().SetStatusFlagsForIdentity(ctx, identity.ID, status)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"identity_id": identity.ID,
}, "Unable to update status values for identity.")
return err
}
return nil
})
log.Debug(ctx, map[string]interface{}{
"identity_id": identity.ID,
"tokens": len(tokens),
}, "Updated all token status values for identity.")
return err
} | go | func (s *tokenServiceImpl) SetStatusForAllIdentityTokens(ctx context.Context, identityID uuid.UUID, status int) error {
identity, err := s.Repositories().Identities().LoadWithUser(ctx, identityID)
if err != nil {
return err
}
// Load all tokens for the identity
tokens, err := s.Repositories().TokenRepository().ListForIdentity(ctx, identity.ID)
if err != nil {
return err
}
err = s.ExecuteInTransaction(func() error {
// Update all the token status flags
err = s.Repositories().TokenRepository().SetStatusFlagsForIdentity(ctx, identity.ID, status)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"identity_id": identity.ID,
}, "Unable to update status values for identity.")
return err
}
return nil
})
log.Debug(ctx, map[string]interface{}{
"identity_id": identity.ID,
"tokens": len(tokens),
}, "Updated all token status values for identity.")
return err
} | [
"func",
"(",
"s",
"*",
"tokenServiceImpl",
")",
"SetStatusForAllIdentityTokens",
"(",
"ctx",
"context",
".",
"Context",
",",
"identityID",
"uuid",
".",
"UUID",
",",
"status",
"int",
")",
"error",
"{",
"identity",
",",
"err",
":=",
"s",
".",
"Repositories",
... | // SetStatusForAllIdentityTokens parses the specified token string and extracts the sub claim, using it to then load
// all tokens for that identity and setting their status flag with the specified status value | [
"SetStatusForAllIdentityTokens",
"parses",
"the",
"specified",
"token",
"string",
"and",
"extracts",
"the",
"sub",
"claim",
"using",
"it",
"to",
"then",
"load",
"all",
"tokens",
"for",
"that",
"identity",
"and",
"setting",
"their",
"status",
"flag",
"with",
"the... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/token/service/token_service.go#L708-L739 |
150,837 | fabric8-services/fabric8-auth | authentication/provider/service/link_service.go | NewLinkService | func NewLinkService(context servicecontext.ServiceContext, config LinkServiceConfiguration) service.LinkService {
return &linkServiceImpl{
BaseService: base.NewBaseService(context),
config: config,
}
} | go | func NewLinkService(context servicecontext.ServiceContext, config LinkServiceConfiguration) service.LinkService {
return &linkServiceImpl{
BaseService: base.NewBaseService(context),
config: config,
}
} | [
"func",
"NewLinkService",
"(",
"context",
"servicecontext",
".",
"ServiceContext",
",",
"config",
"LinkServiceConfiguration",
")",
"service",
".",
"LinkService",
"{",
"return",
"&",
"linkServiceImpl",
"{",
"BaseService",
":",
"base",
".",
"NewBaseService",
"(",
"con... | // NewLinkService creates a new service for linking accounts | [
"NewLinkService",
"creates",
"a",
"new",
"service",
"for",
"linking",
"accounts"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authentication/provider/service/link_service.go#L34-L39 |
150,838 | fabric8-services/fabric8-auth | migration/migration.go | Migrate | func Migrate(db *sql.DB, catalog string, configuration MigrationConfiguration) error {
var err error
if db == nil {
return errs.Errorf("Database handle is nil\n")
}
m := GetMigrations(configuration)
var tx *sql.Tx
for nextVersion := int64(0); nextVersion < int64(len(m)) && err == nil; nextVersion++ {
tx, err = db.Begin()
if err != nil {
return errs.Errorf("Failed to start transaction: %s\n", err)
}
err = MigrateToNextVersion(tx, &nextVersion, m, catalog)
if err != nil {
oldErr := err
log.Info(nil, map[string]interface{}{
"next_version": nextVersion,
"migrations": m,
"err": err,
}, "Rolling back transaction due to: %v", err)
if err = tx.Rollback(); err != nil {
log.Error(nil, map[string]interface{}{
"next_version": nextVersion,
"migrations": m,
"err": err,
}, "error while rolling back transaction")
return errs.Errorf("Error while rolling back transaction: %s\n", err)
}
return oldErr
}
if err = tx.Commit(); err != nil {
log.Error(nil, map[string]interface{}{
"migrations": m,
"err": err,
}, "error during transaction commit: %v", err)
return errs.Errorf("Error during transaction commit: %s\n", err)
}
}
if err != nil {
log.Error(nil, map[string]interface{}{
"migrations": m,
"err": err,
}, "migration failed with error: %v", err)
return errs.Errorf("Migration failed with error: %s\n", err)
}
return nil
} | go | func Migrate(db *sql.DB, catalog string, configuration MigrationConfiguration) error {
var err error
if db == nil {
return errs.Errorf("Database handle is nil\n")
}
m := GetMigrations(configuration)
var tx *sql.Tx
for nextVersion := int64(0); nextVersion < int64(len(m)) && err == nil; nextVersion++ {
tx, err = db.Begin()
if err != nil {
return errs.Errorf("Failed to start transaction: %s\n", err)
}
err = MigrateToNextVersion(tx, &nextVersion, m, catalog)
if err != nil {
oldErr := err
log.Info(nil, map[string]interface{}{
"next_version": nextVersion,
"migrations": m,
"err": err,
}, "Rolling back transaction due to: %v", err)
if err = tx.Rollback(); err != nil {
log.Error(nil, map[string]interface{}{
"next_version": nextVersion,
"migrations": m,
"err": err,
}, "error while rolling back transaction")
return errs.Errorf("Error while rolling back transaction: %s\n", err)
}
return oldErr
}
if err = tx.Commit(); err != nil {
log.Error(nil, map[string]interface{}{
"migrations": m,
"err": err,
}, "error during transaction commit: %v", err)
return errs.Errorf("Error during transaction commit: %s\n", err)
}
}
if err != nil {
log.Error(nil, map[string]interface{}{
"migrations": m,
"err": err,
}, "migration failed with error: %v", err)
return errs.Errorf("Migration failed with error: %s\n", err)
}
return nil
} | [
"func",
"Migrate",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"catalog",
"string",
",",
"configuration",
"MigrationConfiguration",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"db",
"==",
"nil",
"{",
"return",
"errs",
".",
"Errorf",
"(",
"\"",
"\\... | // Migrate executes the required migration of the database on startup.
// For each successful migration, an entry will be written into the "version"
// table, that states when a certain version was reached. | [
"Migrate",
"executes",
"the",
"required",
"migration",
"of",
"the",
"database",
"on",
"startup",
".",
"For",
"each",
"successful",
"migration",
"an",
"entry",
"will",
"be",
"written",
"into",
"the",
"version",
"table",
"that",
"states",
"when",
"a",
"certain",... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/migration/migration.go#L43-L100 |
150,839 | fabric8-services/fabric8-auth | controller/invitation.go | NewInvitationController | func NewInvitationController(service *goa.Service, app application.Application, configuration InvitationControllerConfiguration) *InvitationController {
return &InvitationController{
Controller: service.NewController("InvitationController"),
app: app,
config: configuration,
}
} | go | func NewInvitationController(service *goa.Service, app application.Application, configuration InvitationControllerConfiguration) *InvitationController {
return &InvitationController{
Controller: service.NewController("InvitationController"),
app: app,
config: configuration,
}
} | [
"func",
"NewInvitationController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"app",
"application",
".",
"Application",
",",
"configuration",
"InvitationControllerConfiguration",
")",
"*",
"InvitationController",
"{",
"return",
"&",
"InvitationController",
"{",
... | // NewInvitationController creates a invitation controller. | [
"NewInvitationController",
"creates",
"a",
"invitation",
"controller",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/invitation.go#L28-L34 |
150,840 | fabric8-services/fabric8-auth | controller/invitation.go | CreateInvite | func (c *InvitationController) CreateInvite(ctx *app.CreateInviteInvitationContext) error {
currentIdentity, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
var redirectOnSuccess, redirectOnFailure string
links := ctx.Payload.Links
if links != nil {
if links.OnSuccess != nil {
redirectOnSuccess = *links.OnSuccess
}
if links.OnFailure != nil {
redirectOnFailure = *links.OnFailure
}
}
var invitations []invitation.Invitation
for _, invitee := range ctx.Payload.Data {
// Validate that an identifying parameter has been set
if invitee.IdentityID == nil {
return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterErrorFromString("user identifier", "", "no identifier provided"))
}
// If an identity ID has been provided for the user, convert it to a UUID here
var identityID uuid.UUID
if invitee.IdentityID != nil && *invitee.IdentityID != "" {
identityID, err = uuid.FromString(*invitee.IdentityID)
}
// Create the Invitation object, and append it to our list of invitations
invitations = append(invitations, invitation.Invitation{
IdentityID: &identityID,
Roles: invitee.Roles,
Member: *invitee.Member,
RedirectOnSuccess: redirectOnSuccess,
RedirectOnFailure: redirectOnFailure,
})
}
err = c.app.InvitationService().Issue(ctx, currentIdentity.ID, ctx.InviteTo, invitations)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to create invitations")
return jsonapi.JSONErrorResponse(ctx, err)
}
log.Debug(ctx, map[string]interface{}{
"issuing-user-id": *currentIdentity,
"invite-to": ctx.InviteTo,
}, "invitations created")
return ctx.Created()
} | go | func (c *InvitationController) CreateInvite(ctx *app.CreateInviteInvitationContext) error {
currentIdentity, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
var redirectOnSuccess, redirectOnFailure string
links := ctx.Payload.Links
if links != nil {
if links.OnSuccess != nil {
redirectOnSuccess = *links.OnSuccess
}
if links.OnFailure != nil {
redirectOnFailure = *links.OnFailure
}
}
var invitations []invitation.Invitation
for _, invitee := range ctx.Payload.Data {
// Validate that an identifying parameter has been set
if invitee.IdentityID == nil {
return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterErrorFromString("user identifier", "", "no identifier provided"))
}
// If an identity ID has been provided for the user, convert it to a UUID here
var identityID uuid.UUID
if invitee.IdentityID != nil && *invitee.IdentityID != "" {
identityID, err = uuid.FromString(*invitee.IdentityID)
}
// Create the Invitation object, and append it to our list of invitations
invitations = append(invitations, invitation.Invitation{
IdentityID: &identityID,
Roles: invitee.Roles,
Member: *invitee.Member,
RedirectOnSuccess: redirectOnSuccess,
RedirectOnFailure: redirectOnFailure,
})
}
err = c.app.InvitationService().Issue(ctx, currentIdentity.ID, ctx.InviteTo, invitations)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to create invitations")
return jsonapi.JSONErrorResponse(ctx, err)
}
log.Debug(ctx, map[string]interface{}{
"issuing-user-id": *currentIdentity,
"invite-to": ctx.InviteTo,
}, "invitations created")
return ctx.Created()
} | [
"func",
"(",
"c",
"*",
"InvitationController",
")",
"CreateInvite",
"(",
"ctx",
"*",
"app",
".",
"CreateInviteInvitationContext",
")",
"error",
"{",
"currentIdentity",
",",
"err",
":=",
"c",
".",
"app",
".",
"UserService",
"(",
")",
".",
"LoadContextIdentityIf... | // CreateInvite runs the create action. | [
"CreateInvite",
"runs",
"the",
"create",
"action",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/invitation.go#L37-L94 |
150,841 | fabric8-services/fabric8-auth | controller/invitation.go | RescindInvite | func (c *InvitationController) RescindInvite(ctx *app.RescindInviteInvitationContext) error {
currentIdentity, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
invitationID, err := uuid.FromString(ctx.InviteTo)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"invitationID": invitationID,
}, "failed to rescind invitation, invalid invitation id")
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("invitationID", invitationID.String()))
}
err = c.app.InvitationService().Rescind(ctx, currentIdentity.ID, invitationID)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"invitationID": invitationID,
}, "failed to rescind invitation")
return jsonapi.JSONErrorResponse(ctx, err)
}
log.Debug(ctx, map[string]interface{}{
"rescinding-user-id": *currentIdentity,
"invitation-id": ctx.InviteTo,
}, "invitation rescind")
return ctx.OK([]byte{})
} | go | func (c *InvitationController) RescindInvite(ctx *app.RescindInviteInvitationContext) error {
currentIdentity, err := c.app.UserService().LoadContextIdentityIfNotBanned(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
invitationID, err := uuid.FromString(ctx.InviteTo)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"invitationID": invitationID,
}, "failed to rescind invitation, invalid invitation id")
return jsonapi.JSONErrorResponse(ctx, errors.NewNotFoundError("invitationID", invitationID.String()))
}
err = c.app.InvitationService().Rescind(ctx, currentIdentity.ID, invitationID)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"invitationID": invitationID,
}, "failed to rescind invitation")
return jsonapi.JSONErrorResponse(ctx, err)
}
log.Debug(ctx, map[string]interface{}{
"rescinding-user-id": *currentIdentity,
"invitation-id": ctx.InviteTo,
}, "invitation rescind")
return ctx.OK([]byte{})
} | [
"func",
"(",
"c",
"*",
"InvitationController",
")",
"RescindInvite",
"(",
"ctx",
"*",
"app",
".",
"RescindInviteInvitationContext",
")",
"error",
"{",
"currentIdentity",
",",
"err",
":=",
"c",
".",
"app",
".",
"UserService",
"(",
")",
".",
"LoadContextIdentity... | // RescindInvite runs the revoke action. | [
"RescindInvite",
"runs",
"the",
"revoke",
"action",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/invitation.go#L97-L129 |
150,842 | fabric8-services/fabric8-auth | authorization/resource/service/resource_service.go | NewResourceService | func NewResourceService(context servicecontext.ServiceContext) service.ResourceService {
return &resourceServiceImpl{base.NewBaseService(context)}
} | go | func NewResourceService(context servicecontext.ServiceContext) service.ResourceService {
return &resourceServiceImpl{base.NewBaseService(context)}
} | [
"func",
"NewResourceService",
"(",
"context",
"servicecontext",
".",
"ServiceContext",
")",
"service",
".",
"ResourceService",
"{",
"return",
"&",
"resourceServiceImpl",
"{",
"base",
".",
"NewBaseService",
"(",
"context",
")",
"}",
"\n",
"}"
] | // NewResourceService creates a new service. | [
"NewResourceService",
"creates",
"a",
"new",
"service",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resource/service/resource_service.go#L24-L26 |
150,843 | fabric8-services/fabric8-auth | authorization/resource/service/resource_service.go | Read | func (s *resourceServiceImpl) Read(ctx context.Context, resourceID string) (*app.Resource, error) {
res, err := s.Repositories().ResourceRepository().Load(ctx, resourceID)
if err != nil {
return nil, err
}
// Load the resource type scopes
scopes, err := s.Repositories().ResourceTypeScopeRepository().LookupForType(ctx, res.ResourceTypeID)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
var scopeValues []string
for index := range scopes {
scopeValues = append(scopeValues, scopes[index].Name)
}
return &app.Resource{
ResourceID: &res.ResourceID,
Type: &res.ResourceType.Name,
ParentResourceID: res.ParentResourceID,
ResourceScopes: scopeValues,
}, nil
} | go | func (s *resourceServiceImpl) Read(ctx context.Context, resourceID string) (*app.Resource, error) {
res, err := s.Repositories().ResourceRepository().Load(ctx, resourceID)
if err != nil {
return nil, err
}
// Load the resource type scopes
scopes, err := s.Repositories().ResourceTypeScopeRepository().LookupForType(ctx, res.ResourceTypeID)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
var scopeValues []string
for index := range scopes {
scopeValues = append(scopeValues, scopes[index].Name)
}
return &app.Resource{
ResourceID: &res.ResourceID,
Type: &res.ResourceType.Name,
ParentResourceID: res.ParentResourceID,
ResourceScopes: scopeValues,
}, nil
} | [
"func",
"(",
"s",
"*",
"resourceServiceImpl",
")",
"Read",
"(",
"ctx",
"context",
".",
"Context",
",",
"resourceID",
"string",
")",
"(",
"*",
"app",
".",
"Resource",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"s",
".",
"Repositories",
"(",
")",... | // Read reads resource | [
"Read",
"reads",
"resource"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resource/service/resource_service.go#L81-L106 |
150,844 | fabric8-services/fabric8-auth | authorization/resource/service/resource_service.go | CheckExists | func (s *resourceServiceImpl) CheckExists(ctx context.Context, resourceID string) error {
return s.Repositories().ResourceRepository().CheckExists(ctx, resourceID)
} | go | func (s *resourceServiceImpl) CheckExists(ctx context.Context, resourceID string) error {
return s.Repositories().ResourceRepository().CheckExists(ctx, resourceID)
} | [
"func",
"(",
"s",
"*",
"resourceServiceImpl",
")",
"CheckExists",
"(",
"ctx",
"context",
".",
"Context",
",",
"resourceID",
"string",
")",
"error",
"{",
"return",
"s",
".",
"Repositories",
"(",
")",
".",
"ResourceRepository",
"(",
")",
".",
"CheckExists",
... | // Checks if the resource with the given ID exists. Returns an `error.NotFoundError` if the resource does not exists,
// or an `error.InternalServerError` if an error occurred | [
"Checks",
"if",
"the",
"resource",
"with",
"the",
"given",
"ID",
"exists",
".",
"Returns",
"an",
"error",
".",
"NotFoundError",
"if",
"the",
"resource",
"does",
"not",
"exists",
"or",
"an",
"error",
".",
"InternalServerError",
"if",
"an",
"error",
"occurred"... | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/authorization/resource/service/resource_service.go#L110-L112 |
150,845 | fabric8-services/fabric8-auth | sentry/sentry.go | InitializeSentryClient | func InitializeSentryClient(sentryDSN string, options ...func(*client)) (func(), error) {
c, err := raven.New(sentryDSN)
if err != nil {
return nil, err
}
sentryClient = &client{
c: c,
sendErr: make(chan func()),
}
// set all options passed by user
for _, opt := range options {
opt(sentryClient)
}
// wait on errors to be sent on channel of client object
go sentryClient.loop()
return func() {
close(sentryClient.sendErr)
}, nil
} | go | func InitializeSentryClient(sentryDSN string, options ...func(*client)) (func(), error) {
c, err := raven.New(sentryDSN)
if err != nil {
return nil, err
}
sentryClient = &client{
c: c,
sendErr: make(chan func()),
}
// set all options passed by user
for _, opt := range options {
opt(sentryClient)
}
// wait on errors to be sent on channel of client object
go sentryClient.loop()
return func() {
close(sentryClient.sendErr)
}, nil
} | [
"func",
"InitializeSentryClient",
"(",
"sentryDSN",
"string",
",",
"options",
"...",
"func",
"(",
"*",
"client",
")",
")",
"(",
"func",
"(",
")",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"raven",
".",
"New",
"(",
"sentryDSN",
")",
"\n",
"if",
... | // InitializeSentryClient initializes sentry client. This function returns
// function that can be used to close the sentry client and error. | [
"InitializeSentryClient",
"initializes",
"sentry",
"client",
".",
"This",
"function",
"returns",
"function",
"that",
"can",
"be",
"used",
"to",
"close",
"the",
"sentry",
"client",
"and",
"error",
"."
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/sentry/sentry.go#L31-L50 |
150,846 | fabric8-services/fabric8-auth | controller/logout.go | Logoutv2 | func (c *LogoutController) Logoutv2(ctx *app.Logoutv2LogoutContext) error {
logoutRedirect, err := c.doLogout(ctx, ctx.Redirect, ctx.Referer)
if err != nil {
return err
}
locationPayload := &app.RedirectLocation{RedirectLocation: logoutRedirect}
ctx.ResponseData.Header().Set("Cache-Control", "no-cache")
return ctx.OK(locationPayload)
} | go | func (c *LogoutController) Logoutv2(ctx *app.Logoutv2LogoutContext) error {
logoutRedirect, err := c.doLogout(ctx, ctx.Redirect, ctx.Referer)
if err != nil {
return err
}
locationPayload := &app.RedirectLocation{RedirectLocation: logoutRedirect}
ctx.ResponseData.Header().Set("Cache-Control", "no-cache")
return ctx.OK(locationPayload)
} | [
"func",
"(",
"c",
"*",
"LogoutController",
")",
"Logoutv2",
"(",
"ctx",
"*",
"app",
".",
"Logoutv2LogoutContext",
")",
"error",
"{",
"logoutRedirect",
",",
"err",
":=",
"c",
".",
"doLogout",
"(",
"ctx",
",",
"ctx",
".",
"Redirect",
",",
"ctx",
".",
"Re... | // Logoutv2 is a secured logout endpoint that also invalidates all of the user's tokens | [
"Logoutv2",
"is",
"a",
"secured",
"logout",
"endpoint",
"that",
"also",
"invalidates",
"all",
"of",
"the",
"user",
"s",
"tokens"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/logout.go#L46-L56 |
150,847 | fabric8-services/fabric8-auth | controller/logout.go | doLogout | func (c *LogoutController) doLogout(ctx jsonapi.InternalServerError, redirect *string, referrer *string) (string, error) {
if redirect == nil {
if referrer == nil {
log.Error(ctx, nil, "Failed to logout. Referer Header and redirect param are both empty.")
return "", jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterErrorFromString("referrer", referrer,
"referer Header and redirect param are both empty (at least one should be specified)"))
}
redirect = referrer
}
log.Debug(ctx, map[string]interface{}{
"referrer": referrer,
"redirect": *redirect,
}, "Got Request to logout!")
redirectURL, err := url.Parse(*redirect)
if err != nil {
log.Error(ctx, map[string]interface{}{
"redirect_url": *redirect,
"err": err,
}, "Failed to logout. Unable to parse provided redirect url.")
return "", jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("redirect", *redirect))
}
log.Debug(ctx, map[string]interface{}{
"redirect_url": *redirectURL,
"err": err,
}, "parsed provided redirect url.")
logoutRedirect, err := c.app.LogoutService().Logout(ctx, redirectURL.String())
if err != nil {
log.Error(ctx, map[string]interface{}{
"redirect_url": redirectURL.String(),
"err": err,
}, "Failed to logout.")
return "", jsonapi.JSONErrorResponse(ctx, err)
}
return logoutRedirect, nil
} | go | func (c *LogoutController) doLogout(ctx jsonapi.InternalServerError, redirect *string, referrer *string) (string, error) {
if redirect == nil {
if referrer == nil {
log.Error(ctx, nil, "Failed to logout. Referer Header and redirect param are both empty.")
return "", jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterErrorFromString("referrer", referrer,
"referer Header and redirect param are both empty (at least one should be specified)"))
}
redirect = referrer
}
log.Debug(ctx, map[string]interface{}{
"referrer": referrer,
"redirect": *redirect,
}, "Got Request to logout!")
redirectURL, err := url.Parse(*redirect)
if err != nil {
log.Error(ctx, map[string]interface{}{
"redirect_url": *redirect,
"err": err,
}, "Failed to logout. Unable to parse provided redirect url.")
return "", jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("redirect", *redirect))
}
log.Debug(ctx, map[string]interface{}{
"redirect_url": *redirectURL,
"err": err,
}, "parsed provided redirect url.")
logoutRedirect, err := c.app.LogoutService().Logout(ctx, redirectURL.String())
if err != nil {
log.Error(ctx, map[string]interface{}{
"redirect_url": redirectURL.String(),
"err": err,
}, "Failed to logout.")
return "", jsonapi.JSONErrorResponse(ctx, err)
}
return logoutRedirect, nil
} | [
"func",
"(",
"c",
"*",
"LogoutController",
")",
"doLogout",
"(",
"ctx",
"jsonapi",
".",
"InternalServerError",
",",
"redirect",
"*",
"string",
",",
"referrer",
"*",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"redirect",
"==",
"nil",
"{",... | // doLogout performs the logout action, optionally with the user's token string in order to invalidate all the
// user's tokens. Returns the logout redirect URL | [
"doLogout",
"performs",
"the",
"logout",
"action",
"optionally",
"with",
"the",
"user",
"s",
"token",
"string",
"in",
"order",
"to",
"invalidate",
"all",
"the",
"user",
"s",
"tokens",
".",
"Returns",
"the",
"logout",
"redirect",
"URL"
] | 2a60f45fcdf7456553025afca28e81115285cce6 | https://github.com/fabric8-services/fabric8-auth/blob/2a60f45fcdf7456553025afca28e81115285cce6/controller/logout.go#L60-L98 |
150,848 | bclicn/color | color.go | Render | func Render(colorCode int, fontSize int, content string) string {
return "\033[" + strconv.Itoa(fontSize) + ";" + strconv.Itoa(colorCode) + "m" + content + reset
} | go | func Render(colorCode int, fontSize int, content string) string {
return "\033[" + strconv.Itoa(fontSize) + ";" + strconv.Itoa(colorCode) + "m" + content + reset
} | [
"func",
"Render",
"(",
"colorCode",
"int",
",",
"fontSize",
"int",
",",
"content",
"string",
")",
"string",
"{",
"return",
"\"",
"\\033",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"fontSize",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"col... | // you can use custom color code and font size by calling this function | [
"you",
"can",
"use",
"custom",
"color",
"code",
"and",
"font",
"size",
"by",
"calling",
"this",
"function"
] | 108f2023dc84f1f9e64f246fa3997993971b2706 | https://github.com/bclicn/color/blob/108f2023dc84f1f9e64f246fa3997993971b2706/color.go#L53-L55 |
150,849 | leekchan/gtf | gtf.go | Inject | func Inject(funcs map[string]interface{}) {
for k, v := range GtfFuncMap {
if _, ok := funcs[k]; !ok {
funcs[k] = v
}
}
} | go | func Inject(funcs map[string]interface{}) {
for k, v := range GtfFuncMap {
if _, ok := funcs[k]; !ok {
funcs[k] = v
}
}
} | [
"func",
"Inject",
"(",
"funcs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"GtfFuncMap",
"{",
"if",
"_",
",",
"ok",
":=",
"funcs",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"funcs",
"[",
"k",
"]... | // gtf.Inject injects gtf functions into the passed FuncMap.
// It does not overwrite the original function which have same name as a gtf function. | [
"gtf",
".",
"Inject",
"injects",
"gtf",
"functions",
"into",
"the",
"passed",
"FuncMap",
".",
"It",
"does",
"not",
"overwrite",
"the",
"original",
"function",
"which",
"have",
"same",
"name",
"as",
"a",
"gtf",
"function",
"."
] | 5fba33c5b00b4d204dbb2c1a7b27e2b999446cec | https://github.com/leekchan/gtf/blob/5fba33c5b00b4d204dbb2c1a7b27e2b999446cec/gtf.go#L457-L463 |
150,850 | leekchan/gtf | gtf.go | InjectWithPrefix | func InjectWithPrefix(funcs map[string]interface{}, prefix string) {
for k, v := range GtfFuncMap {
funcs[prefix+k] = v
}
} | go | func InjectWithPrefix(funcs map[string]interface{}, prefix string) {
for k, v := range GtfFuncMap {
funcs[prefix+k] = v
}
} | [
"func",
"InjectWithPrefix",
"(",
"funcs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"prefix",
"string",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"GtfFuncMap",
"{",
"funcs",
"[",
"prefix",
"+",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",... | // gtf.Inject injects gtf functions into the passed FuncMap.
// It prefixes the gtf functions with the specified prefix.
// If there are many function which have same names as the gtf functions,
// you can use this function to prefix the gtf functions. | [
"gtf",
".",
"Inject",
"injects",
"gtf",
"functions",
"into",
"the",
"passed",
"FuncMap",
".",
"It",
"prefixes",
"the",
"gtf",
"functions",
"with",
"the",
"specified",
"prefix",
".",
"If",
"there",
"are",
"many",
"function",
"which",
"have",
"same",
"names",
... | 5fba33c5b00b4d204dbb2c1a7b27e2b999446cec | https://github.com/leekchan/gtf/blob/5fba33c5b00b4d204dbb2c1a7b27e2b999446cec/gtf.go#L477-L481 |
150,851 | kylelemons/gousb | usbid/load.go | LoadFromURL | func LoadFromURL(url string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
ids, cls, err := ParseIDs(resp.Body)
if err != nil {
return err
}
Vendors = ids
Classes = cls
LastUpdate = time.Now()
return nil
} | go | func LoadFromURL(url string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
ids, cls, err := ParseIDs(resp.Body)
if err != nil {
return err
}
Vendors = ids
Classes = cls
LastUpdate = time.Now()
return nil
} | [
"func",
"LoadFromURL",
"(",
"url",
"string",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",... | // LoadFromURL replaces the built-in vendor and class mappings with ones loaded
// from the given URL.
//
// This should usually only be necessary if the mappings in the library are
// stale. The contents of this file as of February 2012 are embedded in the
// library itself. | [
"LoadFromURL",
"replaces",
"the",
"built",
"-",
"in",
"vendor",
"and",
"class",
"mappings",
"with",
"ones",
"loaded",
"from",
"the",
"given",
"URL",
".",
"This",
"should",
"usually",
"only",
"be",
"necessary",
"if",
"the",
"mappings",
"in",
"the",
"library",... | 99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e | https://github.com/kylelemons/gousb/blob/99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e/usbid/load.go#L46-L62 |
150,852 | kylelemons/gousb | usbid/regen/regen.go | sanitize | func sanitize(r rune) rune {
switch {
case r == '`':
return -1
case r == '\t', r == '\n':
return r
case r >= ' ' && r <= '~':
return r
}
return -1
} | go | func sanitize(r rune) rune {
switch {
case r == '`':
return -1
case r == '\t', r == '\n':
return r
case r >= ' ' && r <= '~':
return r
}
return -1
} | [
"func",
"sanitize",
"(",
"r",
"rune",
")",
"rune",
"{",
"switch",
"{",
"case",
"r",
"==",
"'`'",
":",
"return",
"-",
"1",
"\n",
"case",
"r",
"==",
"'\\t'",
",",
"r",
"==",
"'\\n'",
":",
"return",
"r",
"\n",
"case",
"r",
">=",
"' '",
"&&",
"r",
... | // sanitize strips characters that can't be `-quoted | [
"sanitize",
"strips",
"characters",
"that",
"can",
"t",
"be",
"-",
"quoted"
] | 99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e | https://github.com/kylelemons/gousb/blob/99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e/usbid/regen/regen.go#L93-L103 |
150,853 | kylelemons/gousb | usb/device.go | Close | func (d *Device) Close() error {
if d.handle == nil {
return fmt.Errorf("usb: double close on device")
}
d.lock.Lock()
defer d.lock.Unlock()
for iface := range d.claimed {
libusb.release(d.handle, iface)
}
libusb.close(d.handle)
d.handle = nil
return nil
} | go | func (d *Device) Close() error {
if d.handle == nil {
return fmt.Errorf("usb: double close on device")
}
d.lock.Lock()
defer d.lock.Unlock()
for iface := range d.claimed {
libusb.release(d.handle, iface)
}
libusb.close(d.handle)
d.handle = nil
return nil
} | [
"func",
"(",
"d",
"*",
"Device",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"d",
".",
"handle",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"d",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
... | // Close the device. | [
"Close",
"the",
"device",
"."
] | 99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e | https://github.com/kylelemons/gousb/blob/99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e/usb/device.go#L81-L93 |
150,854 | kylelemons/gousb | usb/transfer.go | wait | func (t *usbTransfer) wait() (n int, err error) {
t.mu.Lock()
defer t.mu.Unlock()
if !t.submitted {
return 0, nil
}
select {
case <-time.After(10 * time.Second):
return 0, fmt.Errorf("wait timed out after 10s")
case <-t.done:
}
t.submitted = false
n, status := libusb.data(t.xfer)
if status != LIBUSB_TRANSFER_COMPLETED {
return n, status
}
return n, err
} | go | func (t *usbTransfer) wait() (n int, err error) {
t.mu.Lock()
defer t.mu.Unlock()
if !t.submitted {
return 0, nil
}
select {
case <-time.After(10 * time.Second):
return 0, fmt.Errorf("wait timed out after 10s")
case <-t.done:
}
t.submitted = false
n, status := libusb.data(t.xfer)
if status != LIBUSB_TRANSFER_COMPLETED {
return n, status
}
return n, err
} | [
"func",
"(",
"t",
"*",
"usbTransfer",
")",
"wait",
"(",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"t",
".",
"submitte... | // wait waits for libusb to signal the release of transfer data.
// After wait returns, the transfer contents are safe to access
// via t.buf. The number returned by wait indicates how many bytes
// of the buffer were read or written by libusb, and it can be
// smaller than the length of t.buf. | [
"wait",
"waits",
"for",
"libusb",
"to",
"signal",
"the",
"release",
"of",
"transfer",
"data",
".",
"After",
"wait",
"returns",
"the",
"transfer",
"contents",
"are",
"safe",
"to",
"access",
"via",
"t",
".",
"buf",
".",
"The",
"number",
"returned",
"by",
"... | 99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e | https://github.com/kylelemons/gousb/blob/99e7ca4f01738df8a0d994f04e6cc05f8bd51c5e/usb/transfer.go#L62-L79 |
150,855 | gotschmarcel/goserv | util.go | doneProcessing | func doneProcessing(w *responseWriter, ctx *RequestContext) bool {
return w.Written() || ctx.err != nil || ctx.skip
} | go | func doneProcessing(w *responseWriter, ctx *RequestContext) bool {
return w.Written() || ctx.err != nil || ctx.skip
} | [
"func",
"doneProcessing",
"(",
"w",
"*",
"responseWriter",
",",
"ctx",
"*",
"RequestContext",
")",
"bool",
"{",
"return",
"w",
".",
"Written",
"(",
")",
"||",
"ctx",
".",
"err",
"!=",
"nil",
"||",
"ctx",
".",
"skip",
"\n",
"}"
] | // Returns true if either a response was written or a ContextError occured. | [
"Returns",
"true",
"if",
"either",
"a",
"response",
"was",
"written",
"or",
"a",
"ContextError",
"occured",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/util.go#L98-L100 |
150,856 | gotschmarcel/goserv | handlers.go | AddHeaders | func AddHeaders(headers map[string]string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
h := w.Header()
for name, value := range headers {
h.Add(name, value)
}
}
} | go | func AddHeaders(headers map[string]string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
h := w.Header()
for name, value := range headers {
h.Add(name, value)
}
}
} | [
"func",
"AddHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
":=",
"w",
".",
"Header"... | // AddHeaders returns a new HandlerFunc which adds the specified response headers. | [
"AddHeaders",
"returns",
"a",
"new",
"HandlerFunc",
"which",
"adds",
"the",
"specified",
"response",
"headers",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/handlers.go#L28-L36 |
150,857 | gotschmarcel/goserv | route.go | All | func (r *Route) All(fn http.HandlerFunc) *Route {
for _, method := range methodNames {
r.addMethodHandlerFunc(method, fn)
}
return r
} | go | func (r *Route) All(fn http.HandlerFunc) *Route {
for _, method := range methodNames {
r.addMethodHandlerFunc(method, fn)
}
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"All",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"for",
"_",
",",
"method",
":=",
"range",
"methodNames",
"{",
"r",
".",
"addMethodHandlerFunc",
"(",
"method",
",",
"fn",
")",
"\n",
"}",
"\n... | // All registers the specified functions for all methods in the order of appearance. | [
"All",
"registers",
"the",
"specified",
"functions",
"for",
"all",
"methods",
"in",
"the",
"order",
"of",
"appearance",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L21-L26 |
150,858 | gotschmarcel/goserv | route.go | Method | func (r *Route) Method(method string, fn http.HandlerFunc) *Route {
r.addMethodHandlerFunc(method, fn)
return r
} | go | func (r *Route) Method(method string, fn http.HandlerFunc) *Route {
r.addMethodHandlerFunc(method, fn)
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Method",
"(",
"method",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"r",
".",
"addMethodHandlerFunc",
"(",
"method",
",",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Method registers the functions for the specified HTTP method in the order of appearance. | [
"Method",
"registers",
"the",
"functions",
"for",
"the",
"specified",
"HTTP",
"method",
"in",
"the",
"order",
"of",
"appearance",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L29-L32 |
150,859 | gotschmarcel/goserv | route.go | Methods | func (r *Route) Methods(methods []string, fn http.HandlerFunc) *Route {
for _, method := range methods {
r.Method(method, fn)
}
return r
} | go | func (r *Route) Methods(methods []string, fn http.HandlerFunc) *Route {
for _, method := range methods {
r.Method(method, fn)
}
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Methods",
"(",
"methods",
"[",
"]",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"for",
"_",
",",
"method",
":=",
"range",
"methods",
"{",
"r",
".",
"Method",
"(",
"method",
",",
"... | // Methods is an adapter for .Method to register functions
// for multiple methods in one call. | [
"Methods",
"is",
"an",
"adapter",
"for",
".",
"Method",
"to",
"register",
"functions",
"for",
"multiple",
"methods",
"in",
"one",
"call",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L36-L41 |
150,860 | gotschmarcel/goserv | route.go | Get | func (r *Route) Get(fn http.HandlerFunc) *Route {
return r.Method(http.MethodGet, fn)
} | go | func (r *Route) Get(fn http.HandlerFunc) *Route {
return r.Method(http.MethodGet, fn)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Get",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodGet",
",",
"fn",
")",
"\n",
"}"
] | // Get is an adapter for .Method and registers the functions for the "GET" method. | [
"Get",
"is",
"an",
"adapter",
"for",
".",
"Method",
"and",
"registers",
"the",
"functions",
"for",
"the",
"GET",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L44-L46 |
150,861 | gotschmarcel/goserv | route.go | Post | func (r *Route) Post(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPost, fn)
} | go | func (r *Route) Post(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPost, fn)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Post",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPost",
",",
"fn",
")",
"\n",
"}"
] | // Post is an adapter for .Method and registers the functions for the "POST" method. | [
"Post",
"is",
"an",
"adapter",
"for",
".",
"Method",
"and",
"registers",
"the",
"functions",
"for",
"the",
"POST",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L49-L51 |
150,862 | gotschmarcel/goserv | route.go | Put | func (r *Route) Put(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPut, fn)
} | go | func (r *Route) Put(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPut, fn)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Put",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPut",
",",
"fn",
")",
"\n",
"}"
] | // Put is an adapter for .Method and registers the functions for the "PUT" method. | [
"Put",
"is",
"an",
"adapter",
"for",
".",
"Method",
"and",
"registers",
"the",
"functions",
"for",
"the",
"PUT",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L54-L56 |
150,863 | gotschmarcel/goserv | route.go | Delete | func (r *Route) Delete(fn http.HandlerFunc) *Route {
return r.Method(http.MethodDelete, fn)
} | go | func (r *Route) Delete(fn http.HandlerFunc) *Route {
return r.Method(http.MethodDelete, fn)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Delete",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodDelete",
",",
"fn",
")",
"\n",
"}"
] | // Delete is an adapter for .Method and registers the functions for the "DELETE" method. | [
"Delete",
"is",
"an",
"adapter",
"for",
".",
"Method",
"and",
"registers",
"the",
"functions",
"for",
"the",
"DELETE",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L59-L61 |
150,864 | gotschmarcel/goserv | route.go | Patch | func (r *Route) Patch(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPatch, fn)
} | go | func (r *Route) Patch(fn http.HandlerFunc) *Route {
return r.Method(http.MethodPatch, fn)
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Patch",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPatch",
",",
"fn",
")",
"\n",
"}"
] | // Patch is an adapter for .Method and registers the functions for the "PATCH" method. | [
"Patch",
"is",
"an",
"adapter",
"for",
".",
"Method",
"and",
"registers",
"the",
"functions",
"for",
"the",
"PATCH",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L64-L66 |
150,865 | gotschmarcel/goserv | route.go | Rest | func (r *Route) Rest(fn http.HandlerFunc) *Route {
for _, method := range methodNames {
if len(r.methods[method]) > 0 {
continue
}
r.addMethodHandlerFunc(method, fn)
}
return r
} | go | func (r *Route) Rest(fn http.HandlerFunc) *Route {
for _, method := range methodNames {
if len(r.methods[method]) > 0 {
continue
}
r.addMethodHandlerFunc(method, fn)
}
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Rest",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Route",
"{",
"for",
"_",
",",
"method",
":=",
"range",
"methodNames",
"{",
"if",
"len",
"(",
"r",
".",
"methods",
"[",
"method",
"]",
")",
">",
"0",
... | // Rest registers the given handler on all methods without a handler. | [
"Rest",
"registers",
"the",
"given",
"handler",
"on",
"all",
"methods",
"without",
"a",
"handler",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L69-L79 |
150,866 | gotschmarcel/goserv | route.go | serveHTTP | func (r *Route) serveHTTP(res http.ResponseWriter, req *http.Request) {
ctx := Context(req)
for _, handler := range r.methods[req.Method] {
handler(res, req)
if doneProcessing(res.(*responseWriter), ctx) {
return
}
}
} | go | func (r *Route) serveHTTP(res http.ResponseWriter, req *http.Request) {
ctx := Context(req)
for _, handler := range r.methods[req.Method] {
handler(res, req)
if doneProcessing(res.(*responseWriter), ctx) {
return
}
}
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"serveHTTP",
"(",
"res",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"ctx",
":=",
"Context",
"(",
"req",
")",
"\n\n",
"for",
"_",
",",
"handler",
":=",
"range",
"r",
".",
... | // serveHTTP processes the Request by invoking all middleware and all method handlers for the
// corresponding method of the Request in the order they were registered.
//
// The processing stops as soon as a handler writes a response or set's an error
// on the RequestContext. | [
"serveHTTP",
"processes",
"the",
"Request",
"by",
"invoking",
"all",
"middleware",
"and",
"all",
"method",
"handlers",
"for",
"the",
"corresponding",
"method",
"of",
"the",
"Request",
"in",
"the",
"order",
"they",
"were",
"registered",
".",
"The",
"processing",
... | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/route.go#L86-L96 |
150,867 | gotschmarcel/goserv | context.go | Set | func (r *RequestContext) Set(key string, value interface{}) {
r.mutex.Lock()
r.store[key] = value
r.mutex.Unlock()
} | go | func (r *RequestContext) Set(key string, value interface{}) {
r.mutex.Lock()
r.store[key] = value
r.mutex.Unlock()
} | [
"func",
"(",
"r",
"*",
"RequestContext",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"store",
"[",
"key",
"]",
"=",
"value",
"\n",
"r",
".",
"mutex",... | // Set sets the value for the specified the key. It replaces any existing values. | [
"Set",
"sets",
"the",
"value",
"for",
"the",
"specified",
"the",
"key",
".",
"It",
"replaces",
"any",
"existing",
"values",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L29-L33 |
150,868 | gotschmarcel/goserv | context.go | Get | func (r *RequestContext) Get(key string) interface{} {
r.mutex.RLock()
defer r.mutex.RUnlock()
return r.store[key]
} | go | func (r *RequestContext) Get(key string) interface{} {
r.mutex.RLock()
defer r.mutex.RUnlock()
return r.store[key]
} | [
"func",
"(",
"r",
"*",
"RequestContext",
")",
"Get",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"r",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"r",
".",
"store",
... | // Get retrieves the value for key. If the key doesn't exist in the RequestContext,
// Get returns nil. | [
"Get",
"retrieves",
"the",
"value",
"for",
"key",
".",
"If",
"the",
"key",
"doesn",
"t",
"exist",
"in",
"the",
"RequestContext",
"Get",
"returns",
"nil",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L37-L41 |
150,869 | gotschmarcel/goserv | context.go | Delete | func (r *RequestContext) Delete(key string) {
r.mutex.Lock()
delete(r.store, key)
r.mutex.Unlock()
} | go | func (r *RequestContext) Delete(key string) {
r.mutex.Lock()
delete(r.store, key)
r.mutex.Unlock()
} | [
"func",
"(",
"r",
"*",
"RequestContext",
")",
"Delete",
"(",
"key",
"string",
")",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"r",
".",
"store",
",",
"key",
")",
"\n",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
... | // Delete deletes the value associated with key. If the key doesn't exist nothing happens. | [
"Delete",
"deletes",
"the",
"value",
"associated",
"with",
"key",
".",
"If",
"the",
"key",
"doesn",
"t",
"exist",
"nothing",
"happens",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L44-L48 |
150,870 | gotschmarcel/goserv | context.go | Exists | func (r *RequestContext) Exists(key string) bool {
r.mutex.RLock()
_, exists := r.store[key]
r.mutex.RUnlock()
return exists
} | go | func (r *RequestContext) Exists(key string) bool {
r.mutex.RLock()
_, exists := r.store[key]
r.mutex.RUnlock()
return exists
} | [
"func",
"(",
"r",
"*",
"RequestContext",
")",
"Exists",
"(",
"key",
"string",
")",
"bool",
"{",
"r",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"_",
",",
"exists",
":=",
"r",
".",
"store",
"[",
"key",
"]",
"\n",
"r",
".",
"mutex",
".",
"RUnloc... | // Exists returns true if the specified key exists in the RequestContext, otherwise false is returned. | [
"Exists",
"returns",
"true",
"if",
"the",
"specified",
"key",
"exists",
"in",
"the",
"RequestContext",
"otherwise",
"false",
"is",
"returned",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L51-L56 |
150,871 | gotschmarcel/goserv | context.go | Context | func Context(r *http.Request) *RequestContext {
contextMutex.RLock()
defer contextMutex.RUnlock()
return requestContextMap[r]
} | go | func Context(r *http.Request) *RequestContext {
contextMutex.RLock()
defer contextMutex.RUnlock()
return requestContextMap[r]
} | [
"func",
"Context",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"RequestContext",
"{",
"contextMutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"contextMutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"requestContextMap",
"[",
"r",
"]",
"\n",
"}"
] | // Context returns the corresponding RequestContext for the given Request. | [
"Context",
"returns",
"the",
"corresponding",
"RequestContext",
"for",
"the",
"given",
"Request",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L102-L106 |
150,872 | gotschmarcel/goserv | context.go | createRequestContext | func createRequestContext(r *http.Request) {
contextMutex.Lock()
requestContextMap[r] = newRequestContext()
contextMutex.Unlock()
} | go | func createRequestContext(r *http.Request) {
contextMutex.Lock()
requestContextMap[r] = newRequestContext()
contextMutex.Unlock()
} | [
"func",
"createRequestContext",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"contextMutex",
".",
"Lock",
"(",
")",
"\n",
"requestContextMap",
"[",
"r",
"]",
"=",
"newRequestContext",
"(",
")",
"\n",
"contextMutex",
".",
"Unlock",
"(",
")",
"\n",
"}"... | // Stores a new RequestContext for the specified Request in the requestContextMap.
// This may overwrite an existing RequestContext! | [
"Stores",
"a",
"new",
"RequestContext",
"for",
"the",
"specified",
"Request",
"in",
"the",
"requestContextMap",
".",
"This",
"may",
"overwrite",
"an",
"existing",
"RequestContext!"
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L110-L114 |
150,873 | gotschmarcel/goserv | context.go | deleteRequestContext | func deleteRequestContext(r *http.Request) {
contextMutex.Lock()
delete(requestContextMap, r)
contextMutex.Unlock()
} | go | func deleteRequestContext(r *http.Request) {
contextMutex.Lock()
delete(requestContextMap, r)
contextMutex.Unlock()
} | [
"func",
"deleteRequestContext",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"contextMutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"requestContextMap",
",",
"r",
")",
"\n",
"contextMutex",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Removes the RequestContext for the given Request from the requestContextMap. | [
"Removes",
"the",
"RequestContext",
"for",
"the",
"given",
"Request",
"from",
"the",
"requestContextMap",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/context.go#L117-L121 |
150,874 | gotschmarcel/goserv | router.go | All | func (r *Router) All(path string, fn http.HandlerFunc) *Router {
r.Route(path).All(fn)
return r
} | go | func (r *Router) All(path string, fn http.HandlerFunc) *Router {
r.Route(path).All(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"All",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"r",
".",
"Route",
"(",
"path",
")",
".",
"All",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // All registers the specified HandlerFunc for the given path for
// all http methods. | [
"All",
"registers",
"the",
"specified",
"HandlerFunc",
"for",
"the",
"given",
"path",
"for",
"all",
"http",
"methods",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L38-L41 |
150,875 | gotschmarcel/goserv | router.go | Method | func (r *Router) Method(method, path string, fn http.HandlerFunc) *Router {
r.Route(path).Method(method, fn)
return r
} | go | func (r *Router) Method(method, path string, fn http.HandlerFunc) *Router {
r.Route(path).Method(method, fn)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Method",
"(",
"method",
",",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"r",
".",
"Route",
"(",
"path",
")",
".",
"Method",
"(",
"method",
",",
"fn",
")",
"\n",
"return... | // Method registers the specified HandlerFunc for the given path
// and method. | [
"Method",
"registers",
"the",
"specified",
"HandlerFunc",
"for",
"the",
"given",
"path",
"and",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L45-L48 |
150,876 | gotschmarcel/goserv | router.go | Methods | func (r *Router) Methods(methods []string, path string, fn http.HandlerFunc) *Router {
r.Route(path).Methods(methods, fn)
return r
} | go | func (r *Router) Methods(methods []string, path string, fn http.HandlerFunc) *Router {
r.Route(path).Methods(methods, fn)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Methods",
"(",
"methods",
"[",
"]",
"string",
",",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"r",
".",
"Route",
"(",
"path",
")",
".",
"Methods",
"(",
"methods",
",",
... | // Methods is an adapter for Method for registering a HandlerFunc on a path for multiple methods
// in a single call. | [
"Methods",
"is",
"an",
"adapter",
"for",
"Method",
"for",
"registering",
"a",
"HandlerFunc",
"on",
"a",
"path",
"for",
"multiple",
"methods",
"in",
"a",
"single",
"call",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L52-L55 |
150,877 | gotschmarcel/goserv | router.go | Get | func (r *Router) Get(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodGet, path, fn)
} | go | func (r *Router) Get(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodGet, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Get",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodGet",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Get is an adapter for Method registering a HandlerFunc for the "GET" method on path. | [
"Get",
"is",
"an",
"adapter",
"for",
"Method",
"registering",
"a",
"HandlerFunc",
"for",
"the",
"GET",
"method",
"on",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L58-L60 |
150,878 | gotschmarcel/goserv | router.go | Post | func (r *Router) Post(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPost, path, fn)
} | go | func (r *Router) Post(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPost, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Post",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPost",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Post is an adapter for Method registering a HandlerFunc for the "POST" method on path. | [
"Post",
"is",
"an",
"adapter",
"for",
"Method",
"registering",
"a",
"HandlerFunc",
"for",
"the",
"POST",
"method",
"on",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L63-L65 |
150,879 | gotschmarcel/goserv | router.go | Put | func (r *Router) Put(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPut, path, fn)
} | go | func (r *Router) Put(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPut, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Put",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPut",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Put is an adapter for Method registering a HandlerFunc for the "PUT" method on path. | [
"Put",
"is",
"an",
"adapter",
"for",
"Method",
"registering",
"a",
"HandlerFunc",
"for",
"the",
"PUT",
"method",
"on",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L68-L70 |
150,880 | gotschmarcel/goserv | router.go | Delete | func (r *Router) Delete(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodDelete, path, fn)
} | go | func (r *Router) Delete(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodDelete, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Delete",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodDelete",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Delete is an adapter for Method registering a HandlerFunc for the "DELETE" method on path. | [
"Delete",
"is",
"an",
"adapter",
"for",
"Method",
"registering",
"a",
"HandlerFunc",
"for",
"the",
"DELETE",
"method",
"on",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L73-L75 |
150,881 | gotschmarcel/goserv | router.go | Patch | func (r *Router) Patch(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPatch, path, fn)
} | go | func (r *Router) Patch(path string, fn http.HandlerFunc) *Router {
return r.Method(http.MethodPatch, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Patch",
"(",
"path",
"string",
",",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"Method",
"(",
"http",
".",
"MethodPatch",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Patch is an adapter for Method registering a HandlerFunc for the "PATCH" method on path. | [
"Patch",
"is",
"an",
"adapter",
"for",
"Method",
"registering",
"a",
"HandlerFunc",
"for",
"the",
"PATCH",
"method",
"on",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L78-L80 |
150,882 | gotschmarcel/goserv | router.go | Use | func (r *Router) Use(fn http.HandlerFunc) *Router {
r.Route("/*").All(fn)
return r
} | go | func (r *Router) Use(fn http.HandlerFunc) *Router {
r.Route("/*").All(fn)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Use",
"(",
"fn",
"http",
".",
"HandlerFunc",
")",
"*",
"Router",
"{",
"r",
".",
"Route",
"(",
"\"",
"\"",
")",
".",
"All",
"(",
"fn",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Use registers the specified function as middleware.
// Middleware is always processed before any dispatching happens. | [
"Use",
"registers",
"the",
"specified",
"function",
"as",
"middleware",
".",
"Middleware",
"is",
"always",
"processed",
"before",
"any",
"dispatching",
"happens",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L84-L87 |
150,883 | gotschmarcel/goserv | router.go | UseHandler | func (r *Router) UseHandler(handler http.Handler) *Router {
r.Route("/*").All(handler.ServeHTTP)
return r
} | go | func (r *Router) UseHandler(handler http.Handler) *Router {
r.Route("/*").All(handler.ServeHTTP)
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"UseHandler",
"(",
"handler",
"http",
".",
"Handler",
")",
"*",
"Router",
"{",
"r",
".",
"Route",
"(",
"\"",
"\"",
")",
".",
"All",
"(",
"handler",
".",
"ServeHTTP",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // UseHandler is an adapter for Use to register a Handler as middleware. | [
"UseHandler",
"is",
"an",
"adapter",
"for",
"Use",
"to",
"register",
"a",
"Handler",
"as",
"middleware",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L90-L93 |
150,884 | gotschmarcel/goserv | router.go | SubRouter | func (r *Router) SubRouter(prefix string) *Router {
router := newRouter()
router.StrictSlash = r.StrictSlash
router.path = r.path + prefix
r.addRoute(newRoute(prefix, r.StrictSlash, true).All(router.serveHTTP))
return router
} | go | func (r *Router) SubRouter(prefix string) *Router {
router := newRouter()
router.StrictSlash = r.StrictSlash
router.path = r.path + prefix
r.addRoute(newRoute(prefix, r.StrictSlash, true).All(router.serveHTTP))
return router
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"SubRouter",
"(",
"prefix",
"string",
")",
"*",
"Router",
"{",
"router",
":=",
"newRouter",
"(",
")",
"\n",
"router",
".",
"StrictSlash",
"=",
"r",
".",
"StrictSlash",
"\n",
"router",
".",
"path",
"=",
"r",
".",
... | // SubRouter returns a new sub router mounted on the specified prefix.
//
// All sub routers automatically inherit their StrictSlash behaviour,
// have the full mount path and no error handler. It is possible though
// to set a custom error handler for a sub router.
//
// Note that this function returns the new sub router instead of the
// parent router! | [
"SubRouter",
"returns",
"a",
"new",
"sub",
"router",
"mounted",
"on",
"the",
"specified",
"prefix",
".",
"All",
"sub",
"routers",
"automatically",
"inherit",
"their",
"StrictSlash",
"behaviour",
"have",
"the",
"full",
"mount",
"path",
"and",
"no",
"error",
"ha... | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L113-L121 |
150,885 | gotschmarcel/goserv | router.go | Route | func (r *Router) Route(path string) *Route {
route := newRoute(path, r.StrictSlash, false)
r.addRoute(route)
return route
} | go | func (r *Router) Route(path string) *Route {
route := newRoute(path, r.StrictSlash, false)
r.addRoute(route)
return route
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Route",
"(",
"path",
"string",
")",
"*",
"Route",
"{",
"route",
":=",
"newRoute",
"(",
"path",
",",
"r",
".",
"StrictSlash",
",",
"false",
")",
"\n",
"r",
".",
"addRoute",
"(",
"route",
")",
"\n",
"return",
... | // Route returns a new Route for the given path. | [
"Route",
"returns",
"a",
"new",
"Route",
"for",
"the",
"given",
"path",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/router.go#L124-L128 |
150,886 | gotschmarcel/goserv | server.go | Listen | func (s *Server) Listen(addr string) error {
return http.ListenAndServe(addr, s)
} | go | func (s *Server) Listen(addr string) error {
return http.ListenAndServe(addr, s)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Listen",
"(",
"addr",
"string",
")",
"error",
"{",
"return",
"http",
".",
"ListenAndServe",
"(",
"addr",
",",
"s",
")",
"\n",
"}"
] | // Listen is a convenience method that uses http.ListenAndServe. | [
"Listen",
"is",
"a",
"convenience",
"method",
"that",
"uses",
"http",
".",
"ListenAndServe",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/server.go#L39-L41 |
150,887 | gotschmarcel/goserv | server.go | ListenTLS | func (s *Server) ListenTLS(addr, certFile, keyFile string) error {
s.TLS = &TLS{certFile, keyFile}
return http.ListenAndServeTLS(addr, certFile, keyFile, s)
} | go | func (s *Server) ListenTLS(addr, certFile, keyFile string) error {
s.TLS = &TLS{certFile, keyFile}
return http.ListenAndServeTLS(addr, certFile, keyFile, s)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"ListenTLS",
"(",
"addr",
",",
"certFile",
",",
"keyFile",
"string",
")",
"error",
"{",
"s",
".",
"TLS",
"=",
"&",
"TLS",
"{",
"certFile",
",",
"keyFile",
"}",
"\n",
"return",
"http",
".",
"ListenAndServeTLS",
"(... | // ListenTLS is a convenience method that uses http.ListenAndServeTLS.
// The TLS informations used are stored in .TLS after calling this method. | [
"ListenTLS",
"is",
"a",
"convenience",
"method",
"that",
"uses",
"http",
".",
"ListenAndServeTLS",
".",
"The",
"TLS",
"informations",
"used",
"are",
"stored",
"in",
".",
"TLS",
"after",
"calling",
"this",
"method",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/server.go#L45-L48 |
150,888 | gotschmarcel/goserv | server.go | ServeHTTP | func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
iw := newResponseWriter(w)
createRequestContext(r)
defer deleteRequestContext(r)
s.serveHTTP(iw, r)
} | go | func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
iw := newResponseWriter(w)
createRequestContext(r)
defer deleteRequestContext(r)
s.serveHTTP(iw, r)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"iw",
":=",
"newResponseWriter",
"(",
"w",
")",
"\n\n",
"createRequestContext",
"(",
"r",
")",
"\n",
"defer",
... | // ServeHTTP dispatches the request to the internal Router. | [
"ServeHTTP",
"dispatches",
"the",
"request",
"to",
"the",
"internal",
"Router",
"."
] | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/server.go#L51-L58 |
150,889 | gotschmarcel/goserv | server.go | NewServer | func NewServer() *Server {
s := &Server{
Router: newRouter(),
Addr: "",
TLS: nil,
}
s.ErrorHandler = StdErrorHandler
return s
} | go | func NewServer() *Server {
s := &Server{
Router: newRouter(),
Addr: "",
TLS: nil,
}
s.ErrorHandler = StdErrorHandler
return s
} | [
"func",
"NewServer",
"(",
")",
"*",
"Server",
"{",
"s",
":=",
"&",
"Server",
"{",
"Router",
":",
"newRouter",
"(",
")",
",",
"Addr",
":",
"\"",
"\"",
",",
"TLS",
":",
"nil",
",",
"}",
"\n\n",
"s",
".",
"ErrorHandler",
"=",
"StdErrorHandler",
"\n\n"... | // NewServer returns a newly allocated and initialized Server instance.
//
// By default the Server has no template engine, the template root is "" and
// panic recovery is disabled. The Router's ErrorHandler is set to the StdErrorHandler. | [
"NewServer",
"returns",
"a",
"newly",
"allocated",
"and",
"initialized",
"Server",
"instance",
".",
"By",
"default",
"the",
"Server",
"has",
"no",
"template",
"engine",
"the",
"template",
"root",
"is",
"and",
"panic",
"recovery",
"is",
"disabled",
".",
"The",
... | 6fa3f02cd032b488820ace23f86020f5b44b14c7 | https://github.com/gotschmarcel/goserv/blob/6fa3f02cd032b488820ace23f86020f5b44b14c7/server.go#L64-L74 |
150,890 | wildducktheories/go-csv | record.go | Get | func (r *record) Get(key string) string {
x, ok := r.index[key]
if ok && x < len(r.fields) {
return r.fields[x]
}
return ""
} | go | func (r *record) Get(key string) string {
x, ok := r.index[key]
if ok && x < len(r.fields) {
return r.fields[x]
}
return ""
} | [
"func",
"(",
"r",
"*",
"record",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"x",
",",
"ok",
":=",
"r",
".",
"index",
"[",
"key",
"]",
"\n",
"if",
"ok",
"&&",
"x",
"<",
"len",
"(",
"r",
".",
"fields",
")",
"{",
"return",
"r",
".",... | // Answer the value of the field indexed by the column containing the specified header value. | [
"Answer",
"the",
"value",
"of",
"the",
"field",
"indexed",
"by",
"the",
"column",
"containing",
"the",
"specified",
"header",
"value",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/record.go#L64-L70 |
150,891 | wildducktheories/go-csv | record.go | Put | func (r *record) Put(key string, value string) {
x, ok := r.index[key]
if ok && x < cap(r.fields) {
if x > len(r.fields) {
r.fields = r.fields[0:x]
}
if r.cache != nil {
r.cache[key] = value
}
r.fields[x] = value
}
} | go | func (r *record) Put(key string, value string) {
x, ok := r.index[key]
if ok && x < cap(r.fields) {
if x > len(r.fields) {
r.fields = r.fields[0:x]
}
if r.cache != nil {
r.cache[key] = value
}
r.fields[x] = value
}
} | [
"func",
"(",
"r",
"*",
"record",
")",
"Put",
"(",
"key",
"string",
",",
"value",
"string",
")",
"{",
"x",
",",
"ok",
":=",
"r",
".",
"index",
"[",
"key",
"]",
"\n",
"if",
"ok",
"&&",
"x",
"<",
"cap",
"(",
"r",
".",
"fields",
")",
"{",
"if",... | // Puts the specified value into the record at the index determined by the key value. | [
"Puts",
"the",
"specified",
"value",
"into",
"the",
"record",
"at",
"the",
"index",
"determined",
"by",
"the",
"key",
"value",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/record.go#L73-L84 |
150,892 | wildducktheories/go-csv | record.go | AsMap | func (r *record) AsMap() map[string]string {
if r.cache != nil {
return r.cache
}
result := make(map[string]string)
for i, h := range r.header {
if i < len(r.fields) {
result[h] = r.fields[i]
} else {
result[h] = ""
}
}
r.cache = result
return result
} | go | func (r *record) AsMap() map[string]string {
if r.cache != nil {
return r.cache
}
result := make(map[string]string)
for i, h := range r.header {
if i < len(r.fields) {
result[h] = r.fields[i]
} else {
result[h] = ""
}
}
r.cache = result
return result
} | [
"func",
"(",
"r",
"*",
"record",
")",
"AsMap",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"r",
".",
"cache",
"!=",
"nil",
"{",
"return",
"r",
".",
"cache",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]"... | // Return a map containing a copy of the contents of the record. | [
"Return",
"a",
"map",
"containing",
"a",
"copy",
"of",
"the",
"contents",
"of",
"the",
"record",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/record.go#L87-L102 |
150,893 | wildducktheories/go-csv | record.go | PutAll | func (r *record) PutAll(o Record) {
if r.SameHeader(o) {
copy(r.fields, o.AsSlice())
r.cache = nil
} else {
for i, k := range r.header {
v := o.Get(k)
r.fields[i] = v
if r.cache != nil {
r.cache[k] = v
}
}
}
} | go | func (r *record) PutAll(o Record) {
if r.SameHeader(o) {
copy(r.fields, o.AsSlice())
r.cache = nil
} else {
for i, k := range r.header {
v := o.Get(k)
r.fields[i] = v
if r.cache != nil {
r.cache[k] = v
}
}
}
} | [
"func",
"(",
"r",
"*",
"record",
")",
"PutAll",
"(",
"o",
"Record",
")",
"{",
"if",
"r",
".",
"SameHeader",
"(",
"o",
")",
"{",
"copy",
"(",
"r",
".",
"fields",
",",
"o",
".",
"AsSlice",
"(",
")",
")",
"\n",
"r",
".",
"cache",
"=",
"nil",
"... | // Puts all the specified value into the record. | [
"Puts",
"all",
"the",
"specified",
"value",
"into",
"the",
"record",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/record.go#L110-L123 |
150,894 | wildducktheories/go-csv | record.go | SameHeader | func (r *record) SameHeader(o Record) bool {
h := o.Header()
if len(r.header) != len(h) {
return false
} else if len(h) == 0 || &h[0] == &r.header[0] {
// two slices with the same address and length have the same contents
return true
} else {
for i, k := range r.header {
if h[i] != k {
return false
}
}
return true
}
} | go | func (r *record) SameHeader(o Record) bool {
h := o.Header()
if len(r.header) != len(h) {
return false
} else if len(h) == 0 || &h[0] == &r.header[0] {
// two slices with the same address and length have the same contents
return true
} else {
for i, k := range r.header {
if h[i] != k {
return false
}
}
return true
}
} | [
"func",
"(",
"r",
"*",
"record",
")",
"SameHeader",
"(",
"o",
"Record",
")",
"bool",
"{",
"h",
":=",
"o",
".",
"Header",
"(",
")",
"\n",
"if",
"len",
"(",
"r",
".",
"header",
")",
"!=",
"len",
"(",
"h",
")",
"{",
"return",
"false",
"\n",
"}",... | // Efficiently check that the receiver and specified records have the same header | [
"Efficiently",
"check",
"that",
"the",
"receiver",
"and",
"specified",
"records",
"have",
"the",
"same",
"header"
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/record.go#L126-L141 |
150,895 | wildducktheories/go-csv | utils/utils.go | NewIndex | func NewIndex(a []string) Index {
index := make(map[string]int)
for i, v := range a {
index[v] = i
}
return index
} | go | func NewIndex(a []string) Index {
index := make(map[string]int)
for i, v := range a {
index[v] = i
}
return index
} | [
"func",
"NewIndex",
"(",
"a",
"[",
"]",
"string",
")",
"Index",
"{",
"index",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"a",
"{",
"index",
"[",
"v",
"]",
"=",
"i",
"\n",
"}",
"\n",
... | // Return a map that maps each string in the input slice to its index in the slice. | [
"Return",
"a",
"map",
"that",
"maps",
"each",
"string",
"in",
"the",
"input",
"slice",
"to",
"its",
"index",
"in",
"the",
"slice",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/utils/utils.go#L7-L13 |
150,896 | wildducktheories/go-csv | utils/utils.go | Contains | func (i Index) Contains(k string) bool {
_, ok := i[k]
return ok
} | go | func (i Index) Contains(k string) bool {
_, ok := i[k]
return ok
} | [
"func",
"(",
"i",
"Index",
")",
"Contains",
"(",
"k",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"i",
"[",
"k",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // Answer true if the index contains the specified string. | [
"Answer",
"true",
"if",
"the",
"index",
"contains",
"the",
"specified",
"string",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/utils/utils.go#L16-L19 |
150,897 | wildducktheories/go-csv | utils/utils.go | Intersect | func Intersect(a []string, b []string) ([]string, []string, []string) {
index := NewIndex(a)
result := make([]string, 0, len(b))
aNotB := make([]string, len(a), len(a))
copy(aNotB, a)
bNotA := make([]string, 0, len(b))
for _, v := range b {
if i, ok := index[v]; ok {
result = append(result, v)
aNotB[i] = ""
} else {
bNotA = append(bNotA, v)
}
}
i := 0
for j := range a {
present := (aNotB[j] == a[j])
aNotB[i] = a[j]
if present {
i++
}
}
aNotB = aNotB[0:i]
return result, aNotB, bNotA
} | go | func Intersect(a []string, b []string) ([]string, []string, []string) {
index := NewIndex(a)
result := make([]string, 0, len(b))
aNotB := make([]string, len(a), len(a))
copy(aNotB, a)
bNotA := make([]string, 0, len(b))
for _, v := range b {
if i, ok := index[v]; ok {
result = append(result, v)
aNotB[i] = ""
} else {
bNotA = append(bNotA, v)
}
}
i := 0
for j := range a {
present := (aNotB[j] == a[j])
aNotB[i] = a[j]
if present {
i++
}
}
aNotB = aNotB[0:i]
return result, aNotB, bNotA
} | [
"func",
"Intersect",
"(",
"a",
"[",
"]",
"string",
",",
"b",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"string",
",",
"[",
"]",
"string",
")",
"{",
"index",
":=",
"NewIndex",
"(",
"a",
")",
"\n",
"result",
":=",
"make",
... | // Calculate the intersection between two string slices. The first returned slice
// is the intersection between the two slices. The second returned slice is
// a slice of elements in the first slice but not the second. The third returned
// slice is a slice of elements in the second slice but not the first. | [
"Calculate",
"the",
"intersection",
"between",
"two",
"string",
"slices",
".",
"The",
"first",
"returned",
"slice",
"is",
"the",
"intersection",
"between",
"the",
"two",
"slices",
".",
"The",
"second",
"returned",
"slice",
"is",
"a",
"slice",
"of",
"elements",... | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/utils/utils.go#L25-L49 |
150,898 | wildducktheories/go-csv | writer.go | WithCsvWriter | func WithCsvWriter(w *encoding.Writer, c io.Closer) WriterBuilder {
return func(header []string) Writer {
result := &writer{
header: header,
builder: NewRecordBuilder(header),
encoder: w,
closer: c,
}
result.err = result.encoder.Write(header)
return result
}
} | go | func WithCsvWriter(w *encoding.Writer, c io.Closer) WriterBuilder {
return func(header []string) Writer {
result := &writer{
header: header,
builder: NewRecordBuilder(header),
encoder: w,
closer: c,
}
result.err = result.encoder.Write(header)
return result
}
} | [
"func",
"WithCsvWriter",
"(",
"w",
"*",
"encoding",
".",
"Writer",
",",
"c",
"io",
".",
"Closer",
")",
"WriterBuilder",
"{",
"return",
"func",
"(",
"header",
"[",
"]",
"string",
")",
"Writer",
"{",
"result",
":=",
"&",
"writer",
"{",
"header",
":",
"... | // Answer a Writer for the CSV stream constrained by specified header, using the specified encoding writer | [
"Answer",
"a",
"Writer",
"for",
"the",
"CSV",
"stream",
"constrained",
"by",
"specified",
"header",
"using",
"the",
"specified",
"encoding",
"writer"
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/writer.go#L31-L42 |
150,899 | wildducktheories/go-csv | writer.go | WithIoWriter | func WithIoWriter(w io.WriteCloser) WriterBuilder {
return WithCsvWriter(encoding.NewWriter(w), w)
} | go | func WithIoWriter(w io.WriteCloser) WriterBuilder {
return WithCsvWriter(encoding.NewWriter(w), w)
} | [
"func",
"WithIoWriter",
"(",
"w",
"io",
".",
"WriteCloser",
")",
"WriterBuilder",
"{",
"return",
"WithCsvWriter",
"(",
"encoding",
".",
"NewWriter",
"(",
"w",
")",
",",
"w",
")",
"\n",
"}"
] | // Answer a Writer for the CSV stream constrained by the specified header, using the specified io writer. | [
"Answer",
"a",
"Writer",
"for",
"the",
"CSV",
"stream",
"constrained",
"by",
"the",
"specified",
"header",
"using",
"the",
"specified",
"io",
"writer",
"."
] | a843eda7bf0911b9acdfd11a9a41ed87282dcbdd | https://github.com/wildducktheories/go-csv/blob/a843eda7bf0911b9acdfd11a9a41ed87282dcbdd/writer.go#L45-L47 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.