cvt
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Go type conversion

PkgGoDev Go Report Card Build Status codecov GitHub Mentioned in Awesome Go

Simple, safe conversion of any type, including indirect/custom types.

Getting Started

Feature overview

Safety

Support to any data type, no panic, safe with application.

Lightweight

Less code, zero depend, the application almost no heavy burden.

Easily

Semantic clarity, naming, documentation, detailed, directly get started.

Examples

cvt.IntE("12")          // 12, nil
cvt.Float64E("12.34")   // 12.34, nil
cvt.StringE(12.34)      // "12.34", nil
cvt.BoolE("false")      // false, nil
cvt.Int("12")           // 12(success)
cvt.Int(struct{}{})     // 0(failed)
cvt.Int(struct{}{}, 12)     // 12
cvt.Float("hello", 12.34)   // 12.34
type Name string

var name Name = "jioby"

cvt.StringE(name)       // jioby, nil
var name = "jioby"

cvt.StringE(&name)       // jioby, nil
cvt.BoolP("true")   // (*bool)(0x14000126180)(true)