Skip to content

v3: replace usage of optional types in crud with go-option #492

@oleg-jukovec

Description

@oleg-jukovec

The crud package implements its own optional types:

// OptUint is an optional uint.
type OptUint struct {
value uint
exist bool
}
// MakeOptUint creates an optional uint from value.
func MakeOptUint(value uint) OptUint {
return OptUint{
value: value,
exist: true,
}
}
// Get returns the integer value or an error if not present.
func (opt OptUint) Get() (uint, bool) {
return opt.value, opt.exist
}
// OptInt is an optional int.
type OptInt struct {
value int
exist bool
}
// MakeOptInt creates an optional int from value.
func MakeOptInt(value int) OptInt {
return OptInt{
value: value,
exist: true,
}
}
// Get returns the integer value or an error if not present.
func (opt OptInt) Get() (int, bool) {
return opt.value, opt.exist
}
// OptFloat64 is an optional float64.
type OptFloat64 struct {
value float64
exist bool
}
// MakeOptFloat64 creates an optional float64 from value.
func MakeOptFloat64(value float64) OptFloat64 {
return OptFloat64{
value: value,
exist: true,
}
}
// Get returns the float64 value or an error if not present.
func (opt OptFloat64) Get() (float64, bool) {
return opt.value, opt.exist
}
// OptString is an optional string.
type OptString struct {
value string
exist bool
}
// MakeOptString creates an optional string from value.
func MakeOptString(value string) OptString {
return OptString{
value: value,
exist: true,
}
}
// Get returns the string value or an error if not present.
func (opt OptString) Get() (string, bool) {
return opt.value, opt.exist
}
// OptBool is an optional bool.
type OptBool struct {
value bool
exist bool
}
// MakeOptBool creates an optional bool from value.
func MakeOptBool(value bool) OptBool {
return OptBool{
value: value,
exist: true,
}
}
// Get returns the boolean value or an error if not present.
func (opt OptBool) Get() (bool, bool) {
return opt.value, opt.exist
}
// OptTuple is an optional tuple.
type OptTuple struct {
tuple interface{}
}
// MakeOptTuple creates an optional tuple from tuple.
func MakeOptTuple(tuple interface{}) OptTuple {
return OptTuple{tuple}
}
// Get returns the tuple value or an error if not present.
func (o *OptTuple) Get() (interface{}, bool) {
return o.tuple, o.tuple != nil
}

But we already implement a library with optional types:

https://github.com/tarantool/go-option

The goal is to remove the use of custom optional types from the crud package, replacing them with the go-option's ones.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions