Пример #1
0
// SaveApplication will create a application if the ID field is not initialized
// if ID field is initialized, it will update the conresponding application.
func (r *Registry) SaveApplication(app *models.Application, reply *models.Application) error {
	db, err := getDB()
	if err != nil {
		return err
	}

	err = db.Save(app).Error
	if err != nil {
		return err
	}

	key, err := r.keygen.GenRandomKey(int64(app.ID))
	if err != nil {
		return err
	}

	app.AppKey = key

	err = db.Save(app).Error
	if err != nil {
		return err
	}

	reply.ID = app.ID
	reply.AppName = app.AppName
	reply.AppDescription = app.AppDescription
	reply.AppKey = app.AppKey
	reply.ReportUrl = app.ReportUrl
	reply.AppToken = app.AppToken
	reply.AppDomain = app.AppDomain
	reply.CreatedAt = app.CreatedAt
	reply.UpdatedAt = app.UpdatedAt

	return nil
}
Пример #2
0
// SaveApplication will create a application if the ID field is not initialized
// if ID field is initialized, it will update the conresponding application.
func (r *Registry) SaveApplication(app *models.Application, reply *models.Application) error {
	db, err := getDB()
	if err != nil {
		return err
	}

	if app.ID == 0 {
		err = db.Save(app).Error
		if err != nil {
			return err
		}

		key, err := r.keygen.GenRandomKey(int64(app.ID))
		if err != nil {
			return err
		}

		app.AppKey = key
	}

	err = db.Save(app).Error
	if err != nil {
		return err
	}

	cache := getCache()
	cacheKey := fmt.Sprintf("Application:%v", app.ID)
	if _, ok := cache.Get(cacheKey); ok {
		cache.Delete(cacheKey)
	}

	setApplication(reply, app)

	return nil
}
Пример #3
0
func setApplication(target *models.Application, src *models.Application) {
	target.ID = src.ID
	target.AppName = src.AppName
	target.AppDescription = src.AppDescription
	target.AppKey = src.AppKey
	target.ReportUrl = src.ReportUrl
	target.AppToken = src.AppToken
	target.AppDomain = src.AppDomain
	target.CreatedAt = src.CreatedAt
	target.UpdatedAt = src.UpdatedAt
}