Example #1
0
File: util.go Project: l-k-/origins
// Parses the since and asof time values from the request.
func parseTimeParams(r *http.Request) (time.Time, time.Time, error) {
	var (
		err         error
		since, asof time.Time
	)

	q := r.URL.Query()

	// Parse query parameters
	if q.Get("since") != "" {
		if since, err = chrono.Parse(q.Get("since")); err != nil {
			return since, asof, err
		}
	}

	if q.Get("asof") != "" {
		if asof, err = chrono.Parse(q.Get("asof")); err != nil {
			return since, asof, err
		}
	}

	return since, asof, nil
}
Example #2
0
File: log.go Project: l-k-/origins
		if len(args) == 0 {
			cmd.Usage()
			os.Exit(1)
		}

		var (
			w           io.Writer
			fw          origins.Writer
			asof, since time.Time

			domains = args
			file    = viper.GetString("log_file")
			format  = viper.GetString("log_format")
		)

		since, _ = chrono.Parse(viper.GetString("log_since"))
		asof, _ = chrono.Parse(viper.GetString("log_asof"))

		engine := initStorage()

		if file == "" {
			w = os.Stdout
			defer os.Stdout.Sync()
		} else {
			f, err := os.Create(file)

			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
Example #3
0
			cmd.Usage()
			return
		}

		// Check optional arguments.
		domain := viper.GetString("generate_domain")
		ts := viper.GetString("generate_time")
		op := viper.GetString("generate_operation")

		var (
			t   time.Time
			err error
		)

		if ts != "" {
			t, err = chrono.Parse(ts)

			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
		}

		operation, err := origins.ParseOperation(op)

		if err != nil {
			fmt.Print(err)
			os.Exit(1)
		}

		// Construct the full script name.