logo-MindMajix
PostGoLangGoLang
J
James ROBERT

Posted on 25th July 2024|16718 views

0
votes

Golang Cast Interface To Struct

How to convert interface to struct in Go?

1 answers
Answers
P
Anusha V

Posted on 25th July 2024| views

  1. The interface object can be converted to struct through the below code:

 

Type person1 struct {
 Username string
 Lastname string
 }
 Func printIfperson1(object interface{}) {
 person1, ok:= object. (Person1)
 If ok {
  fmt.printf(“Hello %s ! \n” person1.username)
 }
 }

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number