generated from templates/go-generic
20 lines
540 B
Go
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)
|
|
}
|
|
}
|