-
Notifications
You must be signed in to change notification settings - Fork 4
/
response_options.go
75 lines (66 loc) · 1.94 KB
/
response_options.go
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
// Copyright (c) Jim Lambert
// SPDX-License-Identifier: MIT
package gldap
type responseOptions struct {
withDiagnosticMessage string
withMatchedDN string
withResponseCode *int
withApplicationCode *int
withAttributes map[string][]string
}
func responseDefaults() responseOptions {
return responseOptions{
withMatchedDN: "Unused",
withDiagnosticMessage: "Unused",
}
}
func getResponseOpts(opt ...Option) responseOptions {
opts := responseDefaults()
applyOpts(&opts, opt...)
return opts
}
// WithDiagnosticMessage provides an optional diagnostic message for the
// response.
func WithDiagnosticMessage(msg string) Option {
return func(o interface{}) {
if o, ok := o.(*responseOptions); ok {
o.withDiagnosticMessage = msg
}
}
}
// WithMatchedDN provides an optional match DN for the response.
func WithMatchedDN(dn string) Option {
return func(o interface{}) {
if o, ok := o.(*responseOptions); ok {
o.withMatchedDN = dn
}
}
}
// WithResponseCode specifies the ldap response code. For a list of valid codes
// see:
// https://github.com/go-ldap/ldap/blob/13008e4c5260d08625b65eb1f172ae909152b751/v3/error.go#L11
func WithResponseCode(code int) Option {
return func(o interface{}) {
if o, ok := o.(*responseOptions); ok {
o.withResponseCode = &code
}
}
}
// WithApplicationCode specifies the ldap application code. For a list of valid codes
// for a list of supported application codes see:
// https://github.com/jimlambrt/gldap/blob/8f171b8eb659c76019719382c4daf519dd1281e6/codes.go#L159
func WithApplicationCode(applicationCode int) Option {
return func(o interface{}) {
if o, ok := o.(*responseOptions); ok {
o.withApplicationCode = &applicationCode
}
}
}
// WithAttributes specifies optional attributes for a response entry
func WithAttributes(attributes map[string][]string) Option {
return func(o interface{}) {
if o, ok := o.(*responseOptions); ok {
o.withAttributes = attributes
}
}
}