當前位置: 首頁>>代碼示例>>Golang>>正文


Golang model.CleanParams函數代碼示例

本文整理匯總了Golang中github.com/fragmenta/model.CleanParams函數的典型用法代碼示例。如果您正苦於以下問題:Golang CleanParams函數的具體用法?Golang CleanParams怎麽用?Golang CleanParams使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CleanParams函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Create

// Create inserts a new record in the database using params, and returns the newly created id
func Create(params map[string]string) (int64, error) {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	// Check params for invalid values
	err := validateParams(params)
	if err != nil {
		return 0, err
	}

	// Check name is unique - no duplicate names allowed
	count, err := Query().Where("name=?", params["name"]).Count()
	if err != nil {
		return 0, err
	}

	if count > 0 {
		return 0, router.InternalError(err, "User name taken", "A username with this email already exists, sorry.")
	}

	// Update date params
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Insert(params)
}
開發者ID:intfrr,項目名稱:sendto,代碼行數:28,代碼來源:users.go

示例2: Create

// Create inserts a new record in the database using params, and returns the newly created id
func Create(params map[string]string, fh *multipart.FileHeader) (int64, error) {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParamsCreate())

	// Check params for invalid values
	err := validateParams(params)
	if err != nil {
		return 0, err
	}

	// Update date params
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	// Create the file
	id, err := Query().Insert(params)

	if fh != nil && id != 0 {

		// Now retrieve and save the file representation
		f, err := Find(id)
		if err != nil {
			return id, err
		}

		// Save files to disk using the passed in file data (if any).
		err = f.saveFile(fh)
		if err != nil {
			return id, err
		}
	}

	return id, err
}
開發者ID:intfrr,項目名稱:sendto,代碼行數:36,代碼來源:files.go

示例3: Create

// Create inserts a new user
func Create(params map[string]string) (int64, error) {

	params = model.CleanParams(params, AllowedParams())

	err := validateParams(params)
	if err != nil {
		return 0, err
	}

	// Check that this user email is not already in use
	if len(params["email"]) > 0 {
		// Try to fetch a user by this email from the db - we don't allow duplicates
		count, err := Query().Where("email=?", params["email"]).Count()
		if err != nil {
			return 0, err
		}

		if count > 0 {
			return 0, errors.New("A username with this email already exists, sorry.")
		}

	}

	// Update/add some params by default
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Insert(params)
}
開發者ID:maqiv,項目名稱:gohackernews,代碼行數:30,代碼來源:users.go

示例4: Update

// Update this user
func (m *User) Update(params map[string]string) error {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	err := validateParams(params)
	if err != nil {
		return err
	}

	// Make sure updated_at is set to the current time
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Where("id=?", m.Id).Update(params)
}
開發者ID:maqiv,項目名稱:gohackernews,代碼行數:16,代碼來源:users.go

示例5: Update

// Update sets the record in the database from params
func (m *Comment) Update(params map[string]string) error {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	// Check params for invalid values
	err := validateParams(params)
	if err != nil {
		return err
	}

	// Update date params
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Where("id=?", m.Id).Update(params)
}
開發者ID:rogeriomarques,項目名稱:gohackernews,代碼行數:17,代碼來源:comments.go

示例6: Create

// Insert a new tag
func Create(params map[string]string) (int64, error) {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	err := validateParams(params)
	if err != nil {
		return 0, err
	}

	// Update/add some params by default
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Insert(params)
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:17,代碼來源:tags.go

示例7: Create

// Create inserts a new record in the database using params, and returns the newly created id
func Create(params map[string]string) (int64, error) {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	// Check params for invalid values
	err := validateParams(params, true)
	if err != nil {
		return 0, err
	}

	// Update date params
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	return Query().Insert(params)
}
開發者ID:rogeriomarques,項目名稱:gohackernews,代碼行數:18,代碼來源:stories.go

示例8: Create

// Create inserts a new image record in the database and returns the id
func Create(params map[string]string, fh *multipart.FileHeader) (int64, error) {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	err := validateParams(params)
	if err != nil {
		return 0, err
	}

	// Update/add some params by default
	params["created_at"] = query.TimeString(time.Now().UTC())
	params["updated_at"] = query.TimeString(time.Now().UTC())

	id, err := Query().Insert(params)

	if fh != nil && id != 0 {
		// Retreive the form image data by opening the referenced tmp file
		f, err := fh.Open()
		if err != nil {
			return id, err
		}

		// Now retrieve the image concerned, and save the file representations
		image, err := Find(id)
		if err != nil {
			return id, err
		}

		// Save files to disk using the passed in file data (if any)
		err = image.SaveImageRepresentations(f)
		if err != nil {
			return id, err
		}
	}

	return id, err
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:39,代碼來源:images.go

示例9: Update

// Update this tag
func (m *Tag) Update(params map[string]string) error {

	// Remove params not in AllowedParams
	params = model.CleanParams(params, AllowedParams())

	err := validateParams(params)
	if err != nil {
		return err
	}

	// Make sure updated_at is set to the current time
	params["updated_at"] = query.TimeString(time.Now().UTC())

	// Always regenerate dotted ids - we fetch all tags first to avoid db calls
	q := Query().Select("select id,parent_id from tags").Order("id asc")
	tagsList, err := FindAll(q)
	if err == nil {
		params["dotted_ids"] = m.CalculateDottedIds(tagsList)
	} else {
		return err
	}

	return Query().Where("id=?", m.Id).Update(params)
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:25,代碼來源:tags.go


注:本文中的github.com/fragmenta/model.CleanParams函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。