Files
signoz/pkg/factory/name.go
Pranjul Kalsi bdce97a727 fix: replace fmt.Errorf with signoz/pkg/errors and update golangci-li… (#9373)
This PR fulfills the requirements of #9069 by:

- Adding a golangci-lint directive (forbidigo) to disallow all fmt.Errorf usages.
- Replacing existing fmt.Errorf instances with structured errors from github.com/SigNoz/signoz/pkg/errors for consistent error classification and lint compliance.
- Verified lint and build integrity.
2025-10-27 16:30:18 +05:30

47 lines
925 B
Go

package factory
import (
"log/slog"
"regexp"
"github.com/SigNoz/signoz/pkg/errors"
)
var _ slog.LogValuer = (Name{})
var (
// nameRegex is a regex that matches a valid name.
// It must start with a alphabet, and can only contain alphabets, numbers, underscores or hyphens.
nameRegex = regexp.MustCompile(`^[a-z][a-z0-9_-]{0,30}$`)
)
type Name struct {
name string
}
func (n Name) LogValue() slog.Value {
return slog.StringValue(n.name)
}
func (n Name) String() string {
return n.name
}
// NewName creates a new name.
func NewName(name string) (Name, error) {
if !nameRegex.MatchString(name) {
return Name{}, errors.NewInvalidInputf(errors.CodeInvalidInput, "invalid factory name %q", name)
}
return Name{name: name}, nil
}
// MustNewName creates a new name.
// It panics if the name is invalid.
func MustNewName(name string) Name {
n, err := NewName(name)
if err != nil {
panic(err)
}
return n
}