Last active
February 3, 2026 20:19
-
-
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/abc114295fbab3c2f6cbf6457c75c468f842d96a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*?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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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