Rename (*KnownHosts).Load to LoadDefault
This commit is contained in:
		
							parent
							
								
									0bac966b23
								
							
						
					
					
						commit
						4770ad9112
					
				
							
								
								
									
										14
									
								
								doc.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								doc.go
									
									
									
									
									
								
							@ -1,7 +1,7 @@
 | 
			
		||||
/*
 | 
			
		||||
Package gmi implements the Gemini protocol.
 | 
			
		||||
 | 
			
		||||
Send makes a Gemini request:
 | 
			
		||||
Send makes a Gemini request with the default client:
 | 
			
		||||
 | 
			
		||||
	req := gmi.NewRequest("gemini://example.com")
 | 
			
		||||
	resp, err := gmi.Send(req)
 | 
			
		||||
@ -10,18 +10,19 @@ Send makes a Gemini request:
 | 
			
		||||
	}
 | 
			
		||||
	// ...
 | 
			
		||||
 | 
			
		||||
For control over client behavior, create a Client:
 | 
			
		||||
For control over client behavior, create a custom Client:
 | 
			
		||||
 | 
			
		||||
	var client gmi.Client
 | 
			
		||||
	err := client.Send(req)
 | 
			
		||||
	resp, err := client.Send(req)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// handle error
 | 
			
		||||
	}
 | 
			
		||||
	// ...
 | 
			
		||||
 | 
			
		||||
The default client loads known hosts from "$XDG_DATA_HOME/gemini/known_hosts".
 | 
			
		||||
Custom clients can load their own list of known hosts:
 | 
			
		||||
 | 
			
		||||
	err := client.KnownHosts.LoadFrom("path/to/my/known_hosts")
 | 
			
		||||
	err := client.KnownHosts.Load("path/to/my/known_hosts")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// handle error
 | 
			
		||||
	}
 | 
			
		||||
@ -56,7 +57,10 @@ Server is a Gemini server.
 | 
			
		||||
 | 
			
		||||
Servers must be configured with certificates:
 | 
			
		||||
 | 
			
		||||
	server.CertificateStore.Load("/var/lib/gemini/certs")
 | 
			
		||||
	err := server.CertificateStore.Load("/var/lib/gemini/certs")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// handle error
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
Servers can accept requests for multiple hosts and schemes:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@ var (
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	// Initialize the client
 | 
			
		||||
	client.KnownHosts.Load() // Load known hosts
 | 
			
		||||
	client.KnownHosts.LoadDefault() // Load known hosts
 | 
			
		||||
	client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gmi.KnownHosts) error {
 | 
			
		||||
		err := knownHosts.Lookup(hostname, cert)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
 | 
			
		||||
@ -75,7 +75,7 @@ func init() {
 | 
			
		||||
var setupDefaultClientOnce sync.Once
 | 
			
		||||
 | 
			
		||||
func setupDefaultClient() {
 | 
			
		||||
	DefaultClient.KnownHosts.Load()
 | 
			
		||||
	DefaultClient.KnownHosts.LoadDefault()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Send sends a Gemini request and returns a Gemini response.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								tofu.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tofu.go
									
									
									
									
									
								
							@ -21,22 +21,22 @@ type KnownHosts struct {
 | 
			
		||||
	file  *os.File
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Load loads the known hosts from the default known hosts path, which is
 | 
			
		||||
// LoadDefault loads the known hosts from the default known hosts path, which is
 | 
			
		||||
// $XDG_DATA_HOME/gemini/known_hosts.
 | 
			
		||||
// It creates the path and any of its parent directories if they do not exist.
 | 
			
		||||
// KnownHosts will append to the file whenever a certificate is added.
 | 
			
		||||
func (k *KnownHosts) Load() error {
 | 
			
		||||
func (k *KnownHosts) LoadDefault() error {
 | 
			
		||||
	path, err := defaultKnownHostsPath()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return k.LoadFrom(path)
 | 
			
		||||
	return k.Load(path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LoadFrom loads the known hosts from the provided path.
 | 
			
		||||
// Load loads the known hosts from the provided path.
 | 
			
		||||
// It creates the path and any of its parent directories if they do not exist.
 | 
			
		||||
// KnownHosts will append to the file whenever a certificate is added.
 | 
			
		||||
func (k *KnownHosts) LoadFrom(path string) error {
 | 
			
		||||
func (k *KnownHosts) Load(path string) error {
 | 
			
		||||
	if dir := filepath.Dir(path); dir != "." {
 | 
			
		||||
		err := os.MkdirAll(dir, 0755)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user