"Fossies" - the Fresh Open Source Software Archive

Member "buildah-1.23.1/vendor/github.com/docker/distribution/registry/client/auth/challenge/addr.go" (28 Sep 2021, 703 Bytes) of package /linux/misc/buildah-1.23.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package challenge
    2 
    3 import (
    4     "net/url"
    5     "strings"
    6 )
    7 
    8 // FROM: https://golang.org/src/net/http/http.go
    9 // Given a string of the form "host", "host:port", or "[ipv6::address]:port",
   10 // return true if the string includes a port.
   11 func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
   12 
   13 // FROM: http://golang.org/src/net/http/transport.go
   14 var portMap = map[string]string{
   15     "http":  "80",
   16     "https": "443",
   17 }
   18 
   19 // canonicalAddr returns url.Host but always with a ":port" suffix
   20 // FROM: http://golang.org/src/net/http/transport.go
   21 func canonicalAddr(url *url.URL) string {
   22     addr := url.Host
   23     if !hasPort(addr) {
   24         return addr + ":" + portMap[url.Scheme]
   25     }
   26     return addr
   27 }