github.com/pavlo67/common@v0.5.3/common/config/access.go (about)

     1  package config
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  // DEPRECATED!!! use url.URL instead
     9  type Access struct {
    10  	Proto   string
    11  	Host    string
    12  	Port    int
    13  	User    string
    14  	Pass    string
    15  	Path    string
    16  	Options string
    17  }
    18  
    19  func (access *Access) URL() string {
    20  	if access == nil {
    21  		return ""
    22  	}
    23  
    24  	url := strings.TrimSpace(access.Host)
    25  	if access.Port > 0 {
    26  		url += ":" + strconv.Itoa(access.Port)
    27  	}
    28  
    29  	path := strings.TrimSpace(access.Path)
    30  	if len(path) > 0 && path[0] != '/' {
    31  		url += "/" + path
    32  	} else {
    33  		url += path
    34  	}
    35  
    36  	if url != "" {
    37  		proto := strings.TrimSpace(access.Proto)
    38  
    39  		// TODO!!! remove the kostyl
    40  		if proto == "" {
    41  			proto = "http://"
    42  		}
    43  
    44  		url = proto + url
    45  	}
    46  
    47  	return url
    48  }