diff --git a/time.go b/again.go similarity index 99% rename from time.go rename to again.go index 1e38f20..be1186a 100644 --- a/time.go +++ b/again.go @@ -1,10 +1,14 @@ -package main +package again import ( "fmt" "time" ) +type Schedule struct { + NextRunAt time.Time +} + // https://yourbasic.org/golang/time-change-convert-location-timezone/ // https://sebest.github.io/post/create-a-small-docker-image-for-a-golang-binary/ // https://github.com/FKSE/docker-golang-base @@ -12,7 +16,7 @@ import ( // git clone https://github.com/eggert/tz // grep '^Rule' -r tz/ | cut -f8-10 | egrep -iv 'Rule|SAVE' // egrep '\s0:30' -r tz/ -func main() { +func Run() { // blacklist "", "Local" // UTC to TZ should always be correct // TZ to UTC may not be correct diff --git a/cmd/again/again b/cmd/again/again new file mode 100755 index 0000000..7b335b3 Binary files /dev/null and b/cmd/again/again differ diff --git a/cmd/again/again.go b/cmd/again/again.go new file mode 100644 index 0000000..245f9e0 --- /dev/null +++ b/cmd/again/again.go @@ -0,0 +1,55 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net/http" + "os" + "strconv" + "time" + + "git.rootprojects.org/root/go-again/data/jsondb" +) + +func main() { + portEnv := os.Getenv("PORT") + + portInt := flag.Int("port", 0, "port on which to serve http") + addr := flag.String("addr", "", "address on which to serve http") + flag.Parse() + + if "" != portEnv { + if 0 != *portInt { + log.Fatal("You may set PORT or --port, but not both.") + return + } + n, err := strconv.Atoi(portEnv) + if nil != err { + log.Fatalf("Could not parse PORT=%q.", n) + return + } + *portInt = n + } + if *portInt < 1024 || *portInt > 65535 { + log.Fatalf("port should be between 1024 and 65535, not %d.", *portInt) + return + } + portEnv = strconv.Itoa(*portInt) + + server := &http.Server{ + Addr: fmt.Sprintf("%s:%s", *addr, portEnv), + Handler: http.HandlerFunc(handleFunc), + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } + + fmt.Println("Listening on", server.Addr) + log.Fatal(server.ListenAndServe()) +} + +func handleFunc(w http.ResponseWriter, r *http.Request) { + jsondb.List() + w.Write([]byte("Hello, World!")) +} diff --git a/data/jsondb/jsondb.go b/data/jsondb/jsondb.go new file mode 100644 index 0000000..2eebe81 --- /dev/null +++ b/data/jsondb/jsondb.go @@ -0,0 +1,11 @@ +package jsondb + +import ( + "errors" + + again "git.rootprojects.org/root/go-again" +) + +func List() ([]again.Schedule, error) { + return nil, errors.New("Not Implemented") +} diff --git a/examples/awkward.go b/examples/awkward.go new file mode 100755 index 0000000..138db0c --- /dev/null +++ b/examples/awkward.go @@ -0,0 +1,38 @@ +//#!/usr/bin/env go run +package main + +import ( + "fmt" + "time" +) + +func main() { + fmt.Printf("%%s\n") + fmt.Println(time.Parse(time.RFC3339, "2019-06-21T00:01:09-06:00")) + fmt.Println(time.Parse(time.RFC3339, "2019-06-21T00:01:09+06:00")) + fmt.Println(time.Parse(time.RFC3339, "2019-06-21T00:01:09Z")) + fmt.Println(time.Parse(time.RFC3339, "2019-06-21T00:01:09Z-06:00")) + fmt.Println(time.Parse(time.RFC3339, "2019-06-21T00:01:09Z+06:00")) + fmt.Println(time.Date(2020, time.November, 31, 25, 60, 0, 0, time.UTC)) + fmt.Println(time.Date(2016, time.December, 31, 23, 59, 59, 0, time.UTC)) + + var loc *time.Location + loc, _ = time.LoadLocation("America/Denver") + t := time.Date(2019, time.March, 10, 1, 30, 0, 0, loc) + fmt.Println(t, "==", t.UTC()) + // 2019-03-10 01:30:00 -0700 MST == 2019-03-10 08:30:00 +0000 UTC + t = t.Add(time.Duration(1) * time.Hour) + fmt.Println(t, "==", t.UTC()) + // 2019-03-10 03:30:00 -0600 MDT == 2019-03-10 09:30:00 +0000 UTC + + loc, _ = time.LoadLocation("America/Denver") + t = time.Date(2019, time.November, 3, 1, 30, 0, 0, loc) + fmt.Println(t, "==", t.UTC()) + // 2019-11-03 01:30:00 -0600 MDT == 2019-11-03 07:30:00 +0000 UTC + t = t.Add(time.Duration(1) * time.Hour) + fmt.Println(t, "==", t.UTC()) + // 2019-11-03 01:30:00 -0700 MST == 2019-11-03 08:30:00 +0000 UTC + t = t.Add(time.Duration(1) * time.Hour) + fmt.Println(t, "==", t.UTC()) + // 2019-11-03 02:30:00 -0700 MST == 2019-11-03 09:30:00 +0000 UTC +} diff --git a/rollover.go b/examples/rollover.go similarity index 100% rename from rollover.go rename to examples/rollover.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..97231cb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.rootprojects.org/root/go-again + +go 1.12