github.com/aacfactory/fns@v1.2.86-0.20240310083819-80d667fc0a17/services/authorizations/remove.go (about) 1 /* 2 * Copyright 2023 Wang Min Xiang 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package authorizations 19 20 import ( 21 "github.com/aacfactory/errors" 22 "github.com/aacfactory/fns/context" 23 "github.com/aacfactory/fns/runtime" 24 "github.com/aacfactory/fns/services" 25 ) 26 27 var ( 28 removeFnName = []byte("remove") 29 ) 30 31 func Remove(ctx context.Context, account Id, ids ...Id) (err error) { 32 rt := runtime.Load(ctx) 33 _, err = rt.Endpoints().Request( 34 ctx, 35 endpointName, removeFnName, 36 removeParam{ 37 Account: account, 38 Ids: ids, 39 }, 40 ) 41 return 42 } 43 44 type removeParam struct { 45 Account Id `json:"account" avro:"account"` 46 Ids []Id `json:"ids" avro:"ids"` 47 } 48 49 type removeFn struct { 50 store TokenStore 51 } 52 53 func (fn *removeFn) Name() string { 54 return string(removeFnName) 55 } 56 57 func (fn *removeFn) Internal() bool { 58 return true 59 } 60 61 func (fn *removeFn) Readonly() bool { 62 return false 63 } 64 65 func (fn *removeFn) Handle(ctx services.Request) (v any, err error) { 66 param, parmaErr := services.ValueOfParam[removeParam](ctx.Param()) 67 if parmaErr != nil { 68 err = errors.Warning("authorizations: remove failed").WithCause(parmaErr) 69 return 70 } 71 rmErr := fn.store.Remove(ctx, param.Account, param.Ids) 72 if rmErr != nil { 73 err = errors.Warning("authorizations: remove failed").WithCause(rmErr) 74 return 75 } 76 return 77 }