duration is a Go package that provides functionality to convert integer values from JSON configurations into time.Duration values. It supports conversions for:
- nanoseconds
- milliseconds
- seconds
- minutes
- hours
To install the package, run:
go get github.com/AlexandrKobalt/json2duration
Importing the Package
import "github.com/AlexandrKobalt/json2duration"
package main
import (
"encoding/json"
"fmt"
"github.com/AlexandrKobalt/json2duration"
)
func main() {
jsonData := {"duration": 120}
var data struct {
Duration json2duration.Seconds json:"duration"
}
err := json.Unmarshal([]byte(jsonData), &data)
if err != nil {
panic(err)
}
fmt.Println("Duration in seconds:", data.Duration.Seconds())
fmt.Println("Duration:", data.Duration.Duration)
}
This project is licensed under the MIT License. See the LICENSE file for details.