/
store_userinfo.go
47 lines (37 loc) · 1.21 KB
/
store_userinfo.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
package hit
import "github.com/Eun/go-hit/internal/converter"
// IStoreUserInfo defines the functions that can be used to store a user part.
type IStoreUserInfo interface {
IStoreStep
// Username stores the UserInfo's username
Username() IStoreStep
// Password stores the UserInfo's password
Password() IStoreStep
// String stores the string representation of UserInfo
String() IStoreStep
}
type storeUserInfo struct{}
func newStoreUserInfo() IStoreUserInfo {
return &storeUserInfo{}
}
func (s *storeUserInfo) In(v interface{}) IStep {
return newStoreInStep(func(hit Hit, container interface{}) error {
return converter.Convert(hit.Request().URL.User, container)
}, v)
}
func (s *storeUserInfo) Username() IStoreStep {
return newStoreStep(func(hit Hit, v interface{}) error {
return converter.Convert(hit.Request().URL.User.Username(), v)
})
}
func (s *storeUserInfo) Password() IStoreStep {
return newStoreStep(func(hit Hit, v interface{}) error {
pass, _ := hit.Request().URL.User.Password()
return converter.Convert(pass, v)
})
}
func (s *storeUserInfo) String() IStoreStep {
return newStoreStep(func(hit Hit, v interface{}) error {
return converter.Convert(hit.Request().URL.User.String(), v)
})
}