Exercises Stringer Interface

Exercises

https://go.dev/play/p/aAx_HL7aGu1

package main

import "fmt"

type user struct {
    name  string
    email string
}

// Implement custom formating for user struct values.
// /usr/local/Cellar/go/1.17.5/libexec/src/fmt/print.go
// type Stringer interface {
//     String() string
// }
func (u user) String() string {
    return fmt.Sprintf("%s <%s>", u.name, u.email)
}

func main() {
    u := user{
        name:  "John Doe",
        email: "johndoe@example.com",
    }
    fmt.Println(u)
}
© Kimi Tsai all right reserved.            Updated : 2023-07-12 09:04:53

results matching ""

    No results matching ""

    results matching ""

      No results matching ""