gator/internal/executors/middleware.go
Dan Anglin 15386cdb9f
refactor: move executorfunc map
Move the executorFunc map to internal/executors.
2024-10-03 03:37:52 +01:00

20 lines
540 B
Go

package executors
import (
"context"
"fmt"
"codeflow.dananglin.me.uk/apollo/gator/internal/database"
"codeflow.dananglin.me.uk/apollo/gator/internal/state"
)
func middlewareLoggedIn(handler func(s *state.State, exe executor, user database.User) error) executorFunc {
return func(s *state.State, exe executor) error {
user, err := s.DB.GetUserByName(context.Background(), s.Config.CurrentUsername)
if err != nil {
return fmt.Errorf("unable to get the user from the database: %w", err)
}
return handler(s, exe, user)
}
}