Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2025 09:02
Show Gist options
  • Save dacr/4045d6562d8c291dd3ab628ecb43eedd to your computer and use it in GitHub Desktop.
Save dacr/4045d6562d8c291dd3ab628ecb43eedd to your computer and use it in GitHub Desktop.
go casts and conversions / published by https://github.com/dacr/code-examples-manager #53641fce-d636-4b1b-b4b4-78a6c5f95133/79251b5ebfba9df81e10390f5f57ec4593f363d2
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go casts and conversions
// keywords : go, casts, conversions, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 53641fce-d636-4b1b-b4b4-78a6c5f95133
// created-on : 2025-03-27T14:06:42+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : nix-shell -p go --run "go run $file"
package main
import "fmt"
type person struct {
name string
}
func main() {
var toto int64 = 42
titi := int(toto)
tutu := float64(toto)
fmt.Println(toto, titi, tutu)
joe := person{"Joe"}
fmt.Println(joe)
var something any = joe
newJoe := something.(person)
fmt.Println(newJoe)
_, ok := something.(fmt.Stringer)
if !ok {
fmt.Println("Not a stringer !!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment