Skip to content

Commit

Permalink
LoadTest Status unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahaja committed Sep 19, 2020
1 parent 7a92e4a commit 758c946
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
54 changes: 27 additions & 27 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ltt
import (
"context"
"flag"
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -51,8 +52,20 @@ var statusTypes = map[StatusType]string{
StatusStopping: "stopping",
}

var statusTypesFromString = map[string]StatusType{
"stopped": StatusStopped,
"spawning": StatusSpawning,
"running": StatusRunning,
"stopping": StatusStopping,
}

func (s *StatusType) UnmarshalJSON(bytes []byte) error {
*s = statusTypesFromString[string(bytes)]
return nil
}

func (s StatusType) MarshalJSON() ([]byte, error) {
return []byte(statusTypes[s]), nil
return []byte(fmt.Sprintf(`"%s"`, statusTypes[s])), nil
}

const (
Expand Down

0 comments on commit 758c946

Please sign in to comment.