func (g *RuleGroups) Validate() (errs []error) {
	set := map[string]struct{}{}
	for _, g := range g.Groups {
		if g.Name == "" {
			errs = append(errs, errors.Errorf("Groupname should not be empty"))
		}
		if _, ok := set[g.Name]; ok {
			errs = append(
				errs,
				errors.Errorf("groupname: \"%s\" is repeated in the same file", g.Name),
			)
		}
		set[g.Name] = struct{}{}
		for i, r := range g.Rules {
			for _, err := range r.Validate() {
				var ruleName string
				if r.Alert != "" {
					ruleName = r.Alert
				} else {
					ruleName = r.Record
				}
				errs = append(errs, &Error{
					Group:    g.Name,
					Rule:     i,
					RuleName: ruleName,
					Err:      err,
				})
			}
		}
	}
	return errs
}
Validate validates all rules in the rule groups.
package rulefmt
import (
	"io/ioutil"
	"github.com/pkg/errors"
	"github.com/prometheus/common/model"
	"github.com/prometheus/prometheus/promql"
	yaml "gopkg.in/yaml.v2"
)
type Error struct {
	Group    string
	Rule     int
	RuleName string
	Err      error
}
func (err *Error) Error() string {
	return errors.Wrapf(err.Err, "group %q, rule %d, %q", err.Group, err.Rule, err.RuleName).Error()
}
type RuleGroups struct {
	Groups []RuleGroup `yaml:"groups"`
}