go.temporal.io/server@v1.23.0/common/archiver/uri.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package archiver 26 27 import ( 28 "net/url" 29 ) 30 31 type ( 32 // URI identifies the archival resource to which records are written to and read from. 33 URI interface { 34 Scheme() string 35 Path() string 36 Hostname() string 37 Port() string 38 Username() string 39 Password() string 40 String() string 41 Opaque() string 42 Query() map[string][]string 43 } 44 45 uri struct { 46 url *url.URL 47 } 48 ) 49 50 // NewURI constructs a new archiver URI from string. 51 func NewURI(s string) (URI, error) { 52 url, err := url.ParseRequestURI(s) 53 if err != nil { 54 return nil, err 55 } 56 return &uri{url: url}, nil 57 } 58 59 func (u *uri) Scheme() string { 60 return u.url.Scheme 61 } 62 63 func (u *uri) Path() string { 64 return u.url.Path 65 } 66 67 func (u *uri) Hostname() string { 68 return u.url.Hostname() 69 } 70 71 func (u *uri) Port() string { 72 return u.url.Port() 73 } 74 75 func (u *uri) Username() string { 76 if u.url.User == nil { 77 return "" 78 } 79 return u.url.User.Username() 80 } 81 82 func (u *uri) Password() string { 83 if u.url.User == nil { 84 return "" 85 } 86 password, exist := u.url.User.Password() 87 if !exist { 88 return "" 89 } 90 return password 91 } 92 93 func (u *uri) Opaque() string { 94 return u.url.Opaque 95 } 96 97 func (u *uri) Query() map[string][]string { 98 return u.url.Query() 99 } 100 101 func (u *uri) String() string { 102 return u.url.String() 103 }