github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/invoice/invoice.go (about)

     1  package invoice
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/convert"
     7  )
     8  
     9  // Invoice data structure
    10  type Invoice struct {
    11  	InvoiceHash string
    12  	Invoice     string
    13  	Amount      string
    14  }
    15  
    16  var invoiceFields = map[string]int{
    17  	"InvoiceHash": 0,
    18  	"Invoice":     1,
    19  	"Amount":      4,
    20  }
    21  
    22  // NewFromRaw takes in slice of interfaces and converts them to
    23  // pointer to Invoice
    24  func NewFromRaw(raw []interface{}) (*Invoice, error) {
    25  	if len(raw) < 5 {
    26  		return nil, fmt.Errorf("data slice too short for Invoice: %#v", raw)
    27  	}
    28  
    29  	invc := &Invoice{}
    30  
    31  	invc.InvoiceHash = convert.SValOrEmpty(raw[invoiceFields["InvoiceHash"]])
    32  	invc.Invoice = convert.SValOrEmpty(raw[invoiceFields["Invoice"]])
    33  	invc.Amount = convert.SValOrEmpty(raw[invoiceFields["Amount"]])
    34  
    35  	return invc, nil
    36  }