Skip to content

Commit

Permalink
GCLOUD2-12440 unify time layout (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexk53 authored Feb 8, 2024
1 parent 1214c66 commit 9cf8c15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ builds:
flags:
- -trimpath
ldflags:
- '-s -w -X main.AppVersion={{.Version}}'
- '-s -w -X gcorecloud.AppVersion={{.Version}}'
goos:
- windows
- linux
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VERSION ?= $(shell git describe --tags 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
GOARCH ?= $(shell go env GOARCH)
TAGS :=
LDFLAGS := "-w -s -X 'github.com/G-Core/gcorelabscloud-go/cmd.AppVersion=${VERSION}'"
LDFLAGS := "-w -s -X 'github.com/G-Core/gcorelabscloud-go/gcorecloud.AppVersion=${VERSION}' -X 'github.com/G-Core/gcorelabscloud-go/cmd.AppVersion=${VERSION}'"
CMD_PACKAGE := ./cmd/gcoreclient
BINARY := ./gcoreclient

Expand Down
6 changes: 4 additions & 2 deletions provider_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
)

// DefaultUserAgent is the default User-Agent string set in the request header.
const DefaultUserAgent = "gcorecloud/0.0.1"
const DefaultUserAgent = "gcorecloud/%s"

var AppVersion = "0.0.1"

// UserAgent represents a User-Agent header.
type UserAgent struct {
Expand All @@ -36,7 +38,7 @@ func (ua *UserAgent) Prepend(s ...string) {
// GCore cloud User-Agent string.
func (ua *UserAgent) Join() string {
// nolint:gocritic
uaSlice := append(ua.prepend, DefaultUserAgent)
uaSlice := append(ua.prepend, fmt.Sprintf(DefaultUserAgent, AppVersion))
return strings.Join(uaSlice, " ")
}

Expand Down
26 changes: 18 additions & 8 deletions results.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (jt *JSONRFC3339Milli) UnmarshalJSON(data []byte) error {
if err := dec.Decode(&s); err != nil {
return err
}
t, err := time.Parse(RFC3339Milli, s)
t, err := ParseHelper(RFC3339Milli, s)
if err != nil {
return err
}
Expand All @@ -346,7 +346,7 @@ func (jt *JSONRFC3339MilliNoZ) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339MilliNoZ, s)
t, err := ParseHelper(RFC3339MilliNoZ, s)
if err != nil {
return err
}
Expand All @@ -366,7 +366,7 @@ func (jt *JSONRFC1123) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(time.RFC1123, s)
t, err := ParseHelper(time.RFC1123, s)
if err != nil {
return err
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func (jt *JSONRFC3339NoZ) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339NoZ, s)
t, err := ParseHelper(RFC3339NoZ, s)
if err != nil {
return err
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func (jt *JSONRFC3339Z) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339Z, s)
t, err := ParseHelper(RFC3339Z, s)
if err != nil {
return err
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func (jt *JSONRFC3339ZColon) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339ZColon, s)
t, err := ParseHelper(RFC3339ZColon, s)
if err != nil {
return err
}
Expand Down Expand Up @@ -534,7 +534,7 @@ func (jt *JSONRFC3339ZNoT) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339ZNoT, s)
t, err := ParseHelper(RFC3339ZNoT, s)
if err != nil {
return err
}
Expand All @@ -557,7 +557,7 @@ func (jt *JSONRFC3339ZNoTNoZ) UnmarshalJSON(data []byte) error {
if s == "" {
return nil
}
t, err := time.Parse(RFC3339ZNoTNoZ, s)
t, err := ParseHelper(RFC3339ZNoTNoZ, s)
if err != nil {
return err
}
Expand Down Expand Up @@ -815,3 +815,13 @@ type ItemIDName struct {
type ItemID struct {
ID string `json:"id"`
}

// ParseHelper try to parse date with provided layout, if it was failed we try to parse it as RFC3339ZZ
func ParseHelper(layout, date string) (time.Time, error) {
t, err := time.Parse(layout, date)
if err != nil {
t, err = time.Parse(RFC3339ZZ, date)
}

return t, err
}

0 comments on commit 9cf8c15

Please sign in to comment.