AddProcedure adds a new procedure.
(ctx context.Context, proc Procedure)
| 113 | |
| 114 | // AddProcedure adds a new procedure. |
| 115 | func (pgp *Collection) AddProcedure(ctx context.Context, proc Procedure) error { |
| 116 | // First we'll check to see if it exists |
| 117 | if _, ok := pgp.accessCache[proc.ID]; ok { |
| 118 | return errors.Errorf(`procedure "%s" already exists with same argument types`, proc.ID.ProcedureName()) |
| 119 | } |
| 120 | |
| 121 | // Now we'll add the procedure to our map |
| 122 | data, err := proc.Serialize(ctx) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | h, err := pgp.ns.WriteBytes(ctx, data) |
| 127 | if err != nil { |
| 128 | return err |
| 129 | } |
| 130 | mapEditor := pgp.underlyingMap.Editor() |
| 131 | if err = mapEditor.Add(ctx, string(proc.ID), h); err != nil { |
| 132 | return err |
| 133 | } |
| 134 | newMap, err := mapEditor.Flush(ctx) |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | pgp.underlyingMap = newMap |
| 139 | pgp.mapHash = pgp.underlyingMap.HashOf() |
| 140 | return pgp.reloadCaches(ctx) |
| 141 | } |
| 142 | |
| 143 | // DropProcedure drops an existing procedure. |
| 144 | func (pgp *Collection) DropProcedure(ctx context.Context, procIDs ...id.Procedure) error { |
no test coverage detected