github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/util/converter.go (about)

     1  package util
     2  
     3  import (
     4  	"encoding/base64"
     5  	"fmt"
     6  	"strconv"
     7  )
     8  
     9  // FromUint64 convert uint64 to string
    10  func FromUint64(number uint64) string {
    11  	return fmt.Sprintf("%d", number)
    12  }
    13  
    14  // ToUint64 convert input string to uint64 number
    15  func ToUint64(uint64Str string) (uint64, error) {
    16  	val, err := strconv.ParseUint(uint64Str, 10, 64)
    17  	if err != nil {
    18  		return 0, fmt.Errorf("value must be an unsigned 64 bit integer") // hide error from user
    19  	}
    20  	return val, nil
    21  }
    22  
    23  // ToBase64 converts byte input to string base64 encoded output
    24  func ToBase64(byteValue []byte) string {
    25  	return base64.StdEncoding.EncodeToString(byteValue)
    26  }
    27  
    28  // FromBase64 convert input base64 encoded string to decoded bytes
    29  func FromBase64(bytesStr string) ([]byte, error) {
    30  	return base64.StdEncoding.DecodeString(bytesStr)
    31  }