github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/utils/cputil/operation_builder.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cputil 16 17 import ( 18 "github.com/erda-project/erda-infra/providers/component-protocol/cptype" 19 ) 20 21 // OperationBuilder . 22 type OperationBuilder struct { 23 cptype.Operation 24 } 25 26 // NewOpBuilder . 27 func NewOpBuilder() *OperationBuilder { return &OperationBuilder{} } 28 29 // Build . 30 func (b *OperationBuilder) Build() cptype.Operation { 31 return b.Operation 32 } 33 34 // WithText . 35 func (b *OperationBuilder) WithText(text string) *OperationBuilder { 36 b.Operation.Text = text 37 return b 38 } 39 40 // WithConfirmTip . 41 func (b *OperationBuilder) WithConfirmTip(confirmTip string) *OperationBuilder { 42 b.Operation.Confirm = confirmTip 43 return b 44 } 45 46 // WithDisable . 47 func (b *OperationBuilder) WithDisable(disable bool, tip string) *OperationBuilder { 48 b.Operation.Disabled = disable 49 b.Operation.Tip = tip 50 return b 51 } 52 53 // WithTip . 54 func (b *OperationBuilder) WithTip(tip string) *OperationBuilder { 55 b.Operation.Tip = tip 56 return b 57 } 58 59 // WithSkipRender . 60 func (b *OperationBuilder) WithSkipRender(skipRender bool) *OperationBuilder { 61 b.Operation.SkipRender = skipRender 62 return b 63 } 64 65 // WithAsync . 66 func (b *OperationBuilder) WithAsync(async bool) *OperationBuilder { 67 b.Operation.Async = async 68 return b 69 } 70 71 // WithServerDataPtr . 72 func (b *OperationBuilder) WithServerDataPtr(inputPtr interface{}) *OperationBuilder { 73 var serverData cptype.OpServerData 74 MustObjJSONTransfer(inputPtr, &serverData) 75 b.Operation.ServerData = &serverData 76 return b 77 }