golang interface to int

type Person struct {
	firstName string
	lastName  string
}
func printIfPerson(object interface{}) {
	person, ok := object.(Person)
	if ok {
		fmt.Printf("Hello %s!\n", person.firstName)
	}
}

5
1
Awgiedawgie 440215 points

                                    iAreaId := val.(int)
iAreaId, ok := val.(int) // Alt. non panicking version 

5 (1 Votes)
0
3.71
7
A-312 69370 points

                                    var myInt interface{}
myInt = 8

toInt, ok := myInt.(int)
fmt.Println(toInt, ok)  // 8 true

toString, ok := myInt.(string)
fmt.Println(toString, ok)  // "" false

3.71 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to convert string to interface in golang type interface to int golang golang convert interface to concrete type interface to uint golang convert value of interface to int64 golang interface value to int golang convert interface to integer : golang declare interface golang how to access interface values in golang golang interface conversion interface is string not int golang typecast interface to int uint to int golang interface to int64 golang how to assign value to an interface in golang i have to return the interface{} in golang create interface golang how to implement golang interface get interface value golang turn interface into actual type golang interface golang golang int to interface golang type to interface golang convert to interface defining interface golang golang implement interface cast interface to int golang convert string to interface golang interface in golang golang interface type to int how to type an interface golang convert interface golang declare interface with value golang string to interface golang convert empty interface to int64 interface to int interface golang interface to int interface to int golang golang how to cast interface to a type convert interface to int golang int64 to int golang convert types interface {} to int create interface conversion golang creates interface conversion golang golang converts interface golang interface to float64 interface conversion error golang convert interface to int how to cast interface to type cast interface to type golang go interface to int golang type cast interface convert interface to type golang golang type conversion interface golang casting interface to type convert interface to type cast interface golagn golang convert type interface to int golang interface{} to int golang casting interface golang cast interface to float go lang interface to int interface conversion check
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source