github.com/echohead/hub@v2.2.1+incompatible/github/hosts.go (about)

     1  package github
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  
     7  	"github.com/github/hub/git"
     8  )
     9  
    10  var (
    11  	GitHubHostEnv = os.Getenv("GITHUB_HOST")
    12  )
    13  
    14  type GitHubHosts []string
    15  
    16  func (h GitHubHosts) Include(host string) bool {
    17  	for _, hh := range h {
    18  		if hh == host {
    19  			return true
    20  		}
    21  	}
    22  
    23  	return false
    24  }
    25  
    26  func knownGitHubHosts() (hosts GitHubHosts) {
    27  	defaultHost := DefaultGitHubHost()
    28  	hosts = append(hosts, defaultHost)
    29  	hosts = append(hosts, "ssh." + GitHubHost)
    30  
    31  	ghHosts, _ := git.Config("hub.host")
    32  	for _, ghHost := range strings.Split(ghHosts, "\n") {
    33  		ghHost = strings.TrimSpace(ghHost)
    34  		if ghHosts != "" {
    35  			hosts = append(hosts, ghHost)
    36  		}
    37  	}
    38  
    39  	return
    40  }
    41  
    42  func DefaultGitHubHost() string {
    43  	defaultHost := GitHubHostEnv
    44  	if defaultHost == "" {
    45  		defaultHost = GitHubHost
    46  	}
    47  
    48  	return defaultHost
    49  }