strvcom / strv-backend-go-time

Custom Go time & duration implementation.

Home Page:https://go.strv.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STRV time

Latest release codecov GitHub

Custom Go time & duration implementation.

Duration

Duration is a wrapper around time that simplifies serialization/deserialization of time.

Examples

package main

import (
	timex "go.strv.io/time"
)

type config struct {
	AccessTokenExpiration  timex.Duration `json:"access_token_expiration"`
	RefreshTokenExpiration timex.Duration `json:"refresh_token_expiration"`
}

func main() {
	cfg := config{}
	data, _ := os.ReadFile("config.json")
	_ = json.Unmarshal(data, &cfg)
}
// Content of config.json
{
  "access_token_expiration": "1h",
  "refresh_token_expiration": "30d"
}

As can be seen, there is an option to use days directly, so there is no need to use 720h in case of refresh_token_expiration in the example.

About

Custom Go time & duration implementation.

https://go.strv.io

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 97.6%Language:Makefile 2.4%