diff --git a/cli/config.go b/cli/config.go index 3e83b98..a6dce4c 100644 --- a/cli/config.go +++ b/cli/config.go @@ -82,6 +82,8 @@ func (c Config) ConchClient() *conch.Client { ) } +// Renderer is a function that takes some kind of data and an error and renders +// the output type Renderer func(interface{}, error) // Renderer returns a function that will render to STDOUT @@ -89,6 +91,8 @@ func (c Config) Renderer() Renderer { return c.RenderTo(os.Stdout) } +// Before takes a list of checks and initializers and returns a function +// suitable for running in a commmand's before block func (c Config) Before(checks ...func(c Config)) func() { return func() { for _, check := range checks { diff --git a/conch/builds.go b/conch/builds.go index 6ebfb6f..f55694c 100644 --- a/conch/builds.go +++ b/conch/builds.go @@ -45,8 +45,7 @@ func (c *Client) GetBuildByID(id types.UUID) (build types.Build, e error) { return } -// UpdateBuild updates a named build -// POST /build/:build_id_or_name +// UpdateBuild (POST /build/:build_id_or_name) updates a named build func (c *Client) UpdateBuild(name string, update types.BuildUpdate) error { return c.UpdateBuildByName(name, update) } @@ -58,53 +57,55 @@ func (c *Client) UpdateBuildByID(buildID types.UUID, update types.BuildUpdate) e return e } -// UpdateBuild updates a named build -// POST /build/:build_id_or_name +// UpdateBuildByName (POST /build/:build_id_or_name) updates a named build func (c *Client) UpdateBuildByName(name string, update types.BuildUpdate) error { c.Logger.Info(fmt.Sprintf("updating build %v: %v", name, update)) _, e := c.Build(name).Post(update).Send() return e } -// GetBuildUsers retrieves a list of users associated with the given build -// GET /build/:build_id_or_name/user +// GetBuildUsers (GET /build/:build_id_or_name/user) retrieves a list of users +// associated with the given build func (c *Client) GetBuildUsers(name string) (build types.BuildUsers, e error) { c.Logger.Info(fmt.Sprintf("getting users for build: %s", name)) _, e = c.Build(name).User("").Receive(&build) return } -// AddBuildUser associates a new user with the build, optionally tell the API to email the user too -// POST /build/:build_id_or_name/user +// AddBuildUser (POST /build/:build_id_or_name/user) associates a new user with +// the build, optionally tell the API to email the user too func (c *Client) AddBuildUser(name string, update types.BuildAddUser, sendEmail bool) error { c.Logger.Info(fmt.Sprintf("adding users to build %v: %v", name, update)) _, e := c.Build(name).User("").Post(update).Send() return e } -// DeleteBuildUser removes a user from being associated with the build -// DELETE /build/:build_id_or_name/user/#target_user_id_or_email +// DeleteBuildUser (DELETE /build/:build_id_or_name/user/#target_user_id_or_email) +// removes a user from being associated with the build func (c *Client) DeleteBuildUser(name, user string, sendEmail bool) error { c.Logger.Info(fmt.Sprintf("removing user from build %v: %v", name, user)) _, e := c.Build(name).User(user).Delete().Send() return e } -// GetAllBuildOrganizations - GET /build/:build_id_or_name/user +// GetAllBuildOrganizations (GET /build/:build_id_or_name/user) retrieves a +// list of all organizations associated with the named build func (c *Client) GetAllBuildOrganizations(name string) (build types.BuildOrganizations, e error) { c.Logger.Info(fmt.Sprintf("getting organizations for build: %s", name)) _, e = c.Build(name).Organization("").Receive(&build) return } -// AddBuildOrganization - POST /build/:build_id_or_name/user +// AddBuildOrganization (POST /build/:build_id_or_name/user) adds an +// organization to the named build. func (c *Client) AddBuildOrganization(name string, update types.BuildAddOrganization, sendEmail bool) error { c.Logger.Info(fmt.Sprintf("adding organization to build %v: %v", name, update)) _, e := c.Build(name).Organization("").Post(update).Send() return e } -// DeleteBuildOrganization - DELETE /build/:build_id_or_name/user/#target_user_id_or_email +// DeleteBuildOrganization (DELETE /build/:build_id_or_name/user/#target_user_id_or_email) +// removes an organization from the named build func (c *Client) DeleteBuildOrganization(build, org string, sendEmail bool) error { c.Logger.Info(fmt.Sprintf("removing organization from build %v: %v", build, org)) _, e := c.Build(build).Organization(org).Delete().Send() diff --git a/conch/client.go b/conch/client.go index 00bc38f..d7a2914 100644 --- a/conch/client.go +++ b/conch/client.go @@ -29,6 +29,8 @@ func defaultUserAgent() string { return fmt.Sprintf("go-conch %s", filepath.Base(f)) } +// Option is a function that takes a Conch client pointer and applies a +// configuration option to it type Option func(*Client) // New takes a Config struct and returns a new instance of Client @@ -45,27 +47,28 @@ func New(options ...Option) (client *Client) { return } -// HTTPCLient sets the client used by the package for making HTTP Requests +// HTTPClient returns an Option that sets the client used by the package for +// making HTTP Requests func HTTPClient(client *http.Client) Option { return func(c *Client) { c.Sling.Client(client) } } -// UserAgent sets the User-Agent used by the package +// UserAgent returns an Option that sets the User-Agent used by the package func UserAgent(ua string) Option { return func(c *Client) { c.Sling.Set("User-Agent", ua) } } -// API sets the base URL for the API +// API returns an Option that sets the base URL for the API func API(url string) Option { return func(c *Client) { c.Sling.Base(url) } } -// AuthToken sets the authentication token +// AuthToken returns an Option that sets the authentication token func AuthToken(token string) Option { return func(c *Client) { c.Sling.Set("Authorization", "Bearer "+token) } } -// Logger sets the logger used by the package +// Logger returns an Option that sets the logger used by the package func Logger(logger logger.Interface) Option { return func(c *Client) { c.Logger = logger } } @@ -84,13 +87,14 @@ func (c *Client) New() *Client { return &Client{s, l} } -// UserAgent sets the client's User-Agent header to the given string +// UserAgent sets the client's User-Agent header in the request func (c *Client) UserAgent(ua string) *Client { c = c.New() c.Sling.Set("User-Agent", ua) return c } +// Authorization sets the Authorization header in the request func (c *Client) Authorization(auth string) *Client { c = c.New() c.Sling.Set("Authorization", auth) diff --git a/conch/types/common.go b/conch/types/common.go index a13123f..f1ef6cc 100644 --- a/conch/types/common.go +++ b/conch/types/common.go @@ -4,24 +4,38 @@ import ( "github.com/gofrs/uuid" ) +// UUID is a Universally Unique ID type UUID struct{ uuid.UUID } +// MojoRelaxedPlaceholder is a string type MojoRelaxedPlaceholder string +// MojoStandardPlaceholder is a string type MojoStandardPlaceholder string +// Link is a string type Link string +// DeviceSerialNumber is a string type DeviceSerialNumber string +// DeviceSerials is a slice of DeviceSerialNumbers +type DeviceSerials []DeviceSerialNumber + +// DeviceSerialNumberEmbedded0 is a string type DeviceSerialNumberEmbedded0 string +// Macaddr is a string type Macaddr string +// NonEmptyString is a string type NonEmptyString string +// EmailAddress is a string type EmailAddress string +// NewDeviceLinks takes a list of strings and returns them as a single +// DeviceLinks slice func NewDeviceLinks(uris ...string) DeviceLinks { links := []Link{} for _, u := range uris { @@ -29,3 +43,25 @@ func NewDeviceLinks(uris ...string) DeviceLinks { } return DeviceLinks{links} } + +// IntOrStringyInt is an integer that may be presented as a json string +type IntOrStringyInt interface{} + +// DiskSizeItem is an int +type DiskSizeItem int + +// DeviceHealth is a string +// corresponds to device_health_enum in the database +type DeviceHealth string + +// DevicePhase corresponds to device_phase_enum in the database (also used for racks) +type DevicePhase string + +// NonNegativeInteger is an int +type NonNegativeInteger int + +// PositiveInteger is an int +type PositiveInteger int + +// Ipaddr is a string +type Ipaddr string diff --git a/conch/types/requests.go b/conch/types/requests.go index 144a32d..2d93f2d 100644 --- a/conch/types/requests.go +++ b/conch/types/requests.go @@ -2,23 +2,23 @@ package types import "time" +// BuildAddOrganization is a struct // generated by "schematyper -o types/RequestType_BuildAddOrganization.go --package=types --ptr-for-omit BuildAddOrganization.json" -- DO NOT EDIT - type BuildAddOrganization struct { OrganizationID UUID `json:"organization_id"` Role Role `json:"role"` } +// BuildAddUser is a struct // generated by "schematyper -o types/RequestType_BuildAddUser.go --package=types --ptr-for-omit BuildAddUser.json" -- DO NOT EDIT - type BuildAddUser struct { Email EmailAddress `json:"email,omitempty"` Role Role `json:"role"` UserID UUID `json:"user_id,omitempty"` } +// BuildCreateDevice is a struct // generated by "schematyper -o types/RequestType_BuildCreateDevices.go --package=types --ptr-for-omit BuildCreateDevices.json" -- DO NOT EDIT - type BuildCreateDevice struct { AssetTag interface{} `json:"asset_tag,omitempty"` ID UUID `json:"id,omitempty"` @@ -27,15 +27,17 @@ type BuildCreateDevice struct { Sku MojoStandardPlaceholder `json:"sku"` } +// BuildCreateDevices is a slice of BuildCreateDevice type BuildCreateDevices []BuildCreateDevice +// Admin is a struct // generated by "schematyper -o types/RequestType_BuildCreate.go --package=types --ptr-for-omit BuildCreate.json" -- DO NOT EDIT - type Admin struct { Email EmailAddress `json:"email,omitempty"` UserID UUID `json:"user_id,omitempty"` } +// BuildCreate is a struct type BuildCreate struct { Admins []Admin `json:"admins,omitempty"` BuildID UUID `json:"build_id,omitempty"` @@ -44,8 +46,8 @@ type BuildCreate struct { Started time.Time `json:"started,omitempty"` } +// BuildUpdate is a struct // generated by "schematyper -o types/RequestType_BuildUpdate.go --package=types --ptr-for-omit BuildUpdate.json" -- DO NOT EDIT - type BuildUpdate struct { Completed interface{} `json:"completed,omitempty"` Description interface{} `json:"description,omitempty"` @@ -53,8 +55,8 @@ type BuildUpdate struct { Started interface{} `json:"started,omitempty"` } +// DatacenterCreate is a struct // generated by "schematyper -o types/RequestType_DatacenterCreate.go --package=types --ptr-for-omit DatacenterCreate.json" -- DO NOT EDIT - type DatacenterCreate struct { Location NonEmptyString `json:"location"` Region NonEmptyString `json:"region"` @@ -62,8 +64,8 @@ type DatacenterCreate struct { VendorName NonEmptyString `json:"vendor_name,omitempty"` } +// DatacenterUpdate is a struct // generated by "schematyper -o types/RequestType_DatacenterUpdate.go --package=types --ptr-for-omit DatacenterUpdate.json" -- DO NOT EDIT - type DatacenterUpdate struct { Location NonEmptyString `json:"location,omitempty"` Region NonEmptyString `json:"region,omitempty"` @@ -71,17 +73,18 @@ type DatacenterUpdate struct { VendorName NonEmptyString `json:"vendor_name,omitempty"` } +// DeviceLinks is a struct // generated by "schematyper -o types/RequestType_DeviceLinks.go --package=types --ptr-for-omit DeviceLinks.json" -- DO NOT EDIT - type DeviceLinks struct { Links []Link `json:"links"` } +// CpusItem is a map of strings to data // generated by "schematyper -o RequestType_DeviceReport.go --package=types --ptr-for-omit DeviceReport.json" -- DO NOT EDIT - type CpusItem map[string]interface{} -// the contents of a posted device report from relays and reporters +// DeviceReport is a struct of the contents of a posted device report from +// relays and reporters type DeviceReport struct { BiosVersion string `json:"bios_version"` Cpus []CpusItem `json:"cpus,omitempty"` @@ -95,17 +98,19 @@ type DeviceReport struct { Relay *Relay `json:"relay,omitempty"` SerialNumber DeviceSerialNumber `json:"serial_number"` Sku string `json:"sku"` - SystemUUID NonZeroUUID `json:"system_uuid"` + SystemUUID UUID `json:"system_uuid"` Temp *Temp `json:"temp,omitempty"` UptimeSince string `json:"uptime_since,omitempty"` } +// Dimm is a struct of memory information type Dimm struct { MemoryLocator string `json:"memory-locator"` MemorySerialNumber interface{} `json:"memory-serial-number,omitempty"` MemorySize interface{} `json:"memory-size,omitempty"` } +// Disk is a struct of disk information type Disk struct { BlockSz int `json:"block_sz,omitempty"` DriveType string `json:"drive_type,omitempty"` @@ -121,11 +126,10 @@ type Disk struct { Vendor string `json:"vendor,omitempty"` } +// DiskSerialNumber is a string type DiskSerialNumber string -// an integer that may be presented as a json string -type IntOrStringyInt interface{} - +// Interface is a struct of network interface information type Interface struct { Ipaddr interface{} `json:"ipaddr,omitempty"` Mac Macaddr `json:"mac"` @@ -136,23 +140,21 @@ type Interface struct { Vendor string `json:"vendor"` } -type NonZeroUUID interface{} - -type NonZeroUUIDEmbedded1 interface{} - +// Os is a struct of OS inforamtion type Os struct { Hostname string `json:"hostname"` } +// Temp is a struct of temperature data type Temp struct { - Cpu0 IntOrStringyInt `json:"cpu0"` - Cpu1 IntOrStringyInt `json:"cpu1"` + CPU0 IntOrStringyInt `json:"cpu0"` + CPU1 IntOrStringyInt `json:"cpu1"` Exhaust IntOrStringyInt `json:"exhaust,omitempty"` Inlet IntOrStringyInt `json:"inlet,omitempty"` } +// HardwareProductCreate is a struct // generated by "schematyper -o types/RequestType_HardwareProductCreate.go --package=types --ptr-for-omit HardwareProductCreate.json" -- DO NOT EDIT - type HardwareProductCreate struct { Alias MojoStandardPlaceholder `json:"alias,omitempty"` BiosFirmware string `json:"bios_firmware,omitempty"` @@ -192,28 +194,26 @@ type HardwareProductCreate struct { ValidationPlanID UUID `json:"validation_plan_id,omitempty"` } -type HardwareProductCreateEmbedded1 interface{} - +// Chassis is a struct of Chassis data // generated by "schematyper -o types/RequestType_HardwareProductSpecification.go --package=types --ptr-for-omit HardwareProductSpecification.json" -- DO NOT EDIT - type Chassis struct { Memory *Memory `json:"memory,omitempty"` } -type DiskSizeItem int - -// this is the structure of the hardware_product.specification database column +// HardwareProductSpecification is the structure of the +// hardware_product.specification database column type HardwareProductSpecification struct { Chassis *Chassis `json:"chassis,omitempty"` DiskSize map[string]DiskSizeItem `json:"disk_size,omitempty"` } +// Memory is a struct of Memory inforamtion type Memory struct { Dimms []Dimm `json:"dimms,omitempty"` } +// HardwareProductUpdate is a struct // generated by "schematyper -o types/RequestType_HardwareProductUpdate.go --package=types --ptr-for-omit HardwareProductUpdate.json" -- DO NOT EDIT - type HardwareProductUpdate struct { Alias MojoStandardPlaceholder `json:"alias,omitempty"` BiosFirmware string `json:"bios_firmware,omitempty"` @@ -253,8 +253,8 @@ type HardwareProductUpdate struct { ValidationPlanID UUID `json:"validation_plan_id,omitempty"` } +// Login is a struct // generated by "schematyper -o types/RequestType_Login.go --package=types --ptr-for-omit Login.json" -- DO NOT EDIT - type Login struct { Email EmailAddress `json:"email,omitempty"` Password NonEmptyString `json:"password"` @@ -262,8 +262,8 @@ type Login struct { // UserID UUID `json:"user_id,omitempty"` } +// NewUser is a struct // generated by "schematyper -o types/RequestType_NewUser.go --package=types --ptr-for-omit NewUser.json" -- DO NOT EDIT - type NewUser struct { Email EmailAddress `json:"email"` IsAdmin bool `json:"is_admin,omitempty"` @@ -271,37 +271,37 @@ type NewUser struct { Password NonEmptyString `json:"password,omitempty"` } +// NewUserTokenRequest is a struct // generated by "schematyper -o types/RequestType_NewUserToken.go --package=types --ptr-for-omit NewUserToken.json" -- DO NOT EDIT - type NewUserTokenRequest struct { Name string `json:"name"` } +// OrganizationAddUser is a struct // generated by "schematyper -o types/RequestType_OrganizationAddUser.go --package=types --ptr-for-omit OrganizationAddUser.json" -- DO NOT EDIT - type OrganizationAddUser struct { Email EmailAddress `json:"email,omitempty"` Role Role `json:"role"` UserID UUID `json:"user_id,omitempty"` } +// OrganizationCreate is a struct // generated by "schematyper -o types/RequestType_OrganizationCreate.go --package=types --ptr-for-omit OrganizationCreate.json" -- DO NOT EDIT - type OrganizationCreate struct { Admins []Admin `json:"admins"` Description NonEmptyString `json:"description,omitempty"` Name MojoStandardPlaceholder `json:"name"` } +// OrganizationUpdate is a struct // generated by "schematyper -o types/RequestType_OrganizationUpdate.go --package=types --ptr-for-omit OrganizationUpdate.json" -- DO NOT EDIT - type OrganizationUpdate struct { Description interface{} `json:"description,omitempty"` Name MojoStandardPlaceholder `json:"name,omitempty"` } +// RegisterRelay is a struct // generated by "schematyper -o types/RequestType_RegisterRelay.go --package=types --ptr-for-omit RegisterRelay.json" -- DO NOT EDIT - type RegisterRelay struct { Ipaddr string `json:"ipaddr,omitempty"` Name NonEmptyString `json:"name,omitempty"` @@ -310,24 +310,27 @@ type RegisterRelay struct { Version string `json:"version,omitempty"` } +// UpdateUser is a struct // generated by "schematyper -o types/RequestType_UpdateUser.go --package=types --ptr-for-omit UpdateUser.json" -- DO NOT EDIT - type UpdateUser struct { Email EmailAddress `json:"email,omitempty"` IsAdmin bool `json:"is_admin,omitempty"` Name NonEmptyString `json:"name,omitempty"` } +// RackRoleCreate is a struct type RackRoleCreate struct { Name MojoStandardPlaceholder `json:"name"` RackSize PositiveInteger `json:"rack_size"` } +// RackRoleUpdate is a struct type RackRoleUpdate struct { Name MojoStandardPlaceholder `json:"name,omitempty"` RackSize PositiveInteger `json:"rack_size,omitempty"` } +// RackUpdate is a struct type RackUpdate struct { AssetTag interface{} `json:"asset_tag,omitempty"` BuildID UUID `json:"build_id,omitempty"` @@ -338,6 +341,7 @@ type RackUpdate struct { SerialNumber interface{} `json:"serial_number,omitempty"` } +// RackCreate is a struct type RackCreate struct { AssetTag NonEmptyString `json:"asset_tag,omitempty"` BuildID UUID `json:"build_id"` @@ -348,19 +352,23 @@ type RackCreate struct { SerialNumber NonEmptyString `json:"serial_number,omitempty"` } +// RackLayoutUpdate is a struct type RackLayoutUpdate struct { HardwareProductID UUID `json:"hardware_product_id,omitempty"` RackID interface{} `json:"rack_id,omitempty"` RackUnitStart PositiveInteger `json:"rack_unit_start,omitempty"` } +// RackAssignmentDelete is a struct type RackAssignmentDelete struct { DeviceID UUID `json:"device_id"` RackUnitStart PositiveInteger `json:"rack_unit_start"` } +// RackAssignmentDeletes is slice of RackAssignmentDelete structs type RackAssignmentDeletes []RackAssignmentDelete +// RackAssignmentUpdate is a struct type RackAssignmentUpdate struct { DeviceAssetTag interface{} `json:"device_asset_tag,omitempty"` DeviceID UUID `json:"device_id,omitempty"` @@ -368,16 +376,20 @@ type RackAssignmentUpdate struct { RackUnitStart PositiveInteger `json:"rack_unit_start"` } +// RackAssignmentUpdates is a slice of RackAssignmentUpdate structs type RackAssignmentUpdates []RackAssignmentUpdate +// RackPhase is a struct type RackPhase struct { Phase DevicePhase `json:"phase"` } +// RackLinks is a struct type RackLinks struct { Links []Link `json:"links,omitempty"` } +// DatacenterRoomCreate is a struct type DatacenterRoomCreate struct { Alias MojoStandardPlaceholder `json:"alias"` Az NonEmptyString `json:"az"` @@ -385,6 +397,7 @@ type DatacenterRoomCreate struct { VendorName MojoRelaxedPlaceholder `json:"vendor_name"` } +// DatacenterRoomUpdate is a struct type DatacenterRoomUpdate struct { Alias MojoStandardPlaceholder `json:"alias,omitempty"` Az NonEmptyString `json:"az,omitempty"` diff --git a/conch/types/responses.go b/conch/types/responses.go index cad9ef8..33ad302 100644 --- a/conch/types/responses.go +++ b/conch/types/responses.go @@ -2,8 +2,8 @@ package types import "time" +// Build is a struct // generated by "schematyper -o types/ResponseType_Build.go --package=types --ptr-for-omit Build.json" -- DO NOT EDIT - type Build struct { Admins UsersTerse `json:"admins,omitempty"` Completed time.Time `json:"completed"` @@ -20,24 +20,21 @@ type Build struct { Links []Link `json:"links"` } -// corresponds to device_health_enum in the database -type DeviceHealth string - -// corresponds to device_phase_enum in the database (also used for racks) -type DevicePhase string - +// UserTerse is a struct type UserTerse struct { Email EmailAddress `json:"email"` ID UUID `json:"id"` Name string `json:"name"` } +// UsersTerse is a slice of UserTerse structs type UsersTerse []UserTerse +// BuildOrganizations is a slice of BuildOrganization structs // generated by "schematyper -o types/ResponseType_BuildOrganizations.go --package=types --ptr-for-omit BuildOrganizations.json" -- DO NOT EDIT - type BuildOrganizations []BuildOrganization +// BuildOrganization is a struct type BuildOrganization struct { ID UUID `json:"id"` Name string `json:"name"` @@ -46,12 +43,12 @@ type BuildOrganization struct { Role Role `json:"role"` } +// Builds is a slice of Build structs // generated by "schematyper -o types/ResponseType_Builds.go --package=types --ptr-for-omit Builds.json" -- DO NOT EDIT - type Builds []Build +// BuildUser is a struct // generated by "schematyper -o types/ResponseType_BuildUsers.go --package=types --ptr-for-omit BuildUsers.json" -- DO NOT EDIT - type BuildUser struct { Email EmailAddress `json:"email"` ID UUID `json:"id"` @@ -59,10 +56,11 @@ type BuildUser struct { Role Role `json:"role"` } +// BuildUsers is a slice of BuildUser structs type BuildUsers []BuildUser +// DatacenterRoomDetailed is a struct // generated by "schematyper -o types/ResponseType_DatacenterRoomsDetailed.go --package=types --ptr-for-omit DatacenterRoomsDetailed.json" -- DO NOT EDIT - type DatacenterRoomDetailed struct { Alias MojoStandardPlaceholder `json:"alias"` AZ string `json:"az"` @@ -73,10 +71,11 @@ type DatacenterRoomDetailed struct { VendorName MojoRelaxedPlaceholder `json:"vendor_name"` } +// DatacenterRoomsDetailed is a slice of DatacenterRoomDetailed structs type DatacenterRoomsDetailed []DatacenterRoomDetailed +// Datacenter is a struct // generated by "schematyper -o types/ResponseType_Datacenters.go --package=types --ptr-for-omit Datacenters.json" -- DO NOT EDIT - type Datacenter struct { Created time.Time `json:"created"` ID UUID `json:"id"` @@ -87,10 +86,11 @@ type Datacenter struct { VendorName string `json:"vendor_name"` } +// Datacenters is a slice of Datacenter structs type Datacenters []Datacenter +// DetailedDevice is a struct // generated by "schematyper -o types/ResponseType_DetailedDevice.go --package=types --ptr-for-omit DetailedDevice.json" -- DO NOT EDIT - type DetailedDevice struct { AssetTag DeviceAssetTag `json:"asset_tag"` BuildID UUID `json:"build_id"` @@ -115,6 +115,7 @@ type DetailedDevice struct { Validated time.Time `json:"validated"` } +// DetailedDeviceDisk is a struct type DetailedDeviceDisk struct { Created time.Time `json:"created"` DriveType interface{} `json:"drive_type"` @@ -132,13 +133,14 @@ type DetailedDeviceDisk struct { Vendor interface{} `json:"vendor"` } +// DetailedDeviceLink is a string type DetailedDeviceLink string -type DeviceInterfaceName interface{} +// DeviceInterfaceName is a string +type DeviceInterfaceName string -type DeviceInterfaceNameEmbedded0 string - -// the contents of a posted device report from relays and reporters +// DeviceReportV300 is a struct that contains the contents of a posted device +// report from relays and reporters type DeviceReportV300 struct { BiosVersion string `json:"bios_version"` Cpus []CpusItem `json:"cpus,omitempty"` @@ -152,11 +154,12 @@ type DeviceReportV300 struct { Relay *Relay `json:"relay,omitempty"` SerialNumber DeviceSerialNumber `json:"serial_number"` Sku string `json:"sku"` - SystemUUID NonZeroUUID `json:"system_uuid"` + SystemUUID UUID `json:"system_uuid"` Temp *Temp `json:"temp,omitempty"` UptimeSince string `json:"uptime_since,omitempty"` } +// DeviceReportV300Disk is a struct of Disk data type DeviceReportV300Disk struct { BlockSz int `json:"block_sz,omitempty"` DriveType string `json:"drive_type,omitempty"` @@ -172,8 +175,10 @@ type DeviceReportV300Disk struct { Vendor string `json:"vendor,omitempty"` } +// DeviceReportV300Link is a strign type DeviceReportV300Link string +// Nic is a strut type Nic struct { IfaceName DeviceInterfaceName `json:"iface_name"` IfaceType string `json:"iface_type,omitempty"` @@ -184,34 +189,33 @@ type Nic struct { PeerSwitch interface{} `json:"peer_switch"` } -type NonNegativeInteger int - +// DeviceBuild is a blob of data // generated by "schematyper -o types/ResponseType_DeviceBuild.go --package=types --ptr-for-omit DeviceBuild.json" -- DO NOT EDIT - type DeviceBuild interface{} +// DeviceHardware is a blob of data // generated by "schematyper -o types/ResponseType_DeviceHardware.go --package=types --ptr-for-omit DeviceHardware.json" -- DO NOT EDIT - type DeviceHardware interface{} -// generated by "schematyper -o types/ResponseType_DeviceLinks.go --package=types --ptr-for-omit DeviceLinks.json" -- DO NOT EDIT - +// DeviceLocationUpdate is a blob of data // generated by "schematyper -o types/ResponseType_DeviceLocationUpdate.go --package=types --ptr-for-omit DeviceLocationUpdate.json" -- DO NOT EDIT - type DeviceLocationUpdate interface{} +// DeviceNicField is struct // generated by "schematyper -o types/ResponseType_DeviceNicField.go --package=types --ptr-for-omit DeviceNicField.json" -- DO NOT EDIT - type DeviceNicField struct { DeviceNicFields DeviceNicFieldEmbedded1 DeviceNicFieldEmbedded2 } +// DeviceNicFieldEmbedded1 is a map of strings to data type DeviceNicFieldEmbedded1 map[string]interface{} +// DeviceNicFieldEmbedded2 is blob of data type DeviceNicFieldEmbedded2 interface{} +// DeviceNicFields is a struct type DeviceNicFields struct { DeviceID UUID `json:"device_id,omitempty"` IfaceDriver string `json:"iface_driver,omitempty"` @@ -224,21 +228,21 @@ type DeviceNicFields struct { State string `json:"state,omitempty"` } -type Ipaddr string - +// DeviceNic is a struct // generated by "schematyper -o types/ResponseType_DeviceNics.go --package=types --ptr-for-omit DeviceNics.json" -- DO NOT EDIT - type DeviceNic struct { DeviceNicFields DeviceNicEmbedded1 } +// DeviceNicEmbedded1 is a map of strings to data type DeviceNicEmbedded1 map[string]interface{} +// DeviceNics is a slice of DeviceNic structs type DeviceNics []DeviceNic +// DevicePXE is a struct // generated by "schematyper -o types/ResponseType_DevicePXE.go --package=types --ptr-for-omit DevicePXE.json" -- DO NOT EDIT - type DevicePXE struct { ID UUID `json:"id"` Ipmi interface{} `json:"ipmi"` @@ -247,7 +251,8 @@ type DevicePXE struct { Pxe interface{} `json:"pxe"` } -// Details of the hardware product the device is expected to be based on its current position and the rack layout. +// TargetHardwareProduct is a struct that details of the hardware product the +// device is expected to be based on its current position and the rack layout. type TargetHardwareProduct struct { Alias string `json:"alias"` HardwareVendorID UUID `json:"hardware_vendor_id"` @@ -256,8 +261,8 @@ type TargetHardwareProduct struct { Sku MojoStandardPlaceholder `json:"sku"` } +// DeviceLocation is a struct // generated by "schematyper -o types/ResponseType_DevicePXEs.go --package=types --ptr-for-omit DevicePXEs.json" -- DO NOT EDIT - type DeviceLocation struct { Az string `json:"az"` DatacenterRoom MojoStandardPlaceholder `json:"datacenter_room"` @@ -266,6 +271,7 @@ type DeviceLocation struct { TargetHardwareProduct TargetHardwareProduct `json:"target_hardware_product"` } +// DevicePxe is a struct type DevicePxe struct { ID UUID `json:"id"` Ipmi interface{} `json:"ipmi"` @@ -274,10 +280,11 @@ type DevicePxe struct { Pxe interface{} `json:"pxe"` } +// DevicePxes is a slice of DevicePXE structs type DevicePxes []DevicePxe +// DeviceReportRow is a struct // generated by "schematyper -o types/ResponseType_DeviceReportRow.go --package=types --ptr-for-omit DeviceReportRow.json" -- DO NOT EDIT - type DeviceReportRow struct { Created time.Time `json:"created"` DeviceID UUID `json:"device_id"` @@ -285,18 +292,15 @@ type DeviceReportRow struct { Report DeviceReportV300 `json:"report"` } -// generated by "schematyper -o types/ResponseType_DeviceSerials.go --package=types --ptr-for-omit DeviceSerials.json" -- DO NOT EDIT - -type DeviceSerials []DeviceSerialNumber - +// DeviceSetting is a string // generated by "schematyper -o types/ResponseType_DeviceSettings.go --package=types --ptr-for-omit DeviceSettings.json" -- DO NOT EDIT - type DeviceSetting string +// DeviceSettings is a map of string to DeviceSetting type DeviceSettings map[string]DeviceSetting +// Device is a struct // generated by "schematyper -o types/ResponseType_Devices.go --package=types --ptr-for-omit Devices.json" -- DO NOT EDIT - type Device struct { AssetTag DeviceAssetTag `json:"asset_tag"` BuildID UUID `json:"build_id"` @@ -320,20 +324,19 @@ type Device struct { Validated time.Time `json:"validated"` } +// Devices is a slice of Device structs type Devices []Device -type PositiveInteger int - +// DeviceSku is a struct // generated by "schematyper -o types/ResponseType_DeviceSku.go --package=types --ptr-for-omit DeviceSku.json" -- DO NOT EDIT - type DeviceSku struct { HardwareProductID UUID `json:"hardware_product_id"` ID UUID `json:"id"` Sku MojoStandardPlaceholder `json:"sku"` } +// HardwareProduct is a struct // generated by "schematyper -o types/ResponseType_HardwareProducts.go --package=types --ptr-for-omit HardwareProducts.json" -- DO NOT EDIT - type HardwareProduct struct { Alias MojoStandardPlaceholder `json:"alias"` Created time.Time `json:"created"` @@ -344,10 +347,11 @@ type HardwareProduct struct { Updated time.Time `json:"updated"` } +// HardwareProducts is a slice of HardwareProduct structs type HardwareProducts []HardwareProduct +// HardwareVendor is a struct // generated by "schematyper -o types/ResponseType_HardwareVendor.go --package=types --ptr-for-omit HardwareVendor.json" -- DO NOT EDIT - type HardwareVendor struct { Created time.Time `json:"created"` ID UUID `json:"id"` @@ -355,16 +359,17 @@ type HardwareVendor struct { Updated time.Time `json:"updated"` } +// HardwareVendors is a slice of HardwareVendor structs type HardwareVendors []HardwareVendor +// LoginToken is a struct // generated by "schematyper -o types/ResponseType_LoginToken.go --package=types --ptr-for-omit LoginToken.json" -- DO NOT EDIT - type LoginToken struct { JwtToken string `json:"jwt_token"` } +// Organization is a struct // generated by "schematyper -o types/ResponseType_Organization.go --package=types --ptr-for-omit Organization.json" -- DO NOT EDIT - type Organization struct { Builds []Build `json:"builds"` Created time.Time `json:"created"` @@ -375,18 +380,20 @@ type Organization struct { Role Role `json:"role,omitempty"` } +// Organizations is a slice of Organization structs type Organizations []Organization +// Ping is a struct // generated by "schematyper -o types/ResponseType_Ping.go --package=types --ptr-for-omit Ping.json" -- DO NOT EDIT - type Ping struct { Status interface{} `json:"status"` } +// DeviceAssetTag is a string // generated by "schematyper -o types/ResponseType_Racks.go --package=types --ptr-for-omit Racks.json" -- DO NOT EDIT - type DeviceAssetTag string +// Rack is a struct type Rack struct { AssetTag DeviceAssetTag `json:"asset_tag"` BuildID UUID `json:"build_id"` @@ -404,10 +411,11 @@ type Rack struct { Updated time.Time `json:"updated"` } +// Racks is a slice of Rack structs type Racks []Rack +// Relay is a struct // generated by "schematyper -o types/ResponseType_Relays.go --package=types --ptr-for-omit Relays.json" -- DO NOT EDIT - type Relay struct { Created time.Time `json:"created,omitempty"` ID UUID `json:"id,omitempty"` @@ -421,12 +429,14 @@ type Relay struct { Version string `json:"version,omitempty"` } +// Relays is a slice of Relay structs type Relays []Relay +// RelaySerialNumber is a string type RelaySerialNumber string +// ReportValidationResults is a struct // generated by "schematyper -o types/ResponseType_ReportValidationResults.go --package=types --ptr-for-omit ReportValidationResults.json" -- DO NOT EDIT - type ReportValidationResults struct { DeviceSerialNumber DeviceSerialNumber `json:"device_serial_number"` HardwareProductID UUID `json:"hardware_product_id"` @@ -435,11 +445,11 @@ type ReportValidationResults struct { Status ValidationStatus `json:"status"` } +// Role is a struct that corresponds to role_enum in the database // generated by "schematyper -o ResponseType_UserDetailed.go --package=types --ptr-for-omit UserDetailed.json" -- DO NOT EDIT - -// corresponds to role_enum in the database type Role string +// UserDetailed is a struct type UserDetailed struct { Builds Builds `json:"builds"` Created time.Time `json:"created"` @@ -454,6 +464,7 @@ type UserDetailed struct { RefuseSessionAuth bool `json:"refuse_session_auth"` } +// Users is a slice of structs type Users []struct { Created time.Time `json:"created"` Email EmailAddress `json:"email"` @@ -466,14 +477,15 @@ type Users []struct { RefuseSessionAuth bool `json:"refuse_session_auth"` } +// UserSetting is a string // generated by "schematyper -o ResponseType_UserSettings.go --package=types --ptr-for-omit UserSettings.json" -- DO NOT EDIT - type UserSetting string +// UserSettings is a map of string to UserSetting type UserSettings map[string]UserSetting +// NewUserTokenResponse is a struct // generated by "schematyper -o types/ResponseType_UserTokens.go --package=types --ptr-for-omit UserTokens.json" -- DO NOT EDIT - type NewUserTokenResponse struct { Name string `json:"name"` Created time.Time `json:"created"` @@ -483,6 +495,7 @@ type NewUserTokenResponse struct { Token string `json:"token"` } +// UserToken is a struct type UserToken struct { Created time.Time `json:"created"` Expires time.Time `json:"expires"` @@ -491,10 +504,11 @@ type UserToken struct { Name string `json:"name"` } +// UserTokens is a slice of UserToken structs type UserTokens []UserToken +// ValidationPlan is a struct // generated by "schematyper -o types/ResponseType_ValidationPlans.go --package=types --ptr-for-omit ValidationPlans.json" -- DO NOT EDIT - type ValidationPlan struct { Created time.Time `json:"created"` Description string `json:"description"` @@ -502,10 +516,11 @@ type ValidationPlan struct { Name MojoStandardPlaceholder `json:"name"` } +// ValidationPlans is a slice of ValidtionPlan structs type ValidationPlans []ValidationPlan +// ValidationResult is a struct // generated by "schematyper -o types/ResponseType_ValidationResults.go --package=types --ptr-for-omit ValidationResults.json" -- DO NOT EDIT - type ValidationResult struct { Category string `json:"category"` Component string `json:"component"` @@ -516,13 +531,15 @@ type ValidationResult struct { ValidationID UUID `json:"validation_id"` } +// ValidationResults is a slice of ValidationResult structs type ValidationResults []ValidationResult -// corresponds to validation_status_enum in the database +// ValidationStatus is a string that corresponds to validation_status_enum in +// the database type ValidationStatus string +// Validation is a struct // generated by "schematyper -o types/ResponseType_Validations.go --package=types --ptr-for-omit Validations.json" -- DO NOT EDIT - type Validation struct { Created time.Time `json:"created"` Deactivated interface{} `json:"deactivated"` @@ -533,10 +550,11 @@ type Validation struct { Version PositiveInteger `json:"version"` } +// Validations is a slice of Validation structs type Validations []Validation +// ValidationStateWithResults is a struct // generated by "schematyper -o types/ResponseType_ValidationStateWithResults.go --package=types --ptr-for-omit ValidationStateWithResults.json" -- DO NOT EDIT - type ValidationStateWithResults struct { Created time.Time `json:"created"` DeviceID UUID `json:"device_id"` @@ -547,12 +565,13 @@ type ValidationStateWithResults struct { Results ValidationResults `json:"results"` } +// Version is a struct // generated by "schematyper -o types/ResponseType_Version.go --package=types --ptr-for-omit Version.json" -- DO NOT EDIT - type Version struct { Version string `json:"version"` } +// RackRole is a struct // generated by "schematyper -o types/ResponseType_RackRoles.go --package=types --ptr-for-omit RackRoles.json" -- DO NOT EDIT type RackRole struct { Created time.Time `json:"created"` @@ -562,8 +581,10 @@ type RackRole struct { Updated time.Time `json:"updated"` } +// RackRoles is a slice of RackRole structs type RackRoles []RackRole +// RackLayout is a struct type RackLayout struct { Created time.Time `json:"created"` HardwareProductID UUID `json:"hardware_product_id"` @@ -576,8 +597,10 @@ type RackLayout struct { Updated time.Time `json:"updated"` } +// RackLayouts is a slice of RackLayout structs type RackLayouts []RackLayout +// RackAssignment is a struct type RackAssignment struct { DeviceAssetTag DeviceAssetTag `json:"device_asset_tag"` DeviceID UUID `json:"device_id"` @@ -588,4 +611,5 @@ type RackAssignment struct { Sku MojoStandardPlaceholder `json:"sku"` } +// RackAssignments is a slice of RackAssignment structs type RackAssignments []RackAssignment diff --git a/conch/types/templates.go b/conch/types/templates.go index 7a9c156..962c617 100644 --- a/conch/types/templates.go +++ b/conch/types/templates.go @@ -13,6 +13,8 @@ import ( func (bl Builds) Len() int { return len(bl) } func (bl Builds) Swap(i, j int) { bl[i], bl[j] = bl[j], bl[i] } func (bl Builds) Less(i, j int) bool { return bl[i].Name < bl[j].Name } + +// Headers returns the list of headers for the table view func (bl Builds) Headers() []string { return []string{ "Name", @@ -22,6 +24,7 @@ func (bl Builds) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (bl Builds) ForEach(do func([]string)) { for _, b := range bl { do([]string{ @@ -58,11 +61,14 @@ Links * Completed: {{ TimeStr .Completed }} by {{ .CompletedUser.Name }}({{ .CompletedUser.Email }}) ` +// Template returns a template string for rendering to Markdown func (b Build) Template() string { return buildTemplate } func (bu BuildUsers) Len() int { return len(bu) } func (bu BuildUsers) Swap(i, j int) { bu[i], bu[j] = bu[j], bu[i] } func (bu BuildUsers) Less(i, j int) bool { return bu[i].Name < bu[j].Name } + +// Headers returns the list of headers for the table view func (bu BuildUsers) Headers() []string { return []string{ "ID", @@ -72,6 +78,7 @@ func (bu BuildUsers) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (bu BuildUsers) ForEach(do func([]string)) { for _, u := range bu { do([]string{ @@ -86,6 +93,8 @@ func (bu BuildUsers) ForEach(do func([]string)) { func (bo BuildOrganizations) Len() int { return len(bo) } func (bo BuildOrganizations) Swap(i, j int) { bo[i], bo[j] = bo[j], bo[i] } func (bo BuildOrganizations) Less(i, j int) bool { return bo[i].Name < bo[j].Name } + +// Headers returns the list of headers for the table view func (bo BuildOrganizations) Headers() []string { return []string{ "ID", @@ -95,6 +104,7 @@ func (bo BuildOrganizations) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (bo BuildOrganizations) ForEach(do func([]string)) { for _, o := range bo { do([]string{ @@ -109,6 +119,8 @@ func (bo BuildOrganizations) ForEach(do func([]string)) { func (dl Datacenters) Len() int { return len(dl) } func (dl Datacenters) Swap(i, j int) { dl[i], dl[j] = dl[j], dl[i] } func (dl Datacenters) Less(i, j int) bool { return dl[i].VendorName < dl[j].VendorName } + +// Headers returns the list of headers for the table view func (dl Datacenters) Headers() []string { return []string{ "ID", @@ -119,6 +131,7 @@ func (dl Datacenters) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (dl Datacenters) ForEach(do func([]string)) { for _, d := range dl { do([]string{ @@ -145,6 +158,7 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (d Datacenter) Template() string { return datacenterTemplate } func (ds DeviceSettings) String() string { @@ -217,6 +231,7 @@ Disks:{{range $name, $slots := .Disks}} {{ end }}{{ end }} ` +// Template returns a template string for rendering to Markdown func (d DetailedDevice) Template() string { return detailedDeviceTemplate } const deviceTemplate = ` @@ -248,11 +263,14 @@ Links: {{ range .Links }} ` +// Template returns a template string for rendering to Markdown func (d Device) Template() string { return deviceTemplate } func (d Devices) Len() int { return len(d) } func (d Devices) Swap(i, j int) { d[i], d[j] = d[j], d[i] } func (d Devices) Less(i, j int) bool { return d[i].SerialNumber < d[j].SerialNumber } + +// Headers returns the list of headers for the table view func (d Devices) Headers() []string { return []string{ "Serial", @@ -265,6 +283,7 @@ func (d Devices) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (d Devices) ForEach(do func([]string)) { for _, device := range d { do([]string{ @@ -281,6 +300,7 @@ func (d Devices) ForEach(do func([]string)) { const deviceReportTemplate = `` +// Template returns a template string for rendering to Markdown func (d DeviceReport) Template() string { return deviceReportTemplate } const hardwareProductTemplate = ` @@ -298,6 +318,7 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (hp HardwareProduct) Template() string { return hardwareProductTemplate } // TODO sort interface, tabulable interface @@ -340,11 +361,14 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (h HardwareVendor) Template() string { return hardwareVendorTemplate } func (h HardwareVendors) Len() int { return len(h) } func (h HardwareVendors) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h HardwareVendors) Less(i, j int) bool { return h[i].Name < h[j].Name } + +// Headers returns the list of headers for the table view func (h HardwareVendors) Headers() []string { return []string{ "Name", @@ -354,6 +378,7 @@ func (h HardwareVendors) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (h HardwareVendors) ForEach(do func([]string)) { for _, v := range h { do([]string{ @@ -372,11 +397,14 @@ ID: {{ .ID }} Description: {{ .Description }} ` +// Template returns a template string for rendering to Markdown func (o Organization) Template() string { return organizationTemplate } func (o Organizations) Len() int { return len(o) } func (o Organizations) Swap(i, j int) { o[i], o[j] = o[j], o[i] } func (o Organizations) Less(i, j int) bool { return o[i].Name < o[j].Name } + +// Headers returns the list of headers for the table view func (o Organizations) Headers() []string { return []string{ "Name", @@ -385,6 +413,7 @@ func (o Organizations) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (o Organizations) ForEach(do func([]string)) { for _, org := range o { do([]string{ @@ -412,11 +441,14 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (r Rack) Template() string { return rackTemplate } -func (r Racks) Len() int { return len(r) } -func (r Racks) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r Racks) Less(i, j int) bool { return r[i].SerialNumber > r[j].SerialNumber } +func (rl Racks) Len() int { return len(rl) } +func (rl Racks) Swap(i, j int) { rl[i], rl[j] = rl[j], rl[i] } +func (rl Racks) Less(i, j int) bool { return rl[i].SerialNumber > rl[j].SerialNumber } + +// Headers returns the list of headers for the table view func (rl Racks) Headers() []string { return []string{ "ID", @@ -431,6 +463,7 @@ func (rl Racks) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (rl Racks) ForEach(do func([]string)) { for _, r := range rl { do([]string{ @@ -447,10 +480,11 @@ func (rl Racks) ForEach(do func([]string)) { } } -func (r RackLayouts) Len() int { return len(r) } -func (r RackLayouts) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r RackLayouts) Less(i, j int) bool { return r[i].RackUnitStart > r[j].RackUnitStart } +func (rl RackLayouts) Len() int { return len(rl) } +func (rl RackLayouts) Swap(i, j int) { rl[i], rl[j] = rl[j], rl[i] } +func (rl RackLayouts) Less(i, j int) bool { return rl[i].RackUnitStart > rl[j].RackUnitStart } +// Headers returns the list of headers for the table view func (rl RackLayouts) Headers() []string { return []string{ "Rack Unit Start", @@ -462,6 +496,7 @@ func (rl RackLayouts) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (rl RackLayouts) ForEach(do func([]string)) { for _, r := range rl { do([]string{ @@ -479,6 +514,7 @@ func (ra RackAssignments) Len() int { return len(ra) } func (ra RackAssignments) Swap(i, j int) { ra[i], ra[j] = ra[j], ra[i] } func (ra RackAssignments) Less(i, j int) bool { return ra[i].RackUnitStart > ra[j].RackUnitStart } +// Headers returns the list of headers for the table view func (ra RackAssignments) Headers() []string { return []string{ "Device Serial", @@ -489,6 +525,7 @@ func (ra RackAssignments) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (ra RackAssignments) ForEach(do func([]string)) { for _, r := range ra { do([]string{ @@ -501,9 +538,9 @@ func (ra RackAssignments) ForEach(do func([]string)) { } } -func (r RackRoles) Len() int { return len(r) } -func (r RackRoles) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r RackRoles) Less(i, j int) bool { return r[i].Name < r[j].Name } +func (rl RackRoles) Len() int { return len(rl) } +func (rl RackRoles) Swap(i, j int) { rl[i], rl[j] = rl[j], rl[i] } +func (rl RackRoles) Less(i, j int) bool { return rl[i].Name < rl[j].Name } func (rl RackRoles) String() string { sort.Sort(rl) @@ -541,6 +578,7 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (r RackRole) Template() string { return rackRoleTemplate } const relayTemplate = ` @@ -558,11 +596,12 @@ IP Address: {{ .IpAddr }} SSH Port: {{ .SshPort }} ` +// Template returns a template string for rendering to Markdown func (r Relay) Template() string { return relayTemplate } -func (r Relays) Len() int { return len(r) } -func (r Relays) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r Relays) Less(i, j int) bool { return r[i].Updated.Before(r[j].Updated) } +func (rl Relays) Len() int { return len(rl) } +func (rl Relays) Swap(i, j int) { rl[i], rl[j] = rl[j], rl[i] } +func (rl Relays) Less(i, j int) bool { return rl[i].Updated.Before(rl[j].Updated) } func (rl Relays) String() string { sort.Sort(rl) @@ -606,12 +645,14 @@ Created: {{ TimeStr .Created }} Updated: {{ TimeStr .Updated }} ` +// Template returns a template string for rendering to Markdown func (r DatacenterRoomDetailed) Template() string { return roomTemplate } func (dr DatacenterRoomsDetailed) Len() int { return len(dr) } func (dr DatacenterRoomsDetailed) Swap(i, j int) { dr[i], dr[j] = dr[j], dr[i] } func (dr DatacenterRoomsDetailed) Less(i, j int) bool { return dr[i].Alias < dr[j].Alias } +// Headers returns the list of headers for the table view func (dr DatacenterRoomsDetailed) Headers() []string { return []string{ "ID", @@ -624,6 +665,7 @@ func (dr DatacenterRoomsDetailed) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (dr DatacenterRoomsDetailed) ForEach(do func([]string)) { for _, r := range dr { do([]string{ @@ -638,6 +680,7 @@ func (dr DatacenterRoomsDetailed) ForEach(do func([]string)) { } } +// Headers returns the list of headers for the table view func (u UserSettings) Headers() []string { return []string{ "Key", @@ -645,6 +688,7 @@ func (u UserSettings) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (u UserSettings) ForEach(do func([]string)) { keys := make([]string, 0) for setting := range u { @@ -678,6 +722,7 @@ Organizations {{ Table .Organizations }} ` +// Template returns a template string for rendering to Markdown func (u UserDetailed) Template() string { return detailedUserTemplate } const validationPlanTemplate = ` @@ -690,6 +735,7 @@ Description: {{ .Description }} Created: {{ .Created }} ` +// Template returns a template string for rendering to Markdown func (v ValidationPlan) Template() string { return validationPlanTemplate } func (v ValidationPlans) Len() int { return len(v) } @@ -737,6 +783,7 @@ Results: {{ .Results }} ` +// Template returns a template string for rendering to Markdown func (v ValidationStateWithResults) Template() string { return validationStateWithResultsTemplate } func (v ValidationResults) Len() int { return len(v) } @@ -786,6 +833,7 @@ State: {{ .State }} Device ID: {{ .DeviceID }} ` +// Template returns a template string for rendering to Markdown func (dn DeviceNic) Template() string { return deviceNicTemplate } const deviceLocationTemplate = ` @@ -798,11 +846,14 @@ DatacenterRoom: {{ .DatacenterRoom }} AZ: {{ .Az }} ` +// Template returns a template string for rendering to Markdown func (dl DeviceLocation) Template() string { return deviceLocationTemplate } func (ul UsersTerse) Len() int { return len(ul) } func (ul UsersTerse) Swap(i, j int) { ul[i], ul[j] = ul[j], ul[i] } func (ul UsersTerse) Less(i, j int) bool { return ul[i].Name < ul[j].Name } + +// Headers returns the list of headers for the table view func (ul UsersTerse) Headers() []string { return []string{ "Name", @@ -810,6 +861,7 @@ func (ul UsersTerse) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (ul UsersTerse) ForEach(do func([]string)) { for _, u := range ul { do([]string{ @@ -834,6 +886,7 @@ Token {{ .Name }} * Expires: {{ TimeStr .Expires }} ` +// Template returns a template string for rendering to Markdown func (ut UserToken) Template() string { return userTokenTemplate } const newUserTokenTemplate = ` @@ -857,11 +910,14 @@ THIS IS THE ONLY TIME IT WILL BE PRINTED, PLEASE RECORD IT NOW ` +// Template returns a template string for rendering to Markdown func (ut NewUserTokenResponse) Template() string { return newUserTokenTemplate } func (ul UserTokens) Len() int { return len(ul) } func (ul UserTokens) Swap(i, j int) { ul[i], ul[j] = ul[j], ul[i] } func (ul UserTokens) Less(i, j int) bool { return ul[i].Name < ul[j].Name } + +// Headers returns the list of headers for the table view func (ul UserTokens) Headers() []string { return []string{ "Name", @@ -872,6 +928,7 @@ func (ul UserTokens) Headers() []string { } } +// ForEach iterates over each item in the list and applies a function to it func (ul UserTokens) ForEach(do func([]string)) { for _, u := range ul { do([]string{ diff --git a/logger/logger.go b/logger/logger.go index 932c8f5..ecb059c 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -16,14 +16,20 @@ import ( // for developer targeted output. While Info is for (verbose) user targeted // output. type Interface interface { + // Debug outputs developer targeted messaging. Debug(...interface{}) + // Info outputs more verbose user targed information Info(...interface{}) } +// NullLogger is a default logger that doesn't output anything. type NullLogger struct{} +// Debug outputs developer targeted messaging. func (nl NullLogger) Debug(msgs ...interface{}) {} -func (nl NullLogger) Info(msgs ...interface{}) {} + +// Info outputs more verbose user targed information +func (nl NullLogger) Info(msgs ...interface{}) {} // Logger is the default logger with configuration levels for debug (developer) // output, and info (verbose user) output.