Post

GoLangGoLang

J
James ROBERT

Posted on 27th June 2022|3338 views

0
votes

Golang Cast Interface To Struct

How to convert interface to struct in Go?

Answers
P
Anusha V

Posted on 27th June 2022

  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