Skip to content

Commit

Permalink
Fix version type string
Browse files Browse the repository at this point in the history
* Also various small cleanups
  • Loading branch information
tliron committed Dec 19, 2018
1 parent 64e0ebe commit abd8d23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
14 changes: 6 additions & 8 deletions tosca/grammars/v1_1/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,15 @@ func (self *Timestamp) Time() time.Time {
}

func parseTimestampUint(value string) uint32 {
u, err := strconv.ParseUint(value, 10, 32)
if err != nil {
panic("as long as the regexp does it's job we should never get here")
if u, err := strconv.ParseUint(value, 10, 32); err == nil {
return uint32(u)
}
return uint32(u)
panic("as long as the regexp does its job we should never get here")
}

func parseTimestampFloat(value string) float64 {
u, err := strconv.ParseFloat(value, 64)
if err != nil {
panic("as long as the regexp does it's job we should never get here")
if u, err := strconv.ParseFloat(value, 64); err == nil {
return u
}
return u
panic("as long as the regexp does its job we should never get here")
}
9 changes: 4 additions & 5 deletions tosca/grammars/v1_1/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var VersionRE = regexp.MustCompile(
//

type Version struct {
String_ string `json:"$str" yaml:"$str"`
String_ string `json:"$string" yaml:"$string"`

Major uint32 `json:"major" yaml:"major"`
Minor uint32 `json:"minor" yaml:"minor"`
Expand Down Expand Up @@ -111,9 +111,8 @@ func (self *Version) Compare(data interface{}) (int, error) {
}

func parseVersionUint(value string) uint32 {
u, err := strconv.ParseUint(value, 10, 32)
if err != nil {
panic("as long as the regexp does it's job we should never get here")
if u, err := strconv.ParseUint(value, 10, 32); err == nil {
return uint32(u)
}
return uint32(u)
panic("as long as the regexp does its job we should never get here")
}
2 changes: 2 additions & 0 deletions tosca/normal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type WorkflowPrecondition struct {
// WorkflowStep
//

// TODO: JSON/YAML marshalling

type WorkflowStep struct {
Workflow *Workflow `json:"-" yaml:"-"`
Name string `json:"-" yaml:"-"`
Expand Down

0 comments on commit abd8d23

Please sign in to comment.