Documentation ¶
Overview ¶
Package model defines the inner most layer of the Clean Architecture containing the business-level models, also called entities or domain. This layer may not depend on outter layers, while all other layers may depend on it. By the way, it is acceptable to annotate structs in this package with multiple frameworks dependent tags (e.g., as required by ORM libraries) since adding more tags does not complicate definition of a struct, but can prevent unnecessary structs duplication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownParkingMode = errors.New("unknown parking mode")
ErrUnknownParkingMode indicates that a given string may not be parsed as a valid/known parking mode. This error encodes a description err string and does not communicate the invalid parking mode string itself because the caller of Parse already knows about the invalid parking mode string. An error should be devised with this assumption that caller is aware of the function which is returning that error in addition to its arguments and other relevant system states which may be known before calling the function which is returning the error. Thereafter, the caller should wrap the obtained error and add the function name and arguments (or alternative information which makes the error complete in its new context), so it can be returned. Ultimately, one caller which is responsible to consume the error, can determine the entire call stack information from the single error chain with no reflection.
Functions ¶
This section is empty.
Types ¶
type Car ¶
type Car struct { Name string // name of the car Coordinate Coordinate // current location of car Parked bool // a flag to indicate if car is parked/moving }
Car models a car which may be persisted in a database. This model does not contain an ID in order to demonstrate that how a model which has no tags and its fields do not match with the expected table may be managed by the adapter layer. For the corresponding struct which fixes these issues and stores the resulting struct in the database, see the unexported gCar struct in the pkg/adapter/db/postgres/carsrp/query.go file.
type Coordinate ¶
type Coordinate struct {
Lat, Lon float64 // latitude and longitude of the geo-location
}
Coordinate represents a geographical location with a latitude and longitude. This struct is included in the Car struct in order to demonstrate how a struct may be embedded while mapping them to a database table.
type ParkingMode ¶
type ParkingMode int
ParkingMode specifies the parking mode enum and accepts two old and new methods. Although this enum is numeric, it is (de)serialized as a string for readability in the adapter layer.
const ( ParkingModeInvalid ParkingMode = iota // zero value is invalid ParkingModeOld // old method incurs more delay ParkingModeNew // new method parks the car with no delay )
Valid values for the ParkingMode enum.
func ParseParkingMode ¶
func ParseParkingMode(p string) (ParkingMode, error)
ParseParkingMode parses the given string and returns a ParkingMode, helping to deserialize it when reading a REST API request. For invalid strings, ParkingModeInvalid and ErrUnknownParkingMode will be returned.
func (ParkingMode) String ¶
func (p ParkingMode) String() string
String converts the ParkingMode enum to a string, helping to serialize it for transmission to web clients (for improved readability). Invalid parking mode causes a panic.
func (ParkingMode) Validate ¶
func (p ParkingMode) Validate() error
Validate returns nil if ParkingMode value is valid. For invalid values, an instance of the ParkingModeError will be returned.
type ParkingModeError ¶
type ParkingModeError int
ParkingModeError indicates an invalid parking mode. This error contains the invalid mode as an integer. Principally, this error type is not required (read the doc of ErrUnknownParkingMode). However, it is declared in order to show how extra parameters may be included in an error. The rare scenario which requires such an error instances (with parameters) belongs to functions which find out about the parameter during their execution and not by their arguments. For example, if a range-loop index is relevant for an error, it may be wrapped and returned by error like this.
func (ParkingModeError) Error ¶
func (e ParkingModeError) Error() string
Error implements the error interface, returning a string representation of the ParkingModeError.
type SemVer ¶ added in v1.1.0
type SemVer [3]uint
SemVer represents a released semantic version, consisting of three components. First component indicates the major version. Incrementing it represents backward-incompatible changes. Second component is the minor version which represents feature additions and changes which are backward compatible and visible in the versioned API level. The last component is the patch version. It represents internal implementation changes which are invisible in the API level.
No pre-release version is considered because unreleased versions are not supposed to be maintained and so do not need migration. If such a migration was required in a development machine, the source version may be migrated back to some released version by one binary and then migrated forward to another unreleased version by another binary (where they are seen as a yet to be evolved released version).
func (*SemVer) Marshal ¶ added in v1.1.0
Marshal serializes sv semantic version as its string representation.
func (SemVer) String ¶ added in v1.1.0
String returns the sv semantic version as a dot-separated string consisting of three numbers like major.minor.patch where all numbers are non-negative.
func (*SemVer) UnmarshalText ¶ added in v1.1.0
UnmarshalText deserializes text byte slice as a string consisting of three dot-separated numbers and fills the sv SemVer instance. In case of errors, sv will be left unchanged.