Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stringer for static type conversions #688

Merged
merged 6 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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