-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Convert capitalization to TextVar flag
- Loading branch information
Showing
4 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cmd/update-plex-ipv6-access-url/internal/handler/capitalization.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type IPv6URLCapitalization string | ||
|
||
const ( | ||
IPv6URLCapitalizationLower IPv6URLCapitalization = "lower" | ||
IPv6URLCapitalizationUpper IPv6URLCapitalization = "upper" | ||
) | ||
|
||
//goland:noinspection GoMixedReceiverTypes | ||
func (c IPv6URLCapitalization) String() string { | ||
return string(c) | ||
} | ||
|
||
//goland:noinspection GoMixedReceiverTypes | ||
func (c *IPv6URLCapitalization) UnmarshalText(text []byte) error { | ||
if len(text) == 0 { | ||
*c = "" | ||
return nil | ||
} | ||
|
||
s := string(text) | ||
switch s { | ||
case string(IPv6URLCapitalizationLower): | ||
*c = IPv6URLCapitalizationLower | ||
case string(IPv6URLCapitalizationUpper): | ||
*c = IPv6URLCapitalizationUpper | ||
default: | ||
return fmt.Errorf("invalid IPv6 URL capitalization: %s", s) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
//goland:noinspection GoMixedReceiverTypes | ||
func (c IPv6URLCapitalization) MarshalText() (text []byte, err error) { | ||
return []byte(c), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters