Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
follow bool
prefix string
eventTemplate string
verbose bool
raw bool
)

Expand All @@ -65,17 +64,17 @@ func get(cmd *cobra.Command, args []string) error {

start, err := lib.GetTime(since, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", since)
return fmt.Errorf("failed to parse time '%s'", since)
}

var end time.Time
if cmd.Flags().Lookup("until").Changed {
if cmd.Flags().Lookup("follow").Changed {
return fmt.Errorf("Can't set both --until and --follow")
return fmt.Errorf("can't set both --until and --follow")
}
end, err = lib.GetTime(until, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", until)
return fmt.Errorf("failed to parse time '%s'", until)
}
}

Expand Down Expand Up @@ -117,7 +116,7 @@ ReadLoop:

err = output.Execute(os.Stdout, event)
if err != nil {
fmt.Fprintf(os.Stdout, err.Error())
fmt.Fprint(os.Stdout, err.Error())
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func groups(cmd *cobra.Command, args []string) error {

start, err := lib.GetTime(since, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", since)
return fmt.Errorf("failed to parse time '%s'", since)
}

end, err := lib.GetTime(until, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", until)
return fmt.Errorf("failed to parse time '%s'", until)
}

logReader, err := lib.NewCloudwatchLogsReader(group, prefix, start, end)
Expand Down
4 changes: 0 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"github.com/spf13/cobra"
)

var (
group string
)

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Expand Down
4 changes: 2 additions & 2 deletions cmd/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func streams(cmd *cobra.Command, args []string) error {

start, err := lib.GetTime(since, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", since)
return fmt.Errorf("failed to parse time '%s'", since)
}

end, err := lib.GetTime(until, time.Now())
if err != nil {
return fmt.Errorf("Failed to parse time '%s'", until)
return fmt.Errorf("failed to parse time '%s'", until)
}

logReader, err := lib.NewCloudwatchLogsReader(group, prefix, start, end)
Expand Down
7 changes: 3 additions & 4 deletions lib/cwreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type CloudwatchLogsReader struct {
end time.Time
error error
streamPrefix string
streamNames string
}

// SetMaxStreams sets the maximum number of streams for describe/filter calls
Expand Down Expand Up @@ -109,7 +108,7 @@ func getLogGroup(ctx context.Context, svc *cloudwatchlogs.Client, name string) (
}

if len(groups) == 0 {
return types.LogGroup{}, fmt.Errorf("Could not find log group '%s'", name)
return types.LogGroup{}, fmt.Errorf("could not find log group '%s'", name)
}

if *groups[0].LogGroupName != name {
Expand Down Expand Up @@ -199,10 +198,10 @@ func (c *CloudwatchLogsReader) getLogStreams(ctx context.Context) ([]types.LogSt
sort.Slice(streams[:], func(i, j int) bool { return *streams[i].LastIngestionTime > *streams[j].LastIngestionTime })
if len(streams) == 0 {
if c.streamPrefix != "" {
return nil, fmt.Errorf("No log streams found matching task prefix '%s' in your time window. Consider adjusting your time window with --since and/or --until", c.streamPrefix)
return nil, fmt.Errorf("no log streams found matching task prefix '%s' in your time window. Consider adjusting your time window with --since and/or --until", c.streamPrefix)
}

return nil, errors.New("No log streams found in your time window. Consider adjusting your time window with --since and/or --until")
return nil, errors.New("no log streams found in your time window. Consider adjusting your time window with --since and/or --until")

}
return streams, nil
Expand Down
5 changes: 1 addition & 4 deletions lib/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ func GetTime(value string, reference time.Time) (time.Time, error) {
}

var format string
var parseInLocation bool

// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation
parseInLocation = !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)
var parseInLocation = !strings.ContainsAny(value, "zZ+") && strings.Count(value, "-") != 3

if strings.Contains(value, ".") {
if parseInLocation {
Expand Down