jsontime

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 5 Imported by: 1

README

jsontime

A json iterator extension that support custom time format.

Usage

100% compatibility with standard lib

Replace

import "encoding/json"

json.Marshal(&data)
json.Unmarshal(input, &data)

with

import "github.com/liamylian/jsontime"

var json = jsontime.ConfigWithCustomTimeFormat

json.Marshal(&data)
json.Unmarshal(input, &data)

Example

package main

import(
	"fmt"
	"time"
	"github.com/liamylian/jsontime"
)

var json = jsontime.ConfigWithCustomTimeFormat

type Book struct {
	Id          int           `json:"id"`
	PublishedAt time.Time     `json:"published_at" time_format:"2006-01-02 15:04:05"`
	UpdatedAt   *time.Time    `json:"updated_at" time_format:"sql_date" time_utc:"true"`
	CreatedAt   time.Time     `json:"created_at" time_format:"sql_datetime" time_location:"UTC"`
}

func main() {
	book := Book {
		Id:          1,
		PublishedAt: time.Now(),
		UpdatedAt:   nil,
		CreatedAt:   time.Now(),
	}
	
	bytes, _ := json.Marshal(book)
	fmt.Printf("%s", bytes)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigWithCustomTimeFormat = jsoniter.ConfigCompatibleWithStandardLibrary

Functions

This section is empty.

Types

type CustomTimeExtension

type CustomTimeExtension struct {
	jsoniter.DummyExtension
}

func (*CustomTimeExtension) UpdateStructDescriptor

func (extension *CustomTimeExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor)

Jump to

Keyboard shortcuts

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