Skip to content

AlexandrKobalt/json2duration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json2duration

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

Installation

To install the package, run:

go get github.com/AlexandrKobalt/json2duration

Usage

Importing the Package

import "github.com/AlexandrKobalt/json2duration"

Example

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)
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages