https://github.com/strvcom/strv-backend-go-time
Custom Go time & duration implementation.
https://github.com/strvcom/strv-backend-go-time
duration go golang time
Last synced: 4 months ago
JSON representation
Custom Go time & duration implementation.
- Host: GitHub
- URL: https://github.com/strvcom/strv-backend-go-time
- Owner: strvcom
- License: bsd-3-clause
- Created: 2022-06-29T13:17:48.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2025-08-22T05:18:51.000Z (10 months ago)
- Last Synced: 2025-08-22T07:16:41.260Z (10 months ago)
- Topics: duration, go, golang, time
- Language: Go
- Homepage: https://go.strv.io
- Size: 41 KB
- Stars: 2
- Watchers: 18
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# STRV time
![Latest release][release]
[![codecov][codecov-img]][codecov]
![GitHub][license]
Custom Go time & duration implementation.
## Duration
Duration is a wrapper around [time](https://pkg.go.dev/time) that simplifies `serialization`/`deserialization` of time.
## Examples
```go
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)
}
```
```json
// 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.
[release]: https://img.shields.io/github/v/release/strvcom/strv-backend-go-time
[codecov]: https://codecov.io/gh/strvcom/strv-backend-go-time
[codecov-img]: https://codecov.io/gh/strvcom/strv-backend-go-time/branch/ci/github-actions/graph/badge.svg?token=FM3Y66NLKX
[license]: https://img.shields.io/github/license/strvcom/strv-backend-go-time