---
title: "Discussion on \"Go Tricks - unpack slice to struct fields\" | Hashnode"
description: "Discussion on \"Go Tricks - unpack slice to struct fields\". Use reflect, in this example, we only show to unpack an int slice to a struct whose fields are all int type.\npackage main\n\nimport (\n    \"errors\"\n    \"fmt\"\n    \"reflect\"\n)\n\ntype Location struct {\n    X int\n    Y int\n    Z int\n}\n\nfunc (loc Location) St..."
url: "https://hashnode.com/posts/go-tricks-unpack-slice-to-struct-fields/6081efe6ff5fc65284a76e9e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Go Tricks - unpack slice to struct fields](https://hn.0xbf.me/go-tricks-unpack-slice-to-struct-fields?utm_source=hashnode&utm_medium=feed)

Use reflect, in this example, we only show to unpack an int slice to a struct whose fields are all int type. package main import ( "errors" "fmt" "reflect" ) type Location struct { X int Y int Z int } func (loc Location) St...

Apr 22, 2021 · 1 min read · hn.0xbf.me  
Read the article

-   [#go](https://hashnode.com/tag/go)

## Written by

[0xBF](https://hashnode.com/@0xbf)

@0xbf

  
[View profile](https://hashnode.com/@0xbf)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
