github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/api/lc_sign_options.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package api 10 11 import ( 12 "github.com/vchain-us/vcn/pkg/meta" 13 ) 14 15 // SignOption is a functional option for signing operations 16 type LcSignOption func(*lcSignOpts) error 17 18 type lcSignOpts struct { 19 status meta.Status 20 visibility meta.Visibility 21 attach []string 22 bom string 23 } 24 25 func makeLcSignOpts(opts ...LcSignOption) (o *lcSignOpts, err error) { 26 o = &lcSignOpts{ 27 status: meta.StatusTrusted, 28 visibility: meta.VisibilityPrivate, 29 attach: nil, 30 } 31 32 for _, option := range opts { 33 if option == nil { 34 continue 35 } 36 if err := option(o); err != nil { 37 return nil, err 38 } 39 } 40 41 return 42 } 43 44 // SignWithStatus returns the functional option for the given status. 45 func LcSignWithStatus(status meta.Status) LcSignOption { 46 return func(o *lcSignOpts) error { 47 o.status = status 48 return nil 49 } 50 } 51 52 // SignWithVisibility returns the functional option for the given visibility. 53 func LcSignWithVisibility(visibility meta.Visibility) LcSignOption { 54 return func(o *lcSignOpts) error { 55 o.visibility = visibility 56 return nil 57 } 58 } 59 60 // LcSignWithAttachments returns the functional option for the given status. 61 func LcSignWithAttachments(attach []string) LcSignOption { 62 return func(o *lcSignOpts) error { 63 o.attach = attach 64 return nil 65 } 66 } 67 68 func LcSignWithBom(bom string) LcSignOption { 69 return func(o *lcSignOpts) error { 70 o.bom = bom 71 return nil 72 } 73 }