atomic time package with json Marshal / Unmarshal support

ATime

Atomic Time package for Go, optimized for performance yet simple to use.

Usage

// one line create
dt := atime.New() // allocates *AtomicTime
dt := atime.NewNow() // allocates *AtomicTime and set it to time.Now().UTC()
dt := atime.NewTime(time.Now()) // allocates *AtomicTime and set it your given time

// change values
dt.SetNow()  // set to time.Now().UTC()
dt.SetNil() // set to 0, expect to get null from json.Marshall
dt.SetToTime(time.Now()) // set it your given time

// get values
dt.GetUnixTime  // get unix time as int64
dt.GetTime() // get time as time.Time
dt.GetTimePointer() // get time as *time.Time

// get duration from Now
dt.SinceNow()

// embedding
type Foo struct {
  myTime *atime.AtomicTime // always use pointer to avoid copy
}

Benchmark:

  • Go 1.7.6
  • Windows 11 64bit
  • AMD Ryzen Threadripper 3960X 24-Core Processor
#read
BenchmarkMutexTimeRead
BenchmarkMutexTimeRead-48               653150656                9.197 ns/op           0 B/op          0 allocs/op
BenchmarkATimeReadTime
BenchmarkATimeReadTime-48               1000000000               0.5350 ns/op          0 B/op          0 allocs/op
BenchmarkATimeReadUnix
BenchmarkATimeReadUnix-48               1000000000               0.4470 ns/op          0 B/op          0 allocs/op

#write
BenchmarkMutexTimePointerWrite
BenchmarkMutexTimePointerWrite-48       134374093               44.44 ns/op           24 B/op          1 allocs/op
BenchmarkMutexTimeWrite
BenchmarkMutexTimeWrite-48              293398590               19.52 ns/op            0 B/op          0 allocs/op
BenchmarkATimeWrite
BenchmarkATimeWrite-48                  776197038                7.181 ns/op           0 B/op          0 allocs/op
  
Similar Resources

mateors zip and unzip package

Zip unzip package How to install this package? go get github.com/mateors/mzip How to make zip files? package main import "github.com/mateors/mzip" f

Apr 25, 2022

A Go filesystem package for working with files and directories

Stowage A Go filesystem package for working with files and directories, it features a simple API with support for the common files and directories ope

May 28, 2021

Maybe is a Go package to provide basic functionality for Option type structures

Maybe Maybe is a library that adds an Option data type for some native Go types. What does it offer: The types exported by this library are immutable

Oct 4, 2022

gsheet is a CLI tool (and Golang package) for piping csv data to and from Google Sheets

gsheet Table of Contents Introduction Why? Installation Authentication and Authorization What about OAuth authentication? CLI Usage Sheet commands Dri

Nov 15, 2022

noioutil finds files using the "io/ioutil" package.

noioutil noioutil finds files using the "io/ioutil" package.

Dec 28, 2021

Yet another Go package for working with *.golden test files, with a focus on simplicity.

go-golden Yet another Go package for working with *.golden test files, with a focus on simplicity. Import import "github.com/jimeh/go-golden" Usage fu

Aug 3, 2022

Go package for tail-ing files

Go package for tail-ing files A Go package striving to emulate the features of the BSD tail program. t, err := tail.TailFile("/var/log/nginx.log", tai

Dec 8, 2021

CSV asynchronous I/O package for go.

golib/csvio selectでの非同期処理に対応した、csvベースでの読み込み/書き込みを行うライブラリです。 csvio.Config CSVのコンマの値や、クォートの有無など、扱うCSVに対するフォーマットを指定できます。 csvio.Reader selectでの非同期処理に対応した、

Jan 21, 2022

Go package that adds marshal and unmarshal features to nullable sql types.

#Nullable Very simple Go module to handle nullable fields. Basically, it adds to sql package types the JSON marshal and unmarshal features. It has 100

Jan 20, 2022

A better way to marshal and unmarshal YAML in Golang

YAML marshaling and unmarshaling support for Go Introduction A wrapper around go-yaml designed to enable a better way of handling YAML when marshaling

Jan 4, 2023

Atomic: a go package for atomic file writing

atomic import "github.com/natefinch/atomic" atomic is a go package for atomic file writing By default, writing to a file in go (and generally any lan

Nov 10, 2021

Type to unmarshal JSON objects while keeping the order of the keys.

orderedjson import "github.com/aybabtme/orderedjson" Sometimes you decode a JSON object in Go, and despite the JSON spec technically requiring that ke

Oct 29, 2022

Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Oct 27, 2022

Marshal data into commands struct!

Marshal data into commands struct!

Commandarrgh in a nuthsell Commandarrgh is an interface that helps you marshaling data into a command arguments structure. Maybe you have been trying

Dec 18, 2021

Time-Based One-Time Password (TOTP) and HMAC-Based One-Time Password (HOTP) library for Go.

otpgo HMAC-Based and Time-Based One-Time Password (HOTP and TOTP) library for Go. Implements RFC 4226 and RFC 6238. Contents Supported Operations Read

Dec 19, 2022

Time struct in Go that uses 4 bytes of memory vs the 24 bytes of time.Time

A tiny time object in Go. Tinytime uses 4 bytes of memory vs the 24 bytes of a standard time.Time{}

Oct 3, 2022

Dynatomic is a library for using dynamodb as an atomic counter

Dynatomic Dynatomic is a library for using dynamodb as an atomic counter Dynatomic Motivation Usage Development Contributing Motivation The dynatomic

Sep 26, 2022

atomic measures + Prometheus exposition library

About Atomic measures with Prometheus exposition for the Go programming language. This is free and unencumbered software released into the public doma

Sep 27, 2022

All the missing AMD64 atomic instructions

atomics All the AMD64 atomic instructions, exposed as Go functions: ⚠️ PRE-ALPHA ⚠️ Features LOCK {ADD,ADC,AND,BTC,BTR,BTS,CMPXCHG,CMPXCH8B,CMPXCHG16B

Sep 20, 2021
Related tags
go-fastdfs 是一个简单的分布式文件系统(私有云存储),具有无中心、高性能,高可靠,免维护等优点,支持断点续传,分块上传,小文件合并,自动同步,自动修复。Go-fastdfs is a simple distributed file system (private cloud storage), with no center, high performance, high reliability, maintenance free and other advantages, support breakpoint continuation, block upload, small file merge, automatic synchronization, automatic repair.(similar fastdfs).
go-fastdfs 是一个简单的分布式文件系统(私有云存储),具有无中心、高性能,高可靠,免维护等优点,支持断点续传,分块上传,小文件合并,自动同步,自动修复。Go-fastdfs is a simple distributed file system (private cloud storage), with no center, high performance, high reliability, maintenance free and other advantages, support breakpoint continuation, block upload, small file merge, automatic synchronization, automatic repair.(similar fastdfs).

中文 English 愿景:为用户提供最简单、可靠、高效的分布式文件系统。 go-fastdfs是一个基于http协议的分布式文件系统,它基于大道至简的设计理念,一切从简设计,使得它的运维及扩展变得更加简单,它具有高性能、高可靠、无中心、免维护等优点。 大家担心的是这么简单的文件系统,靠不靠谱,可不

Jan 8, 2023
A PDF document generator with high level support for text, drawing and images

GoFPDF document generator Package go-pdf/fpdf implements a PDF document generator with high level support for text, drawing and images. Features UTF-8

Jan 4, 2023
File uploader with support for multiple hosts and progress reporting written in Go.
File uploader with support for multiple hosts and progress reporting written in Go.

go-upload File uploader with support for multiple hosts and progress reporting written in Go. Windows, Linux, macOS and Android binaries Usage Upload

Dec 18, 2022
Takes an input http.FileSystem (likely at go generate time) and generates Go code that statically implements it.

vfsgen Package vfsgen takes an http.FileSystem (likely at go generate time) and generates Go code that statically implements the provided http.FileSys

Dec 18, 2022
Simple go script that converts csv file into a json document

csv-go-parser Simple go script that converts csv file into a json document. CSV Input: id,first_name,last_name,email,avatar,ip_address 1,Pauline,Hirth

Jun 4, 2022
Provide an upload endpoint that stores files on pinata and returns a json response with the uploaded file pinata url

Purpose Build a template repository to get to coding as quickly as possible, by starting from a common template which follows the guidelines here Feat

Dec 30, 2021
ZipFly: a golang HTTP server that streams a ZIP file from a list of URLs extracted from a JSON manifest

ZipFly, streaming files as a ZIP like a ?? ZipFly is a golang HTTP server that s

Jun 6, 2022
A package to allow one to concurrently go through a filesystem with ease

skywalker Skywalker is a package to allow one to concurrently go through a filesystem with ease. Features Concurrency BlackList filtering WhiteList fi

Nov 14, 2022
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature

filetype Small and dependency free Go package to infer file and MIME type checking the magic numbers signature. For SVG file type checking, see go-is-

Jan 3, 2023
Package cae implements PHP-like Compression and Archive Extensions.

Compression and Archive Extensions 中文文档 Package cae implements PHP-like Compression and Archive Extensions. But this package has some modifications de

Jun 16, 2022