Skip to content

Commit

Permalink
Use stringer for static type conversions (#688)
Browse files Browse the repository at this point in the history
* Use stringer for static type conversions

* Fix suggested changes

Co-authored-by: Adam Bozanich <adam.boz@gmail.com>
  • Loading branch information
akhilkumarpilli and boz committed Jun 22, 2020
1 parent 2d05f5b commit ec31a6c
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 29 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -24,6 +24,9 @@ bins: $(BINS)
build:
$(GO) build ./...

generate:
$(GO) generate ./...

akashctl:
$(GO) build $(BUILD_FLAGS) ./cmd/akashctl

Expand Down Expand Up @@ -136,6 +139,7 @@ devdeps-install:
$(GO) install github.com/vektra/mockery/.../
$(GO) install k8s.io/code-generator/...
$(GO) install sigs.k8s.io/kind
$(GO) install golang.org/x/tools/cmd/stringer

test-integration: $(BINS)
cp akashctl akashd ./_build
Expand Down
2 changes: 1 addition & 1 deletion cmd/statik/statik.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/swagger-ui/swagger.yaml
Expand Up @@ -883,7 +883,7 @@ paths:
x-example: akash1zsgzee6vvx942c4c69vl859w9azn77j8uhduug
- in: query
name: state
description: Order state to filter (active,insufficient,closed)
description: Order state to filter (active,insufficient-funds,closed)
required: false
type: string
x-example: active
Expand Down
1 change: 1 addition & 0 deletions tools.go
Expand Up @@ -5,6 +5,7 @@ package tools
//nolint
import (
_ "github.com/vektra/mockery"
_ "golang.org/x/tools/cmd/stringer"
_ "k8s.io/code-generator"
_ "sigs.k8s.io/kind"
)
2 changes: 1 addition & 1 deletion x/deployment/client/cli/flags.go
Expand Up @@ -94,7 +94,7 @@ func DepFiltersFromFlags(flags *pflag.FlagSet) (query.DeploymentFilters, error)
// AddGroupFilterFlags add flags to filter for group list
func AddGroupFilterFlags(flags *pflag.FlagSet) {
flags.String("owner", "", "group owner address to filter")
flags.String("state", "", "group state to filter (open,ordered,matched,insufficient,closed)")
flags.String("state", "", "group state to filter (open,ordered,matched,insufficient-funds,closed)")
}

// GroupFiltersFromFlags returns GroupFilters with given flags and error if occurred
Expand Down
47 changes: 47 additions & 0 deletions x/deployment/types/autogen_stringer.go

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

26 changes: 14 additions & 12 deletions x/deployment/types/types.go
Expand Up @@ -8,14 +8,16 @@ import (
"github.com/ovrclk/akash/types"
)

//go:generate stringer -linecomment -output=autogen_stringer.go -type=DeploymentState,GroupState

// DeploymentState defines state of deployment
type DeploymentState uint8

const (
// DeploymentActive is used when state of deployment is active
DeploymentActive DeploymentState = iota + 1
DeploymentActive DeploymentState = iota + 1 // active
// DeploymentClosed is used when state of deployment is closed
DeploymentClosed
DeploymentClosed // closed
)

var (
Expand Down Expand Up @@ -45,24 +47,24 @@ type GroupState uint8

const (
// GroupOpen is used when state of group is open
GroupOpen GroupState = iota + 1
GroupOpen GroupState = iota + 1 // open
// GroupOrdered is used when state of group is ordered
GroupOrdered
GroupOrdered // ordered
// GroupMatched is used when state of group is matched
GroupMatched
GroupMatched // matched
// GroupInsufficientFunds is used when group has insufficient funds
GroupInsufficientFunds
GroupInsufficientFunds // insufficient-funds
// GroupClosed is used when state of group is closed
GroupClosed
GroupClosed // closed
)

// GroupStateMap is used to decode group state flag value
var GroupStateMap = map[string]GroupState{
"open": GroupOpen,
"ordered": GroupOrdered,
"matched": GroupMatched,
"insufficient": GroupInsufficientFunds,
"closed": GroupClosed,
"open": GroupOpen,
"ordered": GroupOrdered,
"matched": GroupMatched,
"insufficient-funds": GroupInsufficientFunds,
"closed": GroupClosed,
}

// GroupSpec stores group specifications
Expand Down
2 changes: 1 addition & 1 deletion x/market/client/cli/flags.go
Expand Up @@ -121,7 +121,7 @@ func BidFiltersFromFlags(flags *pflag.FlagSet) (query.BidFilters, error) {
// AddLeaseFilterFlags add flags to filter for lease list
func AddLeaseFilterFlags(flags *pflag.FlagSet) {
flags.String("owner", "", "lease owner address to filter")
flags.String("state", "", "lease state to filter (active,insufficient,closed)")
flags.String("state", "", "lease state to filter (active,insufficient-funds,closed)")
}

// LeaseFiltersFromFlags returns LeaseFilters with given flags and error if occurred
Expand Down
67 changes: 67 additions & 0 deletions x/market/types/autogen_stringer.go

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

28 changes: 15 additions & 13 deletions x/market/types/types.go
Expand Up @@ -7,16 +7,18 @@ import (
dtypes "github.com/ovrclk/akash/x/deployment/types"
)

//go:generate stringer -linecomment -output=autogen_stringer.go -type=OrderState,BidState,LeaseState

// OrderState defines state of order
type OrderState uint8

const (
// OrderOpen is used when state of order is open
OrderOpen OrderState = iota + 1
OrderOpen OrderState = iota + 1 // order
// OrderMatched is used when state of order is matched
OrderMatched
OrderMatched // matched
// OrderClosed is used when state of order is closed
OrderClosed
OrderClosed // closed
)

var (
Expand Down Expand Up @@ -111,13 +113,13 @@ type BidState uint8

const (
// BidOpen is used when state of bid is opened
BidOpen BidState = iota + 1
BidOpen BidState = iota + 1 // open
// BidMatched is used when state of bid is matched
BidMatched
BidMatched // matched
// BidLost is used when state of bid is lost
BidLost
BidLost // lost
// BidClosed is used when state of bid is closed
BidClosed
BidClosed // closed
)

// BidStateMap is used to decode bid state flag value
Expand Down Expand Up @@ -145,18 +147,18 @@ type LeaseState uint8

const (
// LeaseActive is used when state of lease is active
LeaseActive LeaseState = iota + 1
LeaseActive LeaseState = iota + 1 // active
// LeaseInsufficientFunds is used when lease has insufficient funds
LeaseInsufficientFunds
LeaseInsufficientFunds // insufficient-funds
// LeaseClosed is used when state of lease is closed
LeaseClosed
LeaseClosed // closed
)

// LeaseStateMap is used to decode lease state flag value
var LeaseStateMap = map[string]LeaseState{
"active": LeaseActive,
"insufficient": LeaseInsufficientFunds,
"closed": LeaseClosed,
"active": LeaseActive,
"insufficient-funds": LeaseInsufficientFunds,
"closed": LeaseClosed,
}

// Lease stores LeaseID, state of lease and price
Expand Down

0 comments on commit ec31a6c

Please sign in to comment.