github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/uri/uri-user_Information.go (about) 1 /* For license and copyright information please see the LEGAL file in the code repository */ 2 3 package uri 4 5 import ( 6 "strings" 7 ) 8 9 // UserInformation store user information part of an URI. 10 // https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1 11 type UserInformation struct { 12 userinfo string // 13 username string // 14 password string // 15 } 16 17 func (u *UserInformation) Init(ui string) { 18 u.userinfo = ui 19 var i = strings.IndexByte(ui, Colon) 20 if i >= 0 { 21 u.username = ui[:i] 22 u.password = ui[i+1:] 23 } else { 24 u.userinfo = ui 25 } 26 } 27 func (u *UserInformation) Reinit() { 28 u.userinfo = "" 29 u.username = "" 30 u.password = "" 31 } 32 func (u *UserInformation) Deinit() {} 33 34 func (u *UserInformation) Userinfo() string { return u.userinfo } 35 func (u *UserInformation) Username() string { return u.username } 36 func (u *UserInformation) Password() string { return u.password } 37 38 func (u *UserInformation) SetUserinfo(ui string) { u.userinfo = ui } 39 func (u *UserInformation) SetUsername(un string) { u.username = un } 40 func (u *UserInformation) SetPassword(p string) { u.password = p }