DEV Community

Carlos Alarcon B
Carlos Alarcon B

Posted on

Using lists in go with structs

This is a basic example in go using container/list and structs.

package main

import "fmt"
import "container/list"

type Person struct {
    name string
    age  int

func main() {

    person1 := Person{"John", 44}
    person2 := Person{"Julia", 22}

    list := list.New()

    // Iterate the list
    for e := list.Front(); e != nil; e = e.Next() {
        itemPerson := Person(e.Value.(Person))


Enter fullscreen mode Exit fullscreen mode

Top comments (1)

renatosuero profile image
Renato Suero

I didn't know the package, thanks to share :)