fixed struct alignment && refactor linter
This commit is contained in:
@@ -10,11 +10,18 @@ import (
|
||||
type DigitalOceanMetadata struct {
|
||||
Metadata struct {
|
||||
V1 struct {
|
||||
DropletID int64 `json:"droplet_id"`
|
||||
Hostname string `json:"hostname"`
|
||||
VendorData string `json:"vendor_data"`
|
||||
Features map[string]interface{} `json:"features"`
|
||||
|
||||
Hostname string `json:"hostname"`
|
||||
VendorData string `json:"vendor_data"`
|
||||
Region string `json:"region"`
|
||||
|
||||
PublicKeys []string `json:"public_keys"`
|
||||
Region string `json:"region"`
|
||||
|
||||
DNS struct {
|
||||
Nameservers []string `json:"nameservers"`
|
||||
} `json:"dns"`
|
||||
|
||||
Interfaces struct {
|
||||
Private []struct {
|
||||
IPv4 struct {
|
||||
@@ -31,24 +38,23 @@ type DigitalOceanMetadata struct {
|
||||
Netmask string `json:"netmask"`
|
||||
Gateway string `json:"gateway"`
|
||||
} `json:"ipv4"`
|
||||
IPv6 struct {
|
||||
Address string `json:"ip_address"`
|
||||
CIDR int `json:"cidr"`
|
||||
Gateway string `json:"gateway"`
|
||||
} `json:"ipv6"`
|
||||
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"`
|
||||
DNS struct {
|
||||
Nameservers []string `json:"nameservers"`
|
||||
} `json:"dns"`
|
||||
Features map[string]interface{} `json:"features"`
|
||||
} `json:"v1"`
|
||||
} `json:"metadata"`
|
||||
}
|
||||
@@ -56,7 +62,7 @@ type DigitalOceanMetadata struct {
|
||||
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)
|
||||
_ = json.NewEncoder(w).Encode(stfs.Metadata.V1)
|
||||
default:
|
||||
fs := FileServer(stfs, "json", time.Now())
|
||||
idx := strings.Index(r.URL.Path[1:], "/")
|
||||
|
||||
@@ -2,29 +2,29 @@ package structfs
|
||||
|
||||
type EC2Metadata struct {
|
||||
Latest struct {
|
||||
Userdata string `json:"user-data"`
|
||||
Metadata struct {
|
||||
AMIID int `json:"ami-id"`
|
||||
AMILaunchIndex int `json:"ami-launch-index"`
|
||||
AMIManifestPath string `json:"ami-manifest-path"`
|
||||
AncestorAMIIDs []int `json:"ancestor-ami-ids"`
|
||||
BlockDeviceMapping []string `json:"block-device-mapping"`
|
||||
InstanceID int `json:"instance-id"`
|
||||
InstanceType string `json:"instance-type"`
|
||||
LocalHostname string `json:"local-hostname"`
|
||||
LocalIPv4 string `json:"local-ipv4"`
|
||||
kernelID int `json:"kernel-id"`
|
||||
Placement string `json:"placement"`
|
||||
AvailabilityZone string `json:"availability-zone"`
|
||||
ProductCodes string `json:"product-codes"`
|
||||
PublicHostname string `json:"public-hostname"`
|
||||
PublicIPv4 string `json:"public-ipv4"`
|
||||
PublicKeys []struct {
|
||||
AMIManifestPath string `json:"ami-manifest-path"`
|
||||
InstanceType string `json:"instance-type"`
|
||||
LocalHostname string `json:"local-hostname"`
|
||||
LocalIPv4 string `json:"local-ipv4"`
|
||||
Placement string `json:"placement"`
|
||||
AvailabilityZone string `json:"availability-zone"`
|
||||
ProductCodes string `json:"product-codes"`
|
||||
PublicHostname string `json:"public-hostname"`
|
||||
PublicIPv4 string `json:"public-ipv4"`
|
||||
PublicKeys []struct {
|
||||
Key []string `json:"-"`
|
||||
} `json:"public-keys"`
|
||||
RamdiskID int `json:"ramdisk-id"`
|
||||
ReservationID int `json:"reservation-id"`
|
||||
SecurityGroups []string `json:"security-groups"`
|
||||
AncestorAMIIDs []int `json:"ancestor-ami-ids"`
|
||||
BlockDeviceMapping []string `json:"block-device-mapping"`
|
||||
SecurityGroups []string `json:"security-groups"`
|
||||
RamdiskID int `json:"ramdisk-id"`
|
||||
ReservationID int `json:"reservation-id"`
|
||||
AMIID int `json:"ami-id"`
|
||||
AMILaunchIndex int `json:"ami-launch-index"`
|
||||
kernelID int `json:"kernel-id"`
|
||||
InstanceID int `json:"instance-id"`
|
||||
} `json:"meta-data"`
|
||||
Userdata string `json:"user-data"`
|
||||
} `json:"latest"`
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (fs *fs) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
f, err := fs.Open(r.URL.Path)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
@@ -35,22 +35,22 @@ func (fs *fs) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
type fs struct {
|
||||
modtime time.Time
|
||||
iface interface{}
|
||||
tag string
|
||||
modtime time.Time
|
||||
}
|
||||
|
||||
type file struct {
|
||||
name string
|
||||
offset int64
|
||||
data []byte
|
||||
modtime time.Time
|
||||
name string
|
||||
data []byte
|
||||
offset int64
|
||||
}
|
||||
|
||||
type fileInfo struct {
|
||||
modtime time.Time
|
||||
name string
|
||||
size int64
|
||||
modtime time.Time
|
||||
}
|
||||
|
||||
func (fi *fileInfo) Sys() interface{} {
|
||||
@@ -67,9 +67,9 @@ func (fi *fileInfo) Name() string {
|
||||
|
||||
func (fi *fileInfo) Mode() os.FileMode {
|
||||
if strings.HasSuffix(fi.name, "/") {
|
||||
return os.FileMode(0755) | os.ModeDir
|
||||
return os.FileMode(0o755) | os.ModeDir
|
||||
}
|
||||
return os.FileMode(0644)
|
||||
return os.FileMode(0o644)
|
||||
}
|
||||
|
||||
func (fi *fileInfo) IsDir() bool {
|
||||
@@ -105,22 +105,21 @@ func (f *file) Read(b []byte) (int, error) {
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (f *file) Readdir(count int) ([]os.FileInfo, error) {
|
||||
func (f *file) Readdir(_ int) ([]os.FileInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *file) Seek(offset int64, whence int) (int64, error) {
|
||||
// log.Printf("seek %d %d %s\n", offset, whence, f.name)
|
||||
switch whence {
|
||||
case os.SEEK_SET:
|
||||
case io.SeekStart:
|
||||
f.offset = offset
|
||||
case os.SEEK_CUR:
|
||||
case io.SeekCurrent:
|
||||
f.offset += offset
|
||||
case os.SEEK_END:
|
||||
case io.SeekEnd:
|
||||
f.offset = int64(len(f.data)) + offset
|
||||
}
|
||||
return f.offset, nil
|
||||
|
||||
}
|
||||
|
||||
func (f *file) Stat() (os.FileInfo, error) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package structfs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -82,17 +82,17 @@ func get(path string) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return ioutil.ReadAll(res.Body)
|
||||
return io.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
server(t)
|
||||
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{"http://127.0.0.1:8080/metadata/v1/", "droplet_id\nhostname\nvendor_data\npublic_keys\nregion\ninterfaces\nfloating_ip\ndns\nfeatures"},
|
||||
{"http://127.0.0.1:8080/metadata/v1/", "features\nhostname\nvendor_data\nregion\npublic_keys\ndns\ninterfaces\ndroplet_id\nfloating_ip"},
|
||||
{"http://127.0.0.1:8080/metadata/v1/droplet_id", "2756294"},
|
||||
{"http://127.0.0.1:8080/metadata/v1/dns/", "nameservers"},
|
||||
{"http://127.0.0.1:8080/metadata/v1/dns/nameservers", "2001:4860:4860::8844\n2001:4860:4860::8888\n8.8.8.8"},
|
||||
|
||||
Reference in New Issue
Block a user