commonatlases

package
v0.89.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

commonatlases is a package full of `atlas.Entry` definions for common types in the standard library.

A frequently useful example is the standard library `time.Time` type, which is frequently serialized in some custom way: as a unix int for example, or perhaps an RFC3339 string; there are many popular choices. (`time.Time` is also an example of where *some* custom behavior is pretty much required, because a default struct-mapping is useless on a struct with no exported fields.)

Index

Constants

This section is empty.

Variables

View Source
var Time_AsRFC3339 = atlas.BuildEntry(time.Time{}).Transform().
	TransformMarshal(atlas.MakeMarshalTransformFunc(
		func(x time.Time) (string, error) {
			return x.Format(time.RFC3339), nil
		})).
	TransformUnmarshal(atlas.MakeUnmarshalTransformFunc(
		func(x string) (time.Time, error) {
			return time.Parse(time.RFC3339, x)
		})).
	Complete()
View Source
var Time_AsUnixInt = atlas.BuildEntry(time.Time{}).Transform().
	TransformMarshal(atlas.MakeMarshalTransformFunc(
		func(x time.Time) (int64, error) {
			return x.Unix(), nil
		})).
	TransformUnmarshal(atlas.MakeUnmarshalTransformFunc(
		func(x int64) (time.Time, error) {
			return time.Unix(x, 0).UTC(), nil
		})).
	Complete()

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL