From 9d25f4bf926a4cb1ad29ab25824f4d70f97d34dd Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Wed, 27 May 2020 12:12:30 +0200 Subject: [PATCH] Initial commit --- LICENSE | 201 ++++++++++++++++++++++++++++ README.md | 65 +++++++++ generator/generator.go | 73 +++++++++++ go.mod | 5 + go.sum | 10 ++ must.go | 57 ++++++++ must_test.go | 73 +++++++++++ types_gen.go | 292 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 776 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 generator/generator.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 must.go create mode 100644 must_test.go create mode 100644 types_gen.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d16188 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# Go library to shorten handling of impossible conditions + + must.OK(os.Unsetenv("FOO")) + bs := must.Bytes(json.Marshal(dataStructureDefinedInCode)) + defer must.Do(f.Close) + +is + + if err := os.Unsetenv("FOO"); err != nil { + panic(err) + } + bs, err := json.Marshal(dataStructureDefinedInCode) + if err != nil { + panic(err) + } + defer func() { + if err := f.Close(); err != nil{ + panic(err) + } + }() + +## Why panic? + +Go error handling style is practical for majority of errors. However not all +errors are meaningful and actionable by the caller, so it does not make sense to +surface them. + +Go tacitly acknowledges it by providing functions `regex.MustCompile` and +`template.Must` in the standard library. This library expands on the same idea. + +## Where is it useful? + +The library is proven to be useful in the following situations: + +- Programming errors in all kinds of code, similar to `regex.MustCompile`, +- Filesystem-related errors in a build system, +- Fatal errors in server-side SaaS code. + +The last point needs an explanation. + +Unlike CLI tools where errors ought to be handled in a way meaningful to a user +who might not know the internals of the application, server-side SaaS +applications are run by the SREs or developers who do not need the extra +wrapping, and instead require fatal errors to be delivered reliably and with all +gory details. + +Passing errors up the stack in a regular Go way risks losing the error (by +forgetting to wrap it, or by swallowing it completely), and prevents the +original stacktrace from being surfaced. `panic`ing at the place of fatal error +is reliable and precise. + +## Is it a good idea to use `must` everywhere? + +Definitely not. Go rules for error handling are well thought-out. Reserve `must` +for programming errors and impossible conditions. + +## Legal + +Copyright Tectonic Networks, Inc. + +Licensed under [Apache 2.0](LICENSE) license. + +Authors: +- [Mikhail Gusarov](https://github.com/dottedmag) +- [Alexey Feldgendler](https://github.com/feldgendler) diff --git a/generator/generator.go b/generator/generator.go new file mode 100644 index 0000000..0db1a52 --- /dev/null +++ b/generator/generator.go @@ -0,0 +1,73 @@ +package main + +import ( + "fmt" + "os" + "strings" +) + +func genFunc(fh *os.File, name, typ string) { + if name == "" { + if strings.HasPrefix(typ, "[]") { + name = strings.Title(typ[2:]) + "s" + } else { + name = strings.Title(typ) + } + } + fmt.Fprintf(fh, ` +// %s panics on error, returns the first argument otherwise +func %s(arg %s, err error) %s { + OK(err) + return arg +} +`, name, name, typ, typ) +} + +func genFuncs(fh *os.File, typ string) { + genFunc(fh, "", typ) + genFunc(fh, "", "[]"+typ) +} + +func main() { + if len(os.Args) != 2 { + fmt.Fprintf(os.Stderr, "Usage: generator \n") + os.Exit(2) + } + fh, err := os.OpenFile(os.Args[1], os.O_WRONLY|os.O_CREATE, 0o644) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to open file for writing: %v\n", err) + os.Exit(1) + } + defer fh.Close() + + fmt.Fprint(fh, `// Code generated by github.com/ridge/must/generator. DO NOT EDIT. + +package must + +import ( + "io" + "net" + "os" + "net/url" +) +`) + + for _, size := range []string{"8", "16", "32", "64", ""} { + genFuncs(fh, "uint"+size) + genFuncs(fh, "int"+size) + } + for _, typ := range []string{"bool", "float32", "float64", + "complex64", "complex128", "byte", "rune", "uintptr", + "string"} { + genFuncs(fh, typ) + } + genFunc(fh, "Any", "interface{}") + genFunc(fh, "OSFile", "*os.File") + genFunc(fh, "OSFileInfo", "os.FileInfo") + genFunc(fh, "OSFileInfos", "[]os.FileInfo") + genFunc(fh, "IOReadCloser", "io.ReadCloser") + genFunc(fh, "IOWriter", "io.Writer") + genFunc(fh, "NetIP", "net.IP") + genFunc(fh, "NetListener", "net.Listener") + genFunc(fh, "NetURL", "url.URL") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6aa794b --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/ridge/must + +go 1.14 + +require github.com/stretchr/testify v1.5.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a80206a --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/must.go b/must.go new file mode 100644 index 0000000..4685d50 --- /dev/null +++ b/must.go @@ -0,0 +1,57 @@ +// Package must is a library to shorten handling of impossible conditions +// +// must.OK(os.Unsetenv("FOO")) +// bytes := must.Bytes(json.Marshal(dataStructureDefinedInCode)) +// defer must.Do(f.Close) +// +// is +// +// if err := os.Unsetenv("FOO"); err != nil { +// panic(err) +// } +// +// bytes, err := json.Marshal(dataStructureDefinedInCode) +// if err != nil { +// panic(err) +// } +// +// defer func() { +// if err := f.Close(); err != nil{ +// panic(err) +// } +// }() +// +// Go error handling style is practical for majority of errors. However not all +// errors are meaningful and actionable by the caller, so it does not make sense +// to surface them. +// +// Go tacitly acknowledges it by providing functions regex.MustCompile and +// template.Must in the standard library. This library expands on the same idea. +// +package must + +//go:generate go run ./generator types_gen.go + +// OK panics on error +func OK(err error) { + if err != nil { + panic(err) + } +} + +// Do calls the function and panics on error +// +// For use primarily in defer statements. +// +// BAD example: +// +// // f.Close will be called now, must.OK will be called on function exit +// defer must.OK(f.Close()) +// +// GOOD example: +// +// defer must.Do(f.Close) +// +func Do(fn func() error) { + OK(fn()) +} diff --git a/must_test.go b/must_test.go new file mode 100644 index 0000000..4755de3 --- /dev/null +++ b/must_test.go @@ -0,0 +1,73 @@ +package must + +import ( + "errors" + "os" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestOK(t *testing.T) { + e := errors.New("") + assert.PanicsWithValue(t, e, func() { OK(e) }) + assert.NotPanics(t, func() { OK(nil) }) +} + +func TestDo(t *testing.T) { + e := errors.New("") + assert.PanicsWithValue(t, e, func() { + Do(func() error { + return e + }) + }) + assert.NotPanics(t, func() { + Do(func() error { + return nil + }) + }) +} + +func TestInt(t *testing.T) { + e := errors.New("") + assert.PanicsWithValue(t, e, func() { Int(10, e) }) + assert.Equal(t, 10, Int(10, nil)) +} + +type fakeFileInfo struct { +} + +func (fakeFileInfo) Name() string { + return "" +} + +func (fakeFileInfo) Size() int64 { + return 0 +} + +func (fakeFileInfo) Mode() os.FileMode { + return 0 +} + +func (fakeFileInfo) ModTime() time.Time { + return time.Time{} +} + +func (fakeFileInfo) IsDir() bool { + return false +} + +func (fakeFileInfo) Sys() interface{} { + return nil +} + +func TestOSFileInfos(t *testing.T) { + e := errors.New("") + fis := []os.FileInfo{fakeFileInfo{}} + + assert.PanicsWithValue(t, e, func() { + OSFileInfos(fis, e) + }) + assert.Equal(t, fis, OSFileInfos(fis, nil)) +} diff --git a/types_gen.go b/types_gen.go new file mode 100644 index 0000000..79161b4 --- /dev/null +++ b/types_gen.go @@ -0,0 +1,292 @@ +// Code generated by github.com/ridge/must/generator. DO NOT EDIT. + +package must + +import ( + "io" + "net" + "os" + "net/url" +) + +// Uint8 panics on error, returns the first argument otherwise +func Uint8(arg uint8, err error) uint8 { + OK(err) + return arg +} + +// Uint8s panics on error, returns the first argument otherwise +func Uint8s(arg []uint8, err error) []uint8 { + OK(err) + return arg +} + +// Int8 panics on error, returns the first argument otherwise +func Int8(arg int8, err error) int8 { + OK(err) + return arg +} + +// Int8s panics on error, returns the first argument otherwise +func Int8s(arg []int8, err error) []int8 { + OK(err) + return arg +} + +// Uint16 panics on error, returns the first argument otherwise +func Uint16(arg uint16, err error) uint16 { + OK(err) + return arg +} + +// Uint16s panics on error, returns the first argument otherwise +func Uint16s(arg []uint16, err error) []uint16 { + OK(err) + return arg +} + +// Int16 panics on error, returns the first argument otherwise +func Int16(arg int16, err error) int16 { + OK(err) + return arg +} + +// Int16s panics on error, returns the first argument otherwise +func Int16s(arg []int16, err error) []int16 { + OK(err) + return arg +} + +// Uint32 panics on error, returns the first argument otherwise +func Uint32(arg uint32, err error) uint32 { + OK(err) + return arg +} + +// Uint32s panics on error, returns the first argument otherwise +func Uint32s(arg []uint32, err error) []uint32 { + OK(err) + return arg +} + +// Int32 panics on error, returns the first argument otherwise +func Int32(arg int32, err error) int32 { + OK(err) + return arg +} + +// Int32s panics on error, returns the first argument otherwise +func Int32s(arg []int32, err error) []int32 { + OK(err) + return arg +} + +// Uint64 panics on error, returns the first argument otherwise +func Uint64(arg uint64, err error) uint64 { + OK(err) + return arg +} + +// Uint64s panics on error, returns the first argument otherwise +func Uint64s(arg []uint64, err error) []uint64 { + OK(err) + return arg +} + +// Int64 panics on error, returns the first argument otherwise +func Int64(arg int64, err error) int64 { + OK(err) + return arg +} + +// Int64s panics on error, returns the first argument otherwise +func Int64s(arg []int64, err error) []int64 { + OK(err) + return arg +} + +// Uint panics on error, returns the first argument otherwise +func Uint(arg uint, err error) uint { + OK(err) + return arg +} + +// Uints panics on error, returns the first argument otherwise +func Uints(arg []uint, err error) []uint { + OK(err) + return arg +} + +// Int panics on error, returns the first argument otherwise +func Int(arg int, err error) int { + OK(err) + return arg +} + +// Ints panics on error, returns the first argument otherwise +func Ints(arg []int, err error) []int { + OK(err) + return arg +} + +// Bool panics on error, returns the first argument otherwise +func Bool(arg bool, err error) bool { + OK(err) + return arg +} + +// Bools panics on error, returns the first argument otherwise +func Bools(arg []bool, err error) []bool { + OK(err) + return arg +} + +// Float32 panics on error, returns the first argument otherwise +func Float32(arg float32, err error) float32 { + OK(err) + return arg +} + +// Float32s panics on error, returns the first argument otherwise +func Float32s(arg []float32, err error) []float32 { + OK(err) + return arg +} + +// Float64 panics on error, returns the first argument otherwise +func Float64(arg float64, err error) float64 { + OK(err) + return arg +} + +// Float64s panics on error, returns the first argument otherwise +func Float64s(arg []float64, err error) []float64 { + OK(err) + return arg +} + +// Complex64 panics on error, returns the first argument otherwise +func Complex64(arg complex64, err error) complex64 { + OK(err) + return arg +} + +// Complex64s panics on error, returns the first argument otherwise +func Complex64s(arg []complex64, err error) []complex64 { + OK(err) + return arg +} + +// Complex128 panics on error, returns the first argument otherwise +func Complex128(arg complex128, err error) complex128 { + OK(err) + return arg +} + +// Complex128s panics on error, returns the first argument otherwise +func Complex128s(arg []complex128, err error) []complex128 { + OK(err) + return arg +} + +// Byte panics on error, returns the first argument otherwise +func Byte(arg byte, err error) byte { + OK(err) + return arg +} + +// Bytes panics on error, returns the first argument otherwise +func Bytes(arg []byte, err error) []byte { + OK(err) + return arg +} + +// Rune panics on error, returns the first argument otherwise +func Rune(arg rune, err error) rune { + OK(err) + return arg +} + +// Runes panics on error, returns the first argument otherwise +func Runes(arg []rune, err error) []rune { + OK(err) + return arg +} + +// Uintptr panics on error, returns the first argument otherwise +func Uintptr(arg uintptr, err error) uintptr { + OK(err) + return arg +} + +// Uintptrs panics on error, returns the first argument otherwise +func Uintptrs(arg []uintptr, err error) []uintptr { + OK(err) + return arg +} + +// String panics on error, returns the first argument otherwise +func String(arg string, err error) string { + OK(err) + return arg +} + +// Strings panics on error, returns the first argument otherwise +func Strings(arg []string, err error) []string { + OK(err) + return arg +} + +// Any panics on error, returns the first argument otherwise +func Any(arg interface{}, err error) interface{} { + OK(err) + return arg +} + +// OSFile panics on error, returns the first argument otherwise +func OSFile(arg *os.File, err error) *os.File { + OK(err) + return arg +} + +// OSFileInfo panics on error, returns the first argument otherwise +func OSFileInfo(arg os.FileInfo, err error) os.FileInfo { + OK(err) + return arg +} + +// OSFileInfos panics on error, returns the first argument otherwise +func OSFileInfos(arg []os.FileInfo, err error) []os.FileInfo { + OK(err) + return arg +} + +// IOReadCloser panics on error, returns the first argument otherwise +func IOReadCloser(arg io.ReadCloser, err error) io.ReadCloser { + OK(err) + return arg +} + +// IOWriter panics on error, returns the first argument otherwise +func IOWriter(arg io.Writer, err error) io.Writer { + OK(err) + return arg +} + +// NetIP panics on error, returns the first argument otherwise +func NetIP(arg net.IP, err error) net.IP { + OK(err) + return arg +} + +// NetListener panics on error, returns the first argument otherwise +func NetListener(arg net.Listener, err error) net.Listener { + OK(err) + return arg +} + +// NetURL panics on error, returns the first argument otherwise +func NetURL(arg url.URL, err error) url.URL { + OK(err) + return arg +}