func ParseTimestamp(format string, timestamp interface{}, location string) (time.Time, error) {
	switch format {
	case "unix", "unix_ms", "unix_us", "unix_ns":
		return parseUnix(format, timestamp)
	default:
		if location == "" {
			location = "UTC"
		}
		return parseTime(format, timestamp, location)
	}
}
ParseTimestamp parses a Time according to the standard Telegraf options.
These are generally displayed in the toml similar to:
json_time_key= "timestamp"
json_time_format = "2006-01-02T15:04:05Z07:00"
json_timezone = "America/Los_Angeles"

The format can be one of "unix", "unix_ms", "unix_us", "unix_ns", or a Go
time layout suitable for time.Parse.

When using the "unix" format, a optional fractional component is allowed.
Specific unix time precisions cannot have a fractional component.

Unix times may be an int64, float64, or string.  When using a Go format
string the timestamp must be a string.

The location is a location string suitable for time.LoadLocation.  Unix
times do not use the location string, a unix time is always return in the
UTC location.
package internal
import (
	"bufio"
	"compress/gzip"
	"context"
	"errors"
	"fmt"
	"io"
	"math"
	"math/rand"
	"os"
	"os/exec"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"syscall"
	"time"
	"unicode"
)
const alphanum string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var (
	ErrTimeout             = errors.New("command timed out")
	ErrorNotImplemented    = errors.New("not implemented yet")
	ErrorVersionAlreadySet = errors.New("version has already been set")
)
var version string
type ReadWaitCloser struct {
	pipeReader *io.PipeReader
	wg         sync.WaitGroup
}
func SetVersion(v string) error {
	if version != "" {
		return ErrorVersionAlreadySet
	}
	version = v
	return nil
}
func Version() string {
	return version
}
func ProductToken() string {
	return fmt.Sprintf("Telegraf/%s Go/%s",
		Version(), strings.TrimPrefix(runtime.Version(), "go"))
}
func ReadLines(filename string) ([]string, error) {
	return ReadLinesOffsetN(filename, 0, -1)
}
func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
	f, err := os.Open(filename)
	if err != nil {
		return []string{""}, err
	}
	defer f.Close()
	var ret []string
	r := bufio.NewReader(f)
	for i := 0; i < n+int(offset) || n < 0; i++ {
		line, err := r.ReadString('\n')
		if err != nil {
			break
		}
		if i < int(offset) {
			continue
		}
		ret = append(ret, strings.Trim(line, "\n"))
	}
	return ret, nil
}
func RandomString(n int) string {
	var bytes = make([]byte, n)
	rand.Read(bytes)
	for i, b := range bytes {
		bytes[i] = alphanum[b%byte(len(alphanum))]
	}
	return string(bytes)
}
func SnakeCase(in string) string {
	runes := []rune(in)
	length := len(runes)
	var out []rune
	for i := 0; i < length; i++ {
		if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {
			out = append(out, '_')
		}
		out = append(out, unicode.ToLower(runes[i]))
	}
	return string(out)
}
func RandomSleep(max time.Duration, shutdown chan struct{}) {
	if max == 0 {
		return
	}
	sleepns := rand.Int63n(max.Nanoseconds())
	t := time.NewTimer(time.Nanosecond * time.Duration(sleepns))
	select {
	case <-t.C:
		return
	case <-shutdown:
		t.Stop()
		return
	}
}
func RandomDuration(max time.Duration) time.Duration {
	if max == 0 {
		return 0
	}
	sleepns := rand.Int63n(max.Nanoseconds())
	return time.Duration(sleepns)
}
func SleepContext(ctx context.Context, duration time.Duration) error {
	if duration == 0 {
		return nil
	}
	t := time.NewTimer(duration)
	select {
	case <-t.C:
		return nil
	case <-ctx.Done():
		t.Stop()
		return ctx.Err()
	}
}
func AlignDuration(tm time.Time, interval time.Duration) time.Duration {
	return AlignTime(tm, interval).Sub(tm)
}
func AlignTime(tm time.Time, interval time.Duration) time.Time {
	truncated := tm.Truncate(interval)
	if truncated == tm {
		return tm
	}
	return truncated.Add(interval)
}
func ExitStatus(err error) (int, bool) {
	if exiterr, ok := err.(*exec.ExitError); ok {
		if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
			return status.ExitStatus(), true
		}
	}
	return 0, false
}
func (r *ReadWaitCloser) Close() error {
	err := r.pipeReader.Close()
	r.wg.Wait()  
	return err
}
func CompressWithGzip(data io.Reader) (io.ReadCloser, error) {
	pipeReader, pipeWriter := io.Pipe()
	gzipWriter := gzip.NewWriter(pipeWriter)
	rc := &ReadWaitCloser{
		pipeReader: pipeReader,
	}
	rc.wg.Add(1)
	var err error
	go func() {
		_, err = io.Copy(gzipWriter, data)
		gzipWriter.Close()
		pipeWriter.CloseWithError(err)
		rc.wg.Done()
	}()
	return pipeReader, err
}