From 22be5f9c794eb7751941854ac52be7045f2f94a5 Mon Sep 17 00:00:00 2001 From: Sameer Ajmani Date: Mon, 23 Feb 2015 10:13:15 -0500 Subject: blog: edits to package-names post. I received a question about whether package functions named "New" were required (they're not), so I'm adding examples of functions named "WithX" and "FromY" to show other useful forms. Change-Id: Iff3ddec3dca3344762f09ba52de9cd515a4bc863 Reviewed-on: https://go-review.googlesource.com/5572 Reviewed-by: Rob Pike --- content/package-names.article | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'content/package-names.article') diff --git a/content/package-names.article b/content/package-names.article index 0f95a5b..4ecc057 100644 --- a/content/package-names.article +++ b/content/package-names.article @@ -84,8 +84,10 @@ Client code refers to this type as `http.Server`, so there is no ambiguity. When a function in package pkg returns a value of type `pkg.Pkg` (or `*pkg.Pkg`), the function name can often omit the type name without confusion: - start := time.Now() // start is a time.Time - t, err := time.Parse(time.Kitchen, "6:06PM") // t is a time.Time + start := time.Now() // start is a time.Time + t, err := time.Parse(time.Kitchen, "6:06PM") // t is a time.Time + ctx = context.WithTimeout(ctx, 10*time.Millisecond) // ctx is a context.Context + ip, ok := userip.FromContext(ctx) // ip is a net.IP A function named `New` in package `pkg` returns a value of type `pkg.Pkg`. This is a standard entry point for client code using that type: -- cgit v1.2.3