github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/uri/uri-authority.go (about)

     1  /* For license and copyright information please see the LEGAL file in the code repository */
     2  
     3  package uri
     4  
     5  import "strings"
     6  
     7  type AU = Authority
     8  
     9  // Authority store authority part of an URI.
    10  type Authority struct {
    11  	authority       string // host [ ":" port ]
    12  	UserInformation        //
    13  	host            string // host without port if any exist in authority
    14  	port            string //
    15  }
    16  
    17  func (a *Authority) Init(au string) {
    18  	if au == "" {
    19  		return
    20  	}
    21  
    22  	a.authority = au
    23  
    24  	var i = strings.IndexByte(au, AtSign)
    25  	if i > 0 {
    26  		a.UserInformation.Init(au[:i])
    27  		au = au[:i+1]
    28  	}
    29  	// TODO::: change below to respect RFC
    30  	i = strings.IndexByte(au, Colon)
    31  	if i > 0 {
    32  		a.host = au[:i]
    33  		a.port = au[i+1:]
    34  	} else {
    35  		a.host = au
    36  	}
    37  }
    38  func (a *Authority) Reinit() {
    39  	a.authority = ""
    40  	a.UserInformation.Reinit()
    41  	a.host = ""
    42  	a.port = ""
    43  }
    44  func (a *Authority) Deinit() {}
    45  
    46  func (a *Authority) Authority() string { return a.authority }
    47  func (a *Authority) Host() string      { return a.host }
    48  func (a *Authority) Port() string      { return a.port }
    49  
    50  func (a *Authority) SetAuthority(au string) { a.authority = au }
    51  func (a *Authority) SetHost(h string)       { a.host = h }
    52  func (a *Authority) SetPort(p string)       { a.port = p }