Skip to content

Instantly share code, notes, and snippets.

@dlorenc
Created November 6, 2020 21:27
Show Gist options
  • Save dlorenc/7cd245c2301531f3e789142190bb295b to your computer and use it in GitHub Desktop.
Save dlorenc/7cd245c2301531f3e789142190bb295b to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"os"
"os/exec"
"time"
)
type module struct {
Path string
Version string
Time string
Update struct {
Path string
Version string
Time string
}
}
func main() {
var fp string
if len(os.Args) >= 2 {
fp = os.Args[1]
} else {
fp = "go.mod"
}
cmd := exec.Command("go", "list", "-m", "-u", "-json", "-modfile", fp, "all")
b, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
dec := json.NewDecoder(bytes.NewReader(b))
minutes := float64(0)
for {
var mod module
err := dec.Decode(&mod)
if err == io.EOF {
// all done
break
}
if err != nil {
log.Fatal(err)
}
if mod.Update.Time != "" {
newTime, err := time.Parse(time.RFC3339, mod.Update.Time)
if err != nil {
log.Fatal(err)
}
currentTime, err := time.Parse(time.RFC3339, mod.Time)
if err != nil {
log.Fatal(err)
}
d := newTime.Sub(currentTime)
minutes += d.Minutes()
}
}
fmt.Println(minutes / (365 * 24 * 60))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment