示例#1
0
func parseMinTime() time.Time {
	tm, err := timelib.ParseTime(*min)
	if err != nil {
		tm = time.Time{}
	}
	return tm
}
示例#2
0
func cleanupRangeParam(in, def string) (string, error) {
	if in == "" {
		return def, nil
	}
	t, err := timelib.ParseTime(in)
	if err != nil {
		return in, err
	}
	return t.UTC().Format(time.RFC3339Nano), nil
}
示例#3
0
文件: db.go 项目: nj3ma/seriesly
func setTimeParam(uv url.Values, name, val string) error {
	if val == "" {
		return nil
	}
	t, err := timelib.ParseTime(val)
	if err != nil {
		return err
	}
	uv.Set(name, strconv.FormatInt(t.UnixNano(), 10))
	return nil
}
示例#4
0
func main() {
	flag.Parse()

	if flag.NArg() < 1 {
		log.Fatalf("Usage:  gzip -dc backup.gz | %v http://seriesly:3133/dbname",
			os.Args[0])
	}

	httputil.InitHTTPTracker(false)

	u := flag.Arg(0)
	setupDb(u)

	minTime := parseMinTime()

	t := time.Tick(5 * time.Second)
	i := 0
	var latestKey string

	d := json.NewDecoder(os.Stdin)
	for {
		kv := map[string]*json.RawMessage{}

		err := d.Decode(&kv)
		if err == io.EOF {
			log.Printf("Done!  Processed %v items. Last was %v",
				i, latestKey)
			break
		}
		maybeFatal(err)

		for k, v := range kv {
			if !minTime.IsZero() {
				thist, err := timelib.ParseTime(k)
				if err == nil && minTime.After(thist) {
					continue
				}
			}
			body := []byte(*v)
			sendOne(u, k, body)
			latestKey = k
		}

		i++
		select {
		case <-t:
			log.Printf("Processed %v items, latest was %v", i, latestKey)
		default:
		}
	}
}
示例#5
0
func newDocument(args []string, w http.ResponseWriter, req *http.Request) {
	var k, fk string
	form, err := url.ParseQuery(req.URL.RawQuery)
	if err == nil {
		fk = form.Get("ts")
	}

	if fk == "" {
		k = time.Now().UTC().Format(time.RFC3339Nano)
	} else {
		t, err := timelib.ParseTime(fk)
		if err != nil {
			emitError(400, w, "Bad time format", err.Error())
			return
		}
		k = t.UTC().Format(time.RFC3339Nano)
	}
	putDocument([]string{args[0], k}, w, req)
}