File: require.go

package info (click to toggle)
golang-github-spiffe-go-spiffe 2.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,116 kB
  • sloc: makefile: 157
file content (103 lines) | stat: -rw-r--r-- 3,413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package spiffeid

import (
	"net/url"
)

// RequireFromPath is similar to FromPath except that instead of returning an
// error on malformed input, it panics. It should only be used when the input
// is statically verifiable.
func RequireFromPath(td TrustDomain, path string) ID {
	id, err := FromPath(td, path)
	panicOnErr(err)
	return id
}

// RequireFromPathf is similar to FromPathf except that instead of returning an
// error on malformed input, it panics. It should only be used when the input
// is statically verifiable.
func RequireFromPathf(td TrustDomain, format string, args ...interface{}) ID {
	id, err := FromPathf(td, format, args...)
	panicOnErr(err)
	return id
}

// RequireFromSegments is similar to FromSegments except that instead of
// returning an error on malformed input, it panics. It should only be used
// when the input is statically verifiable.
func RequireFromSegments(td TrustDomain, segments ...string) ID {
	id, err := FromSegments(td, segments...)
	panicOnErr(err)
	return id
}

// RequireFromString is similar to FromString except that instead of returning
// an error on malformed input, it panics. It should only be used when the
// input is statically verifiable.
func RequireFromString(s string) ID {
	id, err := FromString(s)
	panicOnErr(err)
	return id
}

// RequireFromStringf is similar to FromStringf except that instead of
// returning an error on malformed input, it panics. It should only be used
// when the input is statically verifiable.
func RequireFromStringf(format string, args ...interface{}) ID {
	id, err := FromStringf(format, args...)
	panicOnErr(err)
	return id
}

// RequireFromURI is similar to FromURI except that instead of returning an
// error on malformed input, it panics. It should only be used when the input is
// statically verifiable.
func RequireFromURI(uri *url.URL) ID {
	id, err := FromURI(uri)
	panicOnErr(err)
	return id
}

// RequireTrustDomainFromString is similar to TrustDomainFromString except that
// instead of returning an error on malformed input, it panics. It should only
// be used when the input is statically verifiable.
func RequireTrustDomainFromString(s string) TrustDomain {
	td, err := TrustDomainFromString(s)
	panicOnErr(err)
	return td
}

// RequireTrustDomainFromURI is similar to TrustDomainFromURI except that
// instead of returning an error on malformed input, it panics. It should only
// be used when the input is statically verifiable.
func RequireTrustDomainFromURI(uri *url.URL) TrustDomain {
	td, err := TrustDomainFromURI(uri)
	panicOnErr(err)
	return td
}

// RequireFormatPath builds a path by formatting the given formatting string
// with the given args (i.e. fmt.Sprintf). The resulting path must be valid or
// the function panics. It should only be used when the input is statically
// verifiable.
func RequireFormatPath(format string, args ...interface{}) string {
	path, err := FormatPath(format, args...)
	panicOnErr(err)
	return path
}

// RequireJoinPathSegments joins one or more path segments into a slash separated
// path. Segments cannot contain slashes. The resulting path must be valid or
// the function panics. It should only be used when the input is statically
// verifiable.
func RequireJoinPathSegments(segments ...string) string {
	path, err := JoinPathSegments(segments...)
	panicOnErr(err)
	return path
}

func panicOnErr(err error) {
	if err != nil {
		panic(err)
	}
}