MCPcopy Index your code
hub / github.com/ccoVeille/go-safecast

github.com/ccoVeille/go-safecast @v2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.1 ↗ · + Follow
87 symbols 178 edges 12 files 23 documented · 26% 15 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

package safecast_test

import ( "fmt"

"github.com/ccoveille/go-safecast/v2"

)

func Example() { var a int64

a = 42
b, err := safecast.Convert[int16](a) // everything is fine because 42 fits in int16
if err != nil {
    fmt.Println(err)
}
fmt.Println(b)

a = 255 + 1
_, err = safecast.Convert[uint8](a) // 256 is greater than uint8 maximum value
if err != nil {
    fmt.Println(err)
}

a = -1
_, err = safecast.Convert[uint64](a) // -1 cannot fit in uint64
if err != nil {
    fmt.Println(err)
}

str := "\x99" // ASCII code 153 for Trademark symbol
e := str[0]
_, err = safecast.Convert[int8](e)
if err != nil {
    fmt.Println(err)
}

// Output:
// 42
// conversion issue: 256 (int64) is greater than 255 (uint8): maximum value for this type exceeded
// conversion issue: -1 (int64) is less than 0 (uint64): minimum value for this type exceeded
// conversion issue: 153 (uint8) is greater than 127 (int8): maximum value for this type exceeded

}

Extension points exported contracts — how you extend this code

TestingT (Interface)
TestingT is an interface wrapper used by [RequireConvert] that we need for testing purposes. Only the methods used by [ [2 …
conversion.go
Number (Interface)
Number is a constraint for all integers and floats
types.go
ParseOption (FuncType)
ParseOption defines options for the [Parse] function. Use one of the provided option functions to set the desired behav
parse.go
TestRunner (Interface)
(no doc)
asserters_test.go
ConvertOption (FuncType)
ConvertOption is a function type used to set options for the [Convert] function.
conversion.go

Core symbols most depended-on inside this repo

Run
called by 77
asserters_test.go
Helper
called by 17
conversion.go
Fatal
called by 7
conversion.go
Error
called by 3
errors.go
isNegative
called by 2
types.go
sameSign
called by 1
types.go
newConvertOptions
called by 1
conversion.go
newParseOptions
called by 1
parse.go

Shape

Function 53
Method 16
Struct 11
Interface 3
FuncType 2
TypeAlias 2

Languages

Go100%

Modules by API surface

parse_test.go16 symbols
conversion_test.go15 symbols
parse.go13 symbols
asserters_test.go13 symbols
conversion.go11 symbols
types.go10 symbols
types_test.go3 symbols
errors.go3 symbols
readme_test.go1 symbols
examples_test.go1 symbols
conversion_64bit_test.go1 symbols

For agents

$ claude mcp add go-safecast \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page