Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
make golint happy
Browse files Browse the repository at this point in the history
This is a quick pass to stub in docs based on golint. The docs are
hardly complete, but they are a start.
  • Loading branch information
perigrin committed Nov 17, 2020
1 parent da97474 commit 366337e
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 128 deletions.
4 changes: 4 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ 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
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 {
Expand Down
27 changes: 14 additions & 13 deletions conch/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
16 changes: 10 additions & 6 deletions conch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
}
Expand All @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions conch/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,64 @@ 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 {
links = append(links, Link(u))
}
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
Loading

0 comments on commit 366337e

Please sign in to comment.