Skip to content

Commit

Permalink
Try to implement gorm custom data type
Browse files Browse the repository at this point in the history
  • Loading branch information
YummYume committed May 4, 2024
1 parent 8af5006 commit 4a49c2b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/enum/stratagem_keys.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package enum

import (
"database/sql/driver"
"fmt"
)

type StratagemKeys string

const (
Expand All @@ -8,3 +13,28 @@ const (
Down StratagemKeys = "down"
Left StratagemKeys = "left"
)

func (stratagemKey *StratagemKeys) Scan(value interface{}) error {
if value == nil {
return nil
}

switch value {
case "up":
*stratagemKey = Up
case "right":
*stratagemKey = Right
case "down":
*stratagemKey = Down
case "left":
*stratagemKey = Left
default:
return fmt.Errorf("invalid value for StratagemKeys: %v", value)
}

return nil
}

func (stratagemKey StratagemKeys) Value() (driver.Value, error) {
return string(stratagemKey), nil
}
2 changes: 2 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpC
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down

0 comments on commit 4a49c2b

Please sign in to comment.