cast

package module
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 4 Imported by: 7

README

GoDoc CI CodeQL Go Report Card Coverage Status

Cast

GoLobby Cast is a lightweight casting package for Go projects.

Documentation

Required Go Versions

It requires Go v1.16 or newer versions.

Installation

To install this package, run the following command in your project directory.

go get github.com/golobby/cast
Usage Example

The following examples demonstrate how to use the GoLobby Cast package.

val, err := cast.FromString("666", "int32")
// `val` type: int32
// `val` value: 666
val, err := cast.FromString("1", cast.Bool)
// `val` type: bool
// `val` value: true
Supported Types

Currently, the GoLobby Cast supports the following types and related array types:

  • Int (Int8 .. Int64)
  • Uint (Uint8 .. Uint64)
  • Float32 and Float64
  • Bool
  • String

License

GoLobby Cast is released under the MIT License.

Documentation

Overview

Package cast is a lightweight casting (type conversion) library.

Index

Constants

View Source
const (
	Uint8  = "uint8"
	Uint16 = "uint16"
	Uint32 = "uint32"
	Uint64 = "uint64"
	Uint   = "uint"

	Int8  = "int8"
	Int16 = "int16"
	Int32 = "int32"
	Int64 = "int64"
	Int   = "int"

	Float32 = "float32"
	Float64 = "float64"

	Bool = "bool"

	String = "string"
)

Variables

This section is empty.

Functions

func FromString

func FromString(value string, targetType string) (interface{}, error)

FromString casts a string value to the given type name.

func FromType added in v1.3.0

func FromType(value string, targetType reflect.Type) (interface{}, error)

FromType casts a string value to the given reflected type.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL