MCPcopy Index your code
hub / github.com/coder/coder / FindMatchingPresetID

Function FindMatchingPresetID

coderd/prebuilds/parameters.go:17–42  ·  view source on GitHub ↗

FindMatchingPresetID finds a preset ID that matches the provided parameters. It returns the preset ID if a match is found, or uuid.Nil if no match is found. The function performs a bidirectional comparison to ensure all parameters match exactly.

(
	ctx context.Context,
	store database.Store,
	templateVersionID uuid.UUID,
	parameterNames []string,
	parameterValues []string,
)

Source from the content-addressed store, hash-verified

15// It returns the preset ID if a match is found, or uuid.Nil if no match is found.
16// The function performs a bidirectional comparison to ensure all parameters match exactly.
17func FindMatchingPresetID(
18 ctx context.Context,
19 store database.Store,
20 templateVersionID uuid.UUID,
21 parameterNames []string,
22 parameterValues []string,
23) (uuid.UUID, error) {
24 if len(parameterNames) != len(parameterValues) {
25 return uuid.Nil, xerrors.New("parameter names and values must have the same length")
26 }
27
28 result, err := store.FindMatchingPresetID(ctx, database.FindMatchingPresetIDParams{
29 TemplateVersionID: templateVersionID,
30 ParameterNames: parameterNames,
31 ParameterValues: parameterValues,
32 })
33 if err != nil {
34 // Handle the case where no matching preset is found (no rows returned)
35 if errors.Is(err, sql.ErrNoRows) {
36 return uuid.Nil, nil
37 }
38 return uuid.Nil, xerrors.Errorf("find matching preset ID: %w", err)
39 }
40
41 return result, nil
42}

Callers 3

createWorkspaceFunction · 0.92
buildTxMethod · 0.92
TestFindMatchingPresetIDFunction · 0.92

Calls 4

NewMethod · 0.65
FindMatchingPresetIDMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestFindMatchingPresetIDFunction · 0.74