WIP: more stubs
This commit is contained in:
		
							parent
							
								
									e09133ae54
								
							
						
					
					
						commit
						53190fcfdc
					
				| @ -1,10 +1,14 @@ | |||||||
| package main | package again | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | type Schedule struct { | ||||||
|  | 	NextRunAt time.Time | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // https://yourbasic.org/golang/time-change-convert-location-timezone/ | // https://yourbasic.org/golang/time-change-convert-location-timezone/ | ||||||
| // https://sebest.github.io/post/create-a-small-docker-image-for-a-golang-binary/ | // https://sebest.github.io/post/create-a-small-docker-image-for-a-golang-binary/ | ||||||
| // https://github.com/FKSE/docker-golang-base | // https://github.com/FKSE/docker-golang-base | ||||||
| @ -12,7 +16,7 @@ import ( | |||||||
| // git clone https://github.com/eggert/tz | // git clone https://github.com/eggert/tz | ||||||
| // grep '^Rule' -r tz/ | cut -f8-10 | egrep -iv 'Rule|SAVE' | // grep '^Rule' -r tz/ | cut -f8-10 | egrep -iv 'Rule|SAVE' | ||||||
| // egrep '\s0:30' -r tz/ | // egrep '\s0:30' -r tz/ | ||||||
| func main() { | func Run() { | ||||||
| 	// blacklist "", "Local" | 	// blacklist "", "Local" | ||||||
| 	// UTC to TZ should always be correct | 	// UTC to TZ should always be correct | ||||||
| 	// TZ to UTC may not be correct | 	// TZ to UTC may not be correct | ||||||
							
								
								
									
										
											BIN
										
									
								
								cmd/again/again
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								cmd/again/again
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										55
									
								
								cmd/again/again.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								cmd/again/again.go
									
									
									
									
									
										Normal file
									
								
							| @ -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!")) | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								data/jsondb/jsondb.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								data/jsondb/jsondb.go
									
									
									
									
									
										Normal file
									
								
							| @ -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") | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								examples/awkward.go
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										38
									
								
								examples/awkward.go
									
									
									
									
									
										Executable file
									
								
							| @ -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 | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user