MCPcopy Index your code
hub / github.com/AlekSi/pointer / Example

Function Example

pointer_test.go:547–570  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

545}
546
547func Example() {
548 const (
549 defaultName = "some name"
550 )
551
552 // Stuff contains optional fields.
553 type Stuff struct {
554 Name *string
555 Comment *string
556 Value *int64
557 Time *time.Time
558 }
559
560 b, _ := json.Marshal(&Stuff{
561 Name: ToString(defaultName), // can't say &defaultName
562 Comment: ToString("not yet"), // can't say &"not yet"
563 Value: ToInt64(42), // can't say &42 or &int64(42)
564 Time: ToTime(time.Date(2014, 6, 25, 12, 24, 40, 0, time.UTC)), // can't say &time.Date(…)
565 })
566
567 fmt.Printf("%s", b)
568
569 // Output: {"Name":"some name","Comment":"not yet","Value":42,"Time":"2014-06-25T12:24:40Z"}
570}

Callers

nothing calls this directly

Calls 3

ToStringFunction · 0.85
ToInt64Function · 0.85
ToTimeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…