adding the go utilities

This commit is contained in:
Mark McIntyre 2021-09-15 09:26:15 -04:00
parent 7ab9bd207d
commit a5711052c7
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,16 @@
# Build the binary
This will likely change into some sort of `Makefile` later, but for now what is needed to build and use this utility is to run the followning commands:
```bash
$ export GOPATH=/home/mock/.local/bin
$ go build .
$ convert-epoch -epoch 1631711695
Epoch time: 1631711695
Local time: Wed, 15 Sep 2021 09:14:55 -0400
Zulu time: Wed, 15 Sep 2021 13:14:55 +0000
```
I would like to remove the `-epoch` flag in favor of just assuming an epoch time value, but that will come later too. Gotta keep learning the language.

View File

@ -0,0 +1,47 @@
package main
import (
"flag"
"fmt"
"strconv"
"time"
)
// Color for extra touch
type Color string
const (
Black Color = "\u001b[30m"
Red = "\u001b[31m"
BoldRed = "\u001b[91m"
Green = "\u001b[32m"
BoldGreen = "\u001b[92m"
Yellow = "\u001b[33m"
BoldYellow = "\u001b[93m"
Blue = "\u001b[34m"
BoldBlue = "\u001b[94m"
Reset = "\u001b[0m"
)
// Simplify the color printing
func cprint(color Color, title string, time_value string) {
fmt.Println(string(Yellow), title, string(color), time_value, string(Reset))
}
func main() {
epoch_now := time.Now().Unix()
// cprint(Red, "Now time: ", time.Unix(epoch_now, 0).Format(time.RFC1123Z))
epoch_time := flag.Int64("epoch", epoch_now, "Supply epoch time value")
flag.Parse()
cprint(Red, "Epoch time: ", strconv.FormatInt(*epoch_time, 10))
local_time := time.Unix(*epoch_time, 0).Format(time.RFC1123Z)
cprint(BoldBlue, "Local time: ", local_time)
zulu_time := time.Unix(*epoch_time, 0).UTC().Format(time.RFC1123Z)
cprint(BoldGreen, "Zulu time: ", zulu_time)
}

3
go/convert-epoch/go.mod Normal file
View File

@ -0,0 +1,3 @@
module convert-epoch
go 1.16