gin-blog/pkg/convert/convert.go
2021-05-28 18:41:12 +08:00

30 lines
432 B
Go

package convert
import "strconv"
type StrTo string
func (s StrTo) String() string {
return string(s)
}
func (s StrTo) Int() (int, error) {
v, err := strconv.Atoi(s.String())
return v, err
}
func (s StrTo) MustInt() int {
v, _ := s.Int()
return v
}
func (s StrTo) UInt32() (uint32, error) {
v, err := strconv.Atoi(s.String())
return uint32(v), err
}
func (s StrTo) MustUInt32() uint32 {
v, _ := s.UInt32()
return v
}