github.com/mailru/activerecord@v1.12.2/pkg/serializer/printf.go (about)

     1  package serializer
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/mailru/activerecord/pkg/serializer/errs"
     8  )
     9  
    10  func PrintfUnmarshal(opt string, data string, v *float64) error {
    11  	f, err := strconv.ParseFloat(data, 64)
    12  	if err != nil {
    13  		return fmt.Errorf("%w: %v", errs.ErrPrintfParse, err)
    14  	}
    15  
    16  	*v = f
    17  
    18  	return nil
    19  }
    20  
    21  func PrintfMarshal(opt string, data float64) (string, error) {
    22  	return fmt.Sprintf(opt, data), nil
    23  }