push human readable milestone type

This commit is contained in:
Elio Bischof
2023-06-30 02:53:47 +02:00
parent 39e8e869ac
commit 5cacd0e996
3 changed files with 35 additions and 13 deletions

View File

@@ -2,6 +2,11 @@
package milestone
import (
"fmt"
"strings"
)
type Type int
const (
@@ -24,3 +29,31 @@ func AllTypes() []Type {
}
return types
}
func (t *Type) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, t.String())), nil
}
func (t *Type) UnmarshalJSON(data []byte) error {
*t = typeFromString(strings.Trim(string(data), `"`))
return nil
}
func typeFromString(t string) Type {
switch t {
case InstanceCreated.String():
return InstanceCreated
case AuthenticationSucceededOnInstance.String():
return AuthenticationSucceededOnInstance
case ProjectCreated.String():
return ProjectCreated
case ApplicationCreated.String():
return ApplicationCreated
case AuthenticationSucceededOnApplication.String():
return AuthenticationSucceededOnApplication
case InstanceDeleted.String():
return InstanceDeleted
default:
return unknown
}
}