diff --git a/README.md b/README.md index d4fe388..0827004 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ err = mutex.Unlock(ctx) ### Distributed Map -The `Mapp` struct aims to provide similar semantics to native Go map. +The `Map` struct aims to provide similar semantics to a native Go map. ```go ctx := context.Background() diff --git a/marshal/json_marshaler.go b/marshal/json_marshaler.go index 4896989..88461e0 100644 --- a/marshal/json_marshaler.go +++ b/marshal/json_marshaler.go @@ -5,9 +5,11 @@ import ( "encoding/json" ) +// JsonMarshaler is an implementation of Marshaler that uses JSON. type JsonMarshaler[T any] struct { } +// Marshal marshals a go struct into a JSON string. func (jm *JsonMarshaler[T]) Marshal(ctx context.Context, value T) (string, error) { bytes, err := json.Marshal(value) if err != nil { @@ -17,6 +19,7 @@ func (jm *JsonMarshaler[T]) Marshal(ctx context.Context, value T) (string, error return string(bytes), nil } +// Unmarshal unmarshals a go struct from a JSON string into a go struct. func (jm *JsonMarshaler[T]) Unmarshal(ctx context.Context, valueString string, value *T) error { return json.Unmarshal([]byte(valueString), value) } diff --git a/marshal/marshal.go b/marshal/marshal.go index a48880f..8367927 100644 --- a/marshal/marshal.go +++ b/marshal/marshal.go @@ -4,7 +4,10 @@ import ( "context" ) +// Marshaler is an interface contract for marshalling values from Go structs into strings that can be stored in Redis. type Marshaler[T any] interface { + // Marshal marshals a go struct into a string. Marshal(ctx context.Context, value T) (string, error) + // Unmarshal unmarshals a string into a go struct. Unmarshal(ctx context.Context, valueString string, value *T) error }