func (s Store) GetByUserID(ctx context.Context, ids []int) (map[int][]*entity.Permission, error) {
	ret := make(map[int][]*entity.Permission)
	for _, id := range ids {
		perms := s.auth.PermissionsForUser(id)
		for _, perm := range perms {
			ret[id] = append(ret[id], &entity.Permission{
				Code:  perm[1],
				Level: entity.PermissionLevel(perm[2]),
			})
		}
	}
	return ret, nil
}
GetByUserID returns a map of user ids to a slice of permissions.
package permission
import (
	"context"
	"database/sql"
	"go-webapp-example/internal/pkg/entity"
	"go-webapp-example/pkg/clock"
	"go-webapp-example/pkg/db"
	"github.com/pkg/errors"
)
type authManager interface {
	PermissionsForUser(id int) [][]string
	PermissionsForRole(id int) [][]string
}
type Store struct {
	db    *db.Connection
	auth  authManager
	clock *clock.Clock
}
func NewStore(conn *db.Connection, authManager authManager, opts ...func(s *Store)) *Store {
	s := &Store{db: conn, auth: authManager}
	for _, opt := range opts {
		opt(s)
	}
	return s
}
func (s Store) Find(ctx context.Context, id int) (*entity.Permission, error) {
	var permission entity.Permission
	err := s.db.GetContext(ctx, &permission, "SELECT * FROM permissions WHERE id = ? LIMIT 1", id)
	return &permission, errors.WithStack(checkNotFound(err))
}
func (s Store) Get(ctx context.Context) ([]*entity.Permission, error) {
	var permissions []*entity.Permission
	err := s.db.SelectContext(ctx, &permissions, "SELECT * FROM permissions")
	return permissions, errors.WithStack(err)
}