mirror of
https://github.com/hamburghammer/gstat.git
synced 2024-09-28 23:26:05 +02:00
Augusto Dwenger J
f004c93773
This implementation still isn't perfect. One of the encoutered problems is that it does not omit Memory sturcts that are technicly empty. Resulting in JSON with empty objects. This should be a problem for other parsers but it doesn't look good.
35 lines
880 B
Go
35 lines
880 B
Go
package commands
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/hamburghammer/gstat/args"
|
|
)
|
|
|
|
// Date is a the configuration struct to execute the date command
|
|
type Date struct {
|
|
// GetTime is the function to get the actual Time in string format.
|
|
// It should be use to replace/cusomise the time output.
|
|
GetTime func() string
|
|
}
|
|
|
|
// NewDate is a convinice constructor for the Date struct.
|
|
// It sets the GetTime function to standard formatting.
|
|
func NewDate() Date {
|
|
return Date{GetTime: getFormattedTime}
|
|
}
|
|
|
|
// Exec is the implementation of the execution interface for the Date struct.
|
|
func (d Date) Exec(args args.Arguments) ([]byte, error) {
|
|
data := struct{ Date string }{Date: d.PureExec(args)}
|
|
return json.Marshal(data)
|
|
}
|
|
|
|
func (d Date) PureExec(args.Arguments) string {
|
|
return d.GetTime()
|
|
}
|
|
|
|
func getFormattedTime() string {
|
|
return time.Now().Format(time.RFC3339)
|
|
}
|