Skip to content

Commit

Permalink
PC-9797: Implement marshaler on our own (#80)
Browse files Browse the repository at this point in the history
* implement marshaler on our own

* remove files
  • Loading branch information
nieomylnieja authored Jul 20, 2023
1 parent 70fbe10 commit be58eb6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 18 additions & 1 deletion manifest/kind.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package manifest

//go:generate ../bin/go-enum --nocase --lower --names --marshal --values
//go:generate ../bin/go-enum --nocase --lower --names --values

import "strings"

Expand Down Expand Up @@ -50,3 +50,20 @@ func ApplicableKinds() []Kind {
}
return applicable
}

// MarshalText implements the text encoding.TextMarshaler interface.
func (k Kind) MarshalText() ([]byte, error) {
return []byte(k.String()), nil
}

// UnmarshalText implements the text encoding.TextUnmarshaler interface.
func (k *Kind) UnmarshalText(text []byte) error {
tmp, err := ParseKind(string(text))
// We cannot fail here as we often use a partial representation of our objects.
// For instance, embedding AlertMethod inside AlertPolicy.
if err != nil {
tmp = 0
}
*k = tmp
return nil
}
16 changes: 0 additions & 16 deletions manifest/kind_enum.go

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

0 comments on commit be58eb6

Please sign in to comment.