Cast is a Go library that provides easy and safe conversion (casting) between different types in Go programs. Especially when dealing with interface{} or dynamic/reflect-heavy code, it becomes cumbersome to assert types or convert values reliably; cast addresses that by offering a suite of functions to convert from any input to the target type with predictable behaviour. Rather than relying purely on raw type assertions, it offers ToInt, ToString, ToBool, ToTime, etc., and their “error-returning” counterparts like ToIntE. It is particularly useful when dealing with data from YAML, TOML, JSON or other formats where the type can be uncertain. The design choice is to avoid guessing about conversions: e.g., only a string strictly representing an integer can convert to int. The library is mature, tested, and widely used—thus ideal for projects that must handle dynamic input gracefully.

Features

  • Functions like ToInt, ToFloat64, ToString to convert arbitrary values
  • Error-returning variants (e.g., ToIntE) to detect failed conversions
  • Support for slices (e.g., ToStringSlice, ToFloat64Slice) and maps (ToStringMap)
  • Strict conversion semantics: only obvious conversions allowed
  • Works well with dynamic data sources (JSON/YAML/TOML) where types are uncertain
  • Generics and type-alias support in recent versions to streamline usage

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

MIT License

Follow cast

cast Web Site

Other Useful Business Software
Iris Powered By Generali - Iris puts your customer in control of their identity. Icon
Iris Powered By Generali - Iris puts your customer in control of their identity.

Increase customer and employee retention by offering Onwatch identity protection today.

Iris Identity Protection API sends identity monitoring and alerts data into your existing digital environment – an ideal solution for businesses that are looking to offer their customers identity protection services without having to build a new product or app from scratch.
Learn More
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of cast!

Additional Project Details

Programming Language

Go

Related Categories

Go Libraries

Registered

2025-10-28