All checks were successful
		
		
	
	test / test (push) Successful in 42s
				
			## Pull Request template Please, go through these steps before clicking submit on this PR. 1. Give a descriptive title to your PR. 2. Provide a description of your changes. 3. Make sure you have some relevant tests. 4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable). **PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING** Reviewed-on: #369 Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru> Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
		
			
				
	
	
		
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package structfs
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/json"
 | 
						|
	"net/http"
 | 
						|
	"strings"
 | 
						|
	"time"
 | 
						|
)
 | 
						|
 | 
						|
type DigitalOceanMetadata struct {
 | 
						|
	Metadata struct {
 | 
						|
		V1 struct {
 | 
						|
			Features map[string]interface{} `json:"features"`
 | 
						|
 | 
						|
			Hostname   string `json:"hostname"`
 | 
						|
			VendorData string `json:"vendor_data"`
 | 
						|
			Region     string `json:"region"`
 | 
						|
 | 
						|
			PublicKeys []string `json:"public_keys"`
 | 
						|
 | 
						|
			DNS struct {
 | 
						|
				Nameservers []string `json:"nameservers"`
 | 
						|
			} `json:"dns"`
 | 
						|
 | 
						|
			Interfaces struct {
 | 
						|
				Private []struct {
 | 
						|
					IPv4 struct {
 | 
						|
						Address string `json:"ip_address"`
 | 
						|
						Netmask string `json:"netmask"`
 | 
						|
						Gateway string `json:"gateway"`
 | 
						|
					}
 | 
						|
					Mac  string `json:"mac"`
 | 
						|
					Type string `json:"type"`
 | 
						|
				} `json:"private"`
 | 
						|
				Public []struct {
 | 
						|
					IPv4 struct {
 | 
						|
						Address string `json:"ip_address"`
 | 
						|
						Netmask string `json:"netmask"`
 | 
						|
						Gateway string `json:"gateway"`
 | 
						|
					} `json:"ipv4"`
 | 
						|
					Mac  string `json:"mac"`
 | 
						|
					Type string `json:"type"`
 | 
						|
					IPv6 struct {
 | 
						|
						Address string `json:"ip_address"`
 | 
						|
						Gateway string `json:"gateway"`
 | 
						|
						CIDR    int    `json:"cidr"`
 | 
						|
					} `json:"ipv6"`
 | 
						|
				} `json:"public"`
 | 
						|
			} `json:"interfaces"`
 | 
						|
 | 
						|
			DropletID int64 `json:"droplet_id"`
 | 
						|
 | 
						|
			FloatingIP struct {
 | 
						|
				IPv4 struct {
 | 
						|
					Active bool `json:"active"`
 | 
						|
				} `json:"ipv4"`
 | 
						|
			} `json:"floating_ip"`
 | 
						|
		} `json:"v1"`
 | 
						|
	} `json:"metadata"`
 | 
						|
}
 | 
						|
 | 
						|
func (stfs *DigitalOceanMetadata) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
						|
	switch r.URL.Path {
 | 
						|
	case "/metadata/v1.json":
 | 
						|
		_ = json.NewEncoder(w).Encode(stfs.Metadata.V1)
 | 
						|
	default:
 | 
						|
		fs := FileServer(stfs, "json", time.Now())
 | 
						|
		idx := strings.Index(r.URL.Path[1:], "/")
 | 
						|
		r.URL.Path = strings.Replace(r.URL.Path[idx+1:], "/metadata/v1/", "", 1)
 | 
						|
		r.RequestURI = r.URL.Path
 | 
						|
		fs.ServeHTTP(w, r)
 | 
						|
	}
 | 
						|
}
 |