go validate

2026-08-30 浏览 (1)

validate.go 源码

// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials  : https://learngoprogramming.com
// In-person training  : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

package record

import "errors"

// validate whether the current record is valid or not.
func (r *Record) validate() error {
	var msg string

	switch {
	case r.Domain == "":
		msg = "record.domain cannot be empty"
	case r.Page == "":
		msg = "record.page cannot be empty"
	case r.Visits < 0:
		msg = "record.visits cannot be negative"
	case r.Uniques < 0:
		msg = "record.uniques cannot be negative"
	}

	if msg != "" {
		return errors.New(msg)
	}
	return nil
}

你可能感兴趣的文章

go record

go sum

go text

go json

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/r3hkwnas