本文整理汇总了Golang中github.com/almighty/almighty-core/log.Info函数的典型用法代码示例。如果您正苦于以下问题:Golang Info函数的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Save
// Save updates the given tracker in storage.
// returns NotFoundError, ConversionError or InternalError
func (r *GormTrackerRepository) Save(ctx context.Context, t app.Tracker) (*app.Tracker, error) {
res := Tracker{}
id, err := strconv.ParseUint(t.ID, 10, 64)
if err != nil || id == 0 {
return nil, NotFoundError{entity: "tracker", ID: t.ID}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"trackerID": id,
}, "Looking for a tracker repository with id ", id)
tx := r.db.First(&res, id)
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"trackerID": id,
}, "tracker repository not found")
return nil, NotFoundError{entity: "tracker", ID: t.ID}
}
_, present := RemoteWorkItemImplRegistry[t.Type]
// Ensure we support this remote tracker.
if present != true {
return nil, BadParameterError{parameter: "type", value: t.Type}
}
newT := Tracker{
ID: id,
URL: t.URL,
Type: t.Type}
if err := tx.Save(&newT).Error; err != nil {
log.Error(ctx, map[string]interface{}{
"trackerID": newT.ID,
"err": err,
}, "unable to save tracker repository")
return nil, InternalError{simpleError{err.Error()}}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"tracker": newT.ID,
}, "Tracker repository successfully updated")
t2 := app.Tracker{
ID: strconv.FormatUint(id, 10),
URL: t.URL,
Type: t.Type}
return &t2, nil
}
示例2: migrateToNextVersion
// migrateToNextVersion migrates the database to the nextVersion.
// If the database is already at nextVersion or higher, the nextVersion
// will be set to the actual next version.
func migrateToNextVersion(tx *sql.Tx, nextVersion *int64, m migrations) error {
// Obtain exclusive transaction level advisory that doesn't depend on any table.
// Once obtained, the lock is held for the remainder of the current transaction.
// (There is no UNLOCK TABLE command; locks are always released at transaction end.)
if _, err := tx.Exec("SELECT pg_advisory_xact_lock($1)", AdvisoryLockID); err != nil {
return errs.Errorf("Failed to acquire lock: %s\n", err)
}
// Determine current version and adjust the outmost loop
// iterator variable "version"
currentVersion, err := getCurrentVersion(tx)
if err != nil {
return errs.WithStack(err)
}
*nextVersion = currentVersion + 1
if *nextVersion >= int64(len(m)) {
// No further updates to apply (this is NOT an error)
log.Info(nil, map[string]interface{}{
"pkg": "migration",
"nextVersion": *nextVersion,
"currentVersion": currentVersion,
}, "Current version %d. Nothing to update.", currentVersion)
return nil
}
log.Info(nil, map[string]interface{}{
"pkg": "migration",
"nextVersion": *nextVersion,
"currentVersion": currentVersion,
}, "Attempt to update DB to version ", *nextVersion)
// Apply all the updates of the next version
for j := range m[*nextVersion] {
if err := m[*nextVersion][j](tx); err != nil {
return errs.Errorf("Failed to execute migration of step %d of version %d: %s\n", j, *nextVersion, err)
}
}
if _, err := tx.Exec("INSERT INTO version(version) VALUES($1)", *nextVersion); err != nil {
return errs.Errorf("Failed to update DB to version %d: %s\n", *nextVersion, err)
}
log.Info(nil, map[string]interface{}{
"pkg": "migration",
"nextVersion": *nextVersion,
"currentVersion": currentVersion,
}, "Successfully updated DB to version ", *nextVersion)
return nil
}
示例3: Delete
// Delete deletes the work item link with the given id
// returns NotFoundError or InternalError
func (r *GormWorkItemLinkRepository) Delete(ctx context.Context, ID string) error {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return errors.NewNotFoundError("work item link", ID)
}
var link = WorkItemLink{
ID: id,
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wilID": ID,
}, "Deleting the work item link repository")
db := r.db.Delete(&link)
if db.Error != nil {
log.Error(ctx, map[string]interface{}{
"wilID": ID,
"err": db.Error,
}, "unable to delete work item link repository")
return errors.NewInternalError(db.Error.Error())
}
if db.RowsAffected == 0 {
return errors.NewNotFoundError("work item link", id.String())
}
return nil
}
示例4: LoadTypeFromDB
// LoadTypeFromDB return work item type for the given id
func (r *GormWorkItemTypeRepository) LoadTypeFromDB(ctx context.Context, name string) (*WorkItemType, error) {
log.Logger().Infoln("Loading work item type", name)
res, ok := cache.Get(name)
if !ok {
log.Info(ctx, map[string]interface{}{
"pkg": "workitem",
"type": name,
}, "Work item type doesn't exist in the cache. Loading from DB...")
res = WorkItemType{}
db := r.db.Model(&res).Where("name=?", name).First(&res)
if db.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"witName": name,
}, "work item type repository not found")
return nil, errors.NewNotFoundError("work item type", name)
}
if err := db.Error; err != nil {
return nil, errors.NewInternalError(err.Error())
}
cache.Put(res)
}
return &res, nil
}
示例5: List
// List returns tracker selected by the given criteria.Expression, starting with start (zero-based) and returning at most limit items
func (r *GormTrackerRepository) List(ctx context.Context, criteria criteria.Expression, start *int, limit *int) ([]*app.Tracker, error) {
where, parameters, err := workitem.Compile(criteria)
if err != nil {
return nil, BadParameterError{"expression", criteria}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"query": where,
}, "Executing tracker repository query...")
var rows []Tracker
db := r.db.Where(where, parameters...)
if start != nil {
db = db.Offset(*start)
}
if limit != nil {
db = db.Limit(*limit)
}
if err := db.Find(&rows).Error; err != nil {
return nil, errors.WithStack(err)
}
result := make([]*app.Tracker, len(rows))
for i, tracker := range rows {
t := app.Tracker{
ID: strconv.FormatUint(tracker.ID, 10),
URL: tracker.URL,
Type: tracker.Type}
result[i] = &t
}
return result, nil
}
示例6: Load
// Load returns the tracker configuration for the given id
// returns NotFoundError, ConversionError or InternalError
func (r *GormTrackerRepository) Load(ctx context.Context, ID string) (*app.Tracker, error) {
id, err := strconv.ParseUint(ID, 10, 64)
if err != nil || id == 0 {
// treating this as a not found error: the fact that we're using number internal is implementation detail
return nil, NotFoundError{"tracker", ID}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"trackerID": id,
}, "Loading tracker repository...")
res := Tracker{}
tx := r.db.First(&res, id)
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"trackerID": ID,
}, "tracker repository not found")
return nil, NotFoundError{"tracker", ID}
}
if tx.Error != nil {
return nil, InternalError{simpleError{fmt.Sprintf("error while loading: %s", tx.Error.Error())}}
}
t := app.Tracker{
ID: strconv.FormatUint(res.ID, 10),
URL: res.URL,
Type: res.Type}
return &t, nil
}
示例7: Create
// Create creates a new tracker configuration in the repository
// returns BadParameterError, ConversionError or InternalError
func (r *GormTrackerRepository) Create(ctx context.Context, url string, typeID string) (*app.Tracker, error) {
//URL Validation
isValid := govalidator.IsURL(url)
if isValid != true {
return nil, BadParameterError{parameter: "url", value: url}
}
_, present := RemoteWorkItemImplRegistry[typeID]
// Ensure we support this remote tracker.
if present != true {
return nil, BadParameterError{parameter: "type", value: typeID}
}
t := Tracker{
URL: url,
Type: typeID}
tx := r.db
if err := tx.Create(&t).Error; err != nil {
return nil, InternalError{simpleError{err.Error()}}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"tracker": t,
}, "Tracker reposity created")
t2 := app.Tracker{
ID: strconv.FormatUint(t.ID, 10),
URL: url,
Type: typeID}
return &t2, nil
}
示例8: Save
// Save updates the given space in the db. Version must be the same as the one in the stored version
// returns NotFoundError, BadParameterError, VersionConflictError or InternalError
func (r *GormRepository) Save(ctx context.Context, p *Space) (*Space, error) {
pr := Space{}
tx := r.db.Where("id=?", p.ID).First(&pr)
oldVersion := p.Version
p.Version++
if tx.RecordNotFound() {
// treating this as a not found error: the fact that we're using number internal is implementation detail
return nil, errors.NewNotFoundError("space", p.ID.String())
}
if err := tx.Error; err != nil {
return nil, errors.NewInternalError(err.Error())
}
tx = tx.Where("Version = ?", oldVersion).Save(p)
if err := tx.Error; err != nil {
if gormsupport.IsCheckViolation(tx.Error, "spaces_name_check") {
return nil, errors.NewBadParameterError("Name", p.Name).Expected("not empty")
}
if gormsupport.IsUniqueViolation(tx.Error, "spaces_name_idx") {
return nil, errors.NewBadParameterError("Name", p.Name).Expected("unique")
}
return nil, errors.NewInternalError(err.Error())
}
if tx.RowsAffected == 0 {
return nil, errors.NewVersionConflictError("version conflict")
}
log.Info(ctx, map[string]interface{}{
"pkg": "space",
"spaceID": p.ID,
}, "space updated successfully")
return p, nil
}
示例9: Load
// Load returns the tracker query for the given id
// returns NotFoundError, ConversionError or InternalError
func (r *GormTrackerQueryRepository) Load(ctx context.Context, ID string) (*app.TrackerQuery, error) {
id, err := strconv.ParseUint(ID, 10, 64)
if err != nil || id == 0 {
// treating this as a not found error: the fact that we're using number internal is implementation detail
return nil, NotFoundError{"tracker query", ID}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"trackerQueryid": id,
}, "Loading the tracker query")
res := TrackerQuery{}
if r.db.First(&res, id).RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"trackerID": id,
}, "tracker resource not found")
return nil, NotFoundError{"tracker query", ID}
}
tq := app.TrackerQuery{
ID: strconv.FormatUint(res.ID, 10),
Query: res.Query,
Schedule: res.Schedule,
TrackerID: strconv.FormatUint(res.TrackerID, 10)}
return &tq, nil
}
示例10: Delete
// Delete implements application.WorkItemRepository
func (r *UndoableWorkItemRepository) Delete(ctx context.Context, ID string) error {
id, err := strconv.ParseUint(ID, 10, 64)
if err != nil {
// treating this as a not found error: the fact that we're using number internal is implementation detail
return errors.NewNotFoundError("work item", ID)
}
log.Info(ctx, map[string]interface{}{
"pkg": "workitem",
"id": id,
}, "Loading work iteme")
old := WorkItem{}
db := r.wrapped.db.First(&old, id)
if db.Error != nil {
return errors.NewInternalError(fmt.Sprintf("could not load %s, %s", ID, db.Error.Error()))
}
err = r.wrapped.Delete(ctx, ID)
if err == nil {
r.undo.Append(func(db *gorm.DB) error {
old.DeletedAt = nil
db = db.Save(&old)
return db.Error
})
}
return errs.WithStack(err)
}
示例11: Load
// Load returns the work item link type for the given ID.
// Returns NotFoundError, ConversionError or InternalError
func (r *GormWorkItemLinkTypeRepository) Load(ctx context.Context, ID string) (*app.WorkItemLinkTypeSingle, error) {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return nil, errors.NewNotFoundError("work item link type", ID)
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wiltID": ID,
}, "Loading work item link type")
res := WorkItemLinkType{}
db := r.db.Model(&res).Where("id=?", ID).First(&res)
if db.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"wiltID": ID,
}, "work item link type not found")
return nil, errors.NewNotFoundError("work item link type", id.String())
}
if db.Error != nil {
return nil, errors.NewInternalError(db.Error.Error())
}
// Convert the created link type entry into a JSONAPI response
result := ConvertLinkTypeFromModel(res)
return &result, nil
}
示例12: Delete
// Delete deletes the work item link category with the given id
// returns NotFoundError or InternalError
func (r *GormWorkItemLinkCategoryRepository) Delete(ctx context.Context, ID string) error {
id, err := satoriuuid.FromString(ID)
if err != nil {
// treat as not found: clients don't know it must be a UUID
return errors.NewNotFoundError("work item link category", ID)
}
var cat = WorkItemLinkCategory{
ID: id,
}
log.Info(ctx, map[string]interface{}{
"pkg": "link",
"wilcID": ID,
}, "Work item link category to delete")
db := r.db.Delete(&cat)
if db.Error != nil {
return errors.NewInternalError(db.Error.Error())
}
if db.RowsAffected == 0 {
return errors.NewNotFoundError("work item link category", id.String())
}
return nil
}
示例13: createOrUpdateType
func createOrUpdateType(typeName string, extendedTypeName *string, fields map[string]app.FieldDefinition, ctx context.Context, witr *workitem.GormWorkItemTypeRepository, db *gorm.DB) error {
wit, err := witr.LoadTypeFromDB(ctx, typeName)
cause := errs.Cause(err)
switch cause.(type) {
case errors.NotFoundError:
_, err := witr.Create(ctx, extendedTypeName, typeName, fields)
if err != nil {
return errs.WithStack(err)
}
case nil:
log.Info(ctx, map[string]interface{}{
"pkg": "migration",
"typeName": typeName,
}, "Work item type %s exists, will update/overwrite the fields only and parentPath", typeName)
path := typeName
convertedFields, err := workitem.TEMPConvertFieldTypesToModel(fields)
if extendedTypeName != nil {
log.Info(ctx, map[string]interface{}{
"pkg": "migration",
"typeName": typeName,
"extendedTypeName": *extendedTypeName,
}, "Work item type %s extends another type %v will copy fields from the extended type", typeName, *extendedTypeName)
extendedWit, err := witr.LoadTypeFromDB(ctx, *extendedTypeName)
if err != nil {
return errs.WithStack(err)
}
path = extendedWit.Path + workitem.GetTypePathSeparator() + path
//load fields from the extended type
err = loadFields(ctx, extendedWit, convertedFields)
if err != nil {
return errs.WithStack(err)
}
}
if err != nil {
return errs.WithStack(err)
}
wit.Fields = convertedFields
wit.Path = path
db = db.Save(wit)
return db.Error
}
return nil
}
示例14: Migrate
// 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.
func Migrate(db *sql.DB) error {
var err error
if db == nil {
return errs.Errorf("Database handle is nil\n")
}
m := getMigrations()
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)
if err != nil {
oldErr := err
log.Info(nil, map[string]interface{}{
"pkg": "migration",
"nextVersion": nextVersion,
"migrations": m,
"err": err,
}, "Rolling back transaction due to: ", err)
if err = tx.Rollback(); err != nil {
log.Error(nil, map[string]interface{}{
"nextVersion": nextVersion,
"migrations": m,
"err": err,
}, "error while rolling back transaction: ", err)
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: ", 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: ", err)
return errs.Errorf("Migration failed with error: %s\n", err)
}
return nil
}
示例15: Create
// Create creates a new tracker query in the repository
// returns BadParameterError, ConversionError or InternalError
func (r *GormTrackerQueryRepository) Create(ctx context.Context, query string, schedule string, tracker string) (*app.TrackerQuery, error) {
tid, err := strconv.ParseUint(tracker, 10, 64)
if err != nil || tid == 0 {
// treating this as a not found error: the fact that we're using number internal is implementation detail
return nil, NotFoundError{"tracker", tracker}
}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"trackerID": tid,
}, "Tracker ID to be created")
tq := TrackerQuery{
Query: query,
Schedule: schedule,
TrackerID: tid}
tx := r.db
if err := tx.Create(&tq).Error; err != nil {
log.Error(ctx, map[string]interface{}{
"trackerID": tid,
"trackerQuery": query,
}, "unable to create the tracker query")
return nil, InternalError{simpleError{err.Error()}}
}
tq2 := app.TrackerQuery{
ID: strconv.FormatUint(tq.ID, 10),
Query: query,
Schedule: schedule,
TrackerID: tracker}
log.Info(ctx, map[string]interface{}{
"pkg": "remoteworkitem",
"trackerID": tid,
"trackerQuery": tq,
}, "Created tracker query")
return &tq2, nil
}