@@ -2,99 +2,131 @@ package uri
22
33// Builder methods
44
5- func (u URI ) WithScheme (scheme string ) URI {
5+ func (u URI ) WithScheme (scheme string , opts ... Option ) URI {
66 if u .Err () != nil {
77 return u
88 }
99
10+ opts = append (opts , withValidationFlags (flagValidateScheme | flagValidateHost ))
11+ o , redeem := applyURIOptions (opts )
12+ defer func () { redeem (o ) }()
13+
1014 u .scheme = scheme
11- u .authority .ipType , u .err = u .validate ()
15+ u .authority .ipType , u .err = u .validate (o )
1216
1317 return u
1418}
1519
16- func (u URI ) WithAuthority (authority Authority ) URI {
20+ func (u URI ) WithAuthority (authority Authority , opts ... Option ) URI {
1721 if u .Err () != nil {
1822 return u
1923 }
2024
25+ opts = append (opts , withValidationFlags (flagValidateHost | flagValidatePort | flagValidateUserInfo | flagValidatePath ))
26+ o , redeem := applyURIOptions (opts )
27+ defer func () { redeem (o ) }()
28+
2129 u .authority = authority
22- u .authority .ipType , u .err = u .validate ()
30+ u .authority .ipType , u .err = u .validate (o )
2331 u .authority .err = u .err
2432
2533 return u
2634}
2735
28- func (u URI ) WithUserInfo (userinfo string ) URI {
36+ func (u URI ) WithUserInfo (userinfo string , opts ... Option ) URI {
2937 if u .Err () != nil {
3038 return u
3139 }
3240
41+ opts = append (opts , withValidationFlags (flagValidateUserInfo ))
42+ o , redeem := applyURIOptions (opts )
43+ defer func () { redeem (o ) }()
44+
3345 u .authority = u .authority .withEnsuredAuthority ()
3446 u .authority .userinfo = userinfo
35- u .authority .ipType , u .err = u .validate ()
47+ u .authority .ipType , u .err = u .validate (o )
3648 u .authority .err = u .err
3749
3850 return u
3951}
4052
41- func (u URI ) WithHost (host string ) URI {
53+ func (u URI ) WithHost (host string , opts ... Option ) URI {
4254 if u .Err () != nil {
4355 return u
4456 }
4557
58+ opts = append (opts , withValidationFlags (flagValidateHost | flagValidatePort ))
59+ o , redeem := applyURIOptions (opts )
60+ defer func () { redeem (o ) }()
61+
4662 u .authority = u .authority .withEnsuredAuthority ()
4763 u .authority .host = host
48- u .authority .ipType , u .err = u .validate ()
64+ u .authority .ipType , u .err = u .validate (o )
4965 u .authority .err = u .err
5066
5167 return u
5268}
5369
54- func (u URI ) WithPort (port string ) URI {
70+ func (u URI ) WithPort (port string , opts ... Option ) URI { // TODO: port as int?
5571 if u .Err () != nil {
5672 return u
5773 }
5874
75+ opts = append (opts , withValidationFlags (flagValidatePort ))
76+ o , redeem := applyURIOptions (opts )
77+ defer func () { redeem (o ) }()
78+
5979 u .authority = u .authority .withEnsuredAuthority ()
6080 u .authority .port = port
61- u .authority .ipType , u .err = u .validate ()
81+ u .authority .ipType , u .err = u .validate (o )
6282 u .authority .err = u .err
6383
6484 return u
6585}
6686
67- func (u URI ) WithPath (path string ) URI {
87+ func (u URI ) WithPath (path string , opts ... Option ) URI {
6888 if u .Err () != nil {
6989 return u
7090 }
7191
92+ opts = append (opts , withValidationFlags (flagValidatePath ))
93+ o , redeem := applyURIOptions (opts )
94+ defer func () { redeem (o ) }()
95+
7296 u .authority = u .authority .withEnsuredAuthority ()
7397 u .authority .path = path
74- u .authority .ipType , u .err = u .validate ()
98+ u .authority .ipType , u .err = u .validate (o )
7599 u .authority .err = u .err
76100
77101 return u
78102}
79103
80- func (u URI ) WithQuery (query string ) URI {
104+ func (u URI ) WithQuery (query string , opts ... Option ) URI {
81105 if u .Err () != nil {
82106 return u
83107 }
84108
109+ opts = append (opts , withValidationFlags (flagValidateQuery ))
110+ o , redeem := applyURIOptions (opts )
111+ defer func () { redeem (o ) }()
112+
85113 u .query = query
86- u .authority .ipType , u .err = u .validate ()
114+ u .authority .ipType , u .err = u .validate (o )
87115
88116 return u
89117}
90118
91- func (u URI ) WithFragment (fragment string ) URI {
119+ func (u URI ) WithFragment (fragment string , opts ... Option ) URI {
92120 if u .Err () != nil {
93121 return u
94122 }
95123
124+ opts = append (opts , withValidationFlags (flagValidateFragment ))
125+ o , redeem := applyURIOptions (opts )
126+ defer func () { redeem (o ) }()
127+
96128 u .fragment = fragment
97- u .authority .ipType , u .err = u .validate ()
129+ u .authority .ipType , u .err = u .validate (o )
98130
99131 return u
100132}
0 commit comments