Skip to main content

valuer.go

valuer.go - Overview

  1. Overview Defines the Valuer interface, which combines several standard interfaces for handling values, particularly in the context of databases and JSON serialization.

  2. Detailed Documentation

Interface: Valuer

  • Purpose: Combines interfaces for value handling, including zero value checking, string representation, JSON marshaling/unmarshaling, and database scanning/value conversion.
  • Methods:
    • IsZero() bool:
      • Purpose: Returns true if the value is considered empty or zero.
      • Returns: bool - Indicates whether the value is zero.
    • StringValue() string:
      • Purpose: Returns the string representation of the value.
      • Returns: string - The string representation.
    • MarshalJSON() ([]byte, error):
      • Purpose: Returns the JSON encoding of the value. Part of the json.Marshaler interface.
      • Returns: []byte - JSON data; error - Any error during marshaling.
    • UnmarshalJSON(data []byte) error:
      • Purpose: Returns the JSON decoding of the value. Part of the json.Unmarshaler interface.
      • Parameters:
        • data []byte: The JSON data to unmarshal.
      • Returns: error - Any error during unmarshaling.
    • Scan(value interface{}) error:
      • Purpose: Scans a value from a database driver into the underlying struct. Part of the sql.Scanner interface.
      • Parameters:
        • value interface{}: The value to scan from the database.
      • Returns: error - Any error during scanning.
    • Value() (driver.Value, error):
      • Purpose: Converts the struct to a database driver's value. Part of the driver.Valuer interface.
      • Returns: driver.Value - The driver value; error - Any error during conversion.

Include in Getting Started: NO