Use consts for route names and templates.

This commit is contained in:
mikestefanello 2023-12-16 11:07:20 -05:00
parent a787d5dc7f
commit 60c8aefd49
30 changed files with 135 additions and 82 deletions

View file

@ -213,7 +213,7 @@ func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error
// ValidateEmailVerificationToken validates an email verification token and returns the associated email address if
// the token is valid and has not expired
func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error) {
t, err := jwt.Parse(token, func(t *jwt.Token) (interface{}, error) {
t, err := jwt.Parse(token, func(t *jwt.Token) (any, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
}

View file

@ -28,7 +28,7 @@ type (
client *CacheClient
key string
group string
data interface{}
data any
expiration time.Duration
tags []string
}
@ -38,7 +38,7 @@ type (
client *CacheClient
key string
group string
dataType interface{}
dataType any
}
// cacheFlush handles chaining a flush operation
@ -128,7 +128,7 @@ func (c *cacheSet) Group(group string) *cacheSet {
}
// Data sets the data to cache
func (c *cacheSet) Data(data interface{}) *cacheSet {
func (c *cacheSet) Data(data any) *cacheSet {
c.data = data
return c
}
@ -174,13 +174,13 @@ func (c *cacheGet) Group(group string) *cacheGet {
}
// Type sets the expected Go type of the data being retrieved from the cache
func (c *cacheGet) Type(expectedType interface{}) *cacheGet {
func (c *cacheGet) Type(expectedType any) *cacheGet {
c.dataType = expectedType
return c
}
// Fetch fetches the data from the cache
func (c *cacheGet) Fetch(ctx context.Context) (interface{}, error) {
func (c *cacheGet) Fetch(ctx context.Context) (any, error) {
if c.key == "" {
return nil, errors.New("no cache key specified")
}

View file

@ -30,7 +30,7 @@ type (
subject string
body string
template string
templateData interface{}
templateData any
}
)
@ -128,7 +128,7 @@ func (m *mail) Template(template string) *mail {
}
// TemplateData sets the data that will be passed to the template specified when calling Template()
func (m *mail) TemplateData(data interface{}) *mail {
func (m *mail) TemplateData(data any) *mail {
m.templateData = data
return m
}

View file

@ -23,7 +23,7 @@ type (
task struct {
client *TaskClient
typ string
payload interface{}
payload any
periodic *string
queue *string
maxRetries *int
@ -75,7 +75,7 @@ func (t *TaskClient) New(typ string) *task {
}
// Payload sets the task payload data which will be sent to the task handler
func (t *task) Payload(payload interface{}) *task {
func (t *task) Payload(payload any) *task {
t.payload = payload
return t
}

View file

@ -155,7 +155,7 @@ func (t *TemplateRenderer) Load(group, key string) (*TemplateParsed, error) {
}
// Execute executes a template with the given data and provides the output
func (t *TemplateParsed) Execute(data interface{}) (*bytes.Buffer, error) {
func (t *TemplateParsed) Execute(data any) (*bytes.Buffer, error) {
if t.Template == nil {
return nil, errors.New("cannot execute template: template not initialized")
}
@ -209,7 +209,7 @@ func (t *templateBuilder) Store() (*TemplateParsed, error) {
// Execute executes the template with the given data.
// If the template has not already been cached, this will parse and cache the template
func (t *templateBuilder) Execute(data interface{}) (*bytes.Buffer, error) {
func (t *templateBuilder) Execute(data any) (*bytes.Buffer, error) {
tp, err := t.Store()
if err != nil {
return nil, err

View file

@ -18,7 +18,7 @@ func NewValidator() *Validator {
}
// Validate validates a struct
func (v *Validator) Validate(i interface{}) error {
func (v *Validator) Validate(i any) error {
if err := v.validator.Struct(i); err != nil {
return err
}