Skip to content

Instantly share code, notes, and snippets.

@ederavilaprado
Created April 13, 2017 04:51
Show Gist options
  • Select an option

  • Save ederavilaprado/7b4857bd7daf4ff823b19a55a2343875 to your computer and use it in GitHub Desktop.

Select an option

Save ederavilaprado/7b4857bd7daf4ff823b19a55a2343875 to your computer and use it in GitHub Desktop.

Revisions

  1. ederavilaprado created this gist Apr 13, 2017.
    48 changes: 48 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    package main

    import "fmt"

    type Item interface{}

    type Product struct {
    ID int
    Name string
    }

    type CompleteProduct struct {
    Product
    Size int32
    }

    func teste(input Item) {
    fmt.Printf("=> %+v\n", input)

    switch t := input.(type) {
    case Product:
    fmt.Printf("=> Product: %+v\n", t)
    case CompleteProduct:
    fmt.Printf("=> CompletedProduct: %+v\n", t)
    default:
    fmt.Printf("=> %+v\n", "ops")
    }

    }

    func main() {
    // product := Product{
    // ID: 1,
    // Name: "So, ok"
    // }
    p := Product{}
    p.ID = 1
    p.Name = "Teste for name"
    // p.Size = 33

    fmt.Printf("=> %+v\n", p)
    teste(p)

    // item, ok := product.(interface)
    // fmt.Printf("=> ok: %+v\n", ok)
    // fmt.Printf("=> %+v\n", item)

    }