mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 08:48:37 +00:00
Move ParseBool to optional (#33979)
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
package optional
|
||||
|
||||
import "strconv"
|
||||
|
||||
type Option[T any] []T
|
||||
|
||||
func None[T any]() Option[T] {
|
||||
@@ -43,3 +45,12 @@ func (o Option[T]) ValueOrDefault(v T) T {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// ParseBool get the corresponding optional.Option[bool] of a string using strconv.ParseBool
|
||||
func ParseBool(s string) Option[bool] {
|
||||
v, e := strconv.ParseBool(s)
|
||||
if e != nil {
|
||||
return None[bool]()
|
||||
}
|
||||
return Some(v)
|
||||
}
|
||||
|
Reference in New Issue
Block a user