github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/communicator/RequestParam.go (about) 1 package communicator 2 3 import ( 4 "errors" 5 ) 6 7 var ( 8 // ErrNoName occurs when the given name is empty 9 ErrNoName = errors.New("name is required") 10 ) 11 12 // RequestParam represents a single request parameter. Immutable. 13 type RequestParam struct { 14 name, value string 15 } 16 17 // RequestParams represents a slice of RequestParam 18 type RequestParams []RequestParam 19 20 // NewRequestParam creates a RequestParam with the given name and value 21 func NewRequestParam(name, value string) (*RequestParam, error) { 22 if len(name) == 0 { 23 return nil, ErrNoName 24 } 25 return &RequestParam{name, value}, nil 26 } 27 28 // Name returns the name of the RequestParam 29 func (rp RequestParam) Name() string { 30 return rp.name 31 } 32 33 // Value returns the value of the RequestParam 34 func (rp RequestParam) Value() string { 35 return rp.value 36 } 37 38 // String is the implmenetation of the Stringer interface 39 // Format: 'name:value' 40 func (rp RequestParam) String() string { 41 return rp.name + ":" + rp.value 42 }