mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 04:09:29 +02:00
Move ParseBool to optional (#33979)
(cherry picked from commit 25b6f388651c893ecafce918f27bef7e4ae9a967)
This commit is contained in:
parent
9018e5bc19
commit
f68d49cb9e
6 changed files with 31 additions and 33 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue