Add comments to exported types to pass go-lint

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-23 13:08:08 -04:00
parent be51da44bf
commit 161fc48b5a
7 changed files with 35 additions and 5 deletions

View File

@ -13,11 +13,13 @@ import (
portainer "github.com/portainer/portainer/api"
)
// StackListFilter represents a filter for a stack list
type StackListFilter struct {
SwarmID string `json:"SwarmId,omitempty"`
EndpointID portainer.EndpointID `json:"EndpointId,omitempty"`
}
// Config represents a Portainer client configuration
type Config struct {
URL *url.URL
User string
@ -27,6 +29,7 @@ type Config struct {
DoNotUseToken bool
}
// PortainerClient represents a Portainer API client
type PortainerClient interface {
// Authenticate a user to get an auth token
Authenticate() (token string, err error)
@ -305,7 +308,7 @@ func (n *portainerClientImp) GetStatus() (status portainer.Status, err error) {
return
}
// Create a new client
// NewClient creates a new Portainer API client
func NewClient(httpClient *http.Client, config Config) PortainerClient {
return &portainerClientImp{
httpClient: httpClient,

View File

@ -6,6 +6,7 @@ import (
portainer "github.com/portainer/portainer/api"
)
// GetTranslatedStackType returns a stack's Type field (int) translated to it's human readable form (string)
func GetTranslatedStackType(s portainer.Stack) string {
switch s.Type {
case 1:
@ -17,6 +18,7 @@ func GetTranslatedStackType(s portainer.Stack) string {
}
}
// StackCreateRequest represents the body of a request to POST /stacks
type StackCreateRequest struct {
Name string
SwarmID string
@ -24,16 +26,19 @@ type StackCreateRequest struct {
Env []portainer.Pair `json:",omitempty"`
}
// StackUpdateRequest represents the body of a request to PUT /stacks/{id}
type StackUpdateRequest struct {
StackFileContent string
Env []portainer.Pair `json:",omitempty"`
Prune bool
}
// StackFileInspectResponse represents the body of a response for a request to GET /stack/{id}/file
type StackFileInspectResponse struct {
StackFileContent string
}
// GenericError represents the body of a generic error returned by the Portainer API
type GenericError struct {
Err string
Details string
@ -47,11 +52,13 @@ func (e *GenericError) Error() string {
}
}
// AuthenticateUserRequest represents the body of a request to POST /auth
type AuthenticateUserRequest struct {
Username string
Password string
}
// AuthenticateUserResponse represents the body of a response for a request to POST /auth
type AuthenticateUserResponse struct {
Jwt string
}

View File

@ -18,7 +18,7 @@ import (
var cachedClient client.PortainerClient
// Get the cached client or a new one
// GetClient returns the cached Portainer API client. If none is present, creates and returns a new one).
func GetClient() (c client.PortainerClient, err error) {
if cachedClient == nil {
cachedClient, err = GetDefaultClient()
@ -29,7 +29,7 @@ func GetClient() (c client.PortainerClient, err error) {
return cachedClient, nil
}
// Get the default client
// GetDefaultClient returns a new Portainer API client with the default configuration
func GetDefaultClient() (c client.PortainerClient, err error) {
config, err := GetDefaultClientConfig()
if err != nil {
@ -82,7 +82,7 @@ func GetDefaultClient() (c client.PortainerClient, err error) {
return
}
// Get the default config for a client
// GetDefaultClientConfig returns the default configuration for a Portainer API client
func GetDefaultClientConfig() (config client.Config, err error) {
apiURL, err := url.Parse(strings.TrimRight(viper.GetString("url"), "/") + "/api/")
if err != nil {
@ -101,7 +101,7 @@ func GetDefaultClientConfig() (config client.Config, err error) {
return
}
// Get the default http client for a Portainer client
// GetDefaultHTTPClient returns the default HTTP client for a Portainer API client
func GetDefaultHTTPClient() *http.Client {
return &http.Client{
Timeout: viper.GetDuration("timeout"),

View File

@ -8,6 +8,7 @@ import (
"github.com/spf13/viper"
)
// LoadCofig loads the configuration file currently used by viper into a new viper instance
func LoadCofig() (v *viper.Viper, err error) {
// Set config file name
var configFile string
@ -34,6 +35,7 @@ func LoadCofig() (v *viper.Viper, err error) {
return
}
// CheckConfigKeyExists checks a given configuration key exists in the default viper
func CheckConfigKeyExists(key string) (keyExists bool) {
for _, k := range viper.AllKeys() {
if k == key {

View File

@ -7,6 +7,7 @@ import (
"text/tabwriter"
)
// NewTabWriter returns a new tabwriter.Writer
func NewTabWriter(headers []string) (*tabwriter.Writer, error) {
writer := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
_, err := fmt.Fprintln(writer, strings.Join(headers, "\t"))

View File

@ -8,6 +8,7 @@ import (
"github.com/sirupsen/logrus"
)
// Common errors
const (
ErrStackNotFound = Error("Stack not found")
ErrStackClusterNotFound = Error("Stack cluster not found")
@ -29,6 +30,7 @@ func (e Error) Error() string {
return string(e)
}
// GetDefaultEndpoint returns the default endpoint (if only one endpoint exists)
func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
portainerClient, err := GetClient()
if err != nil {
@ -53,6 +55,8 @@ func GetDefaultEndpoint() (endpoint portainer.Endpoint, err error) {
return
}
// GetStackByName returns a stack by its name from the (endpoint filtered) list
// of all stacks
func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID) (stack portainer.Stack, err error) {
portainerClient, err := GetClient()
if err != nil {
@ -73,6 +77,8 @@ func GetStackByName(name string, swarmID string, endpointID portainer.EndpointID
return
}
// GetEndpointByName returns an endpoint by its name from the list of all
// endpoints
func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
portainerClient, err := GetClient()
if err != nil {
@ -93,6 +99,8 @@ func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
return
}
// GetEndpointGroupByName returns an endpoint group by its name from the list
// of all endpoint groups
func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup, err error) {
portainerClient, err := GetClient()
if err != nil {
@ -113,6 +121,8 @@ func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup,
return
}
// GetEndpointFromListByID returns an endpoint by its id from a list of
// endpoints
func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
for i := range endpoints {
if endpoints[i].ID == id {
@ -122,6 +132,8 @@ func GetEndpointFromListByID(endpoints []portainer.Endpoint, id portainer.Endpoi
return endpoint, ErrEndpointNotFound
}
// GetEndpointFromListByName returns an endpoint by its name from a list of
// endpoints
func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (endpoint portainer.Endpoint, err error) {
for i := range endpoints {
if endpoints[i].Name == name {
@ -131,6 +143,7 @@ func GetEndpointFromListByName(endpoints []portainer.Endpoint, name string) (end
return endpoint, ErrEndpointNotFound
}
// GetEndpointSwarmClusterID returns an endpoint's swarm cluster id
func GetEndpointSwarmClusterID(endpointID portainer.EndpointID) (endpointSwarmClusterID string, err error) {
// Get docker information for endpoint
portainerClient, err := GetClient()
@ -167,6 +180,7 @@ func selectValue(jsonMap map[string]interface{}, jsonPath []string) (interface{}
}
}
// GetFormatHelp returns the help string for --format flags
func GetFormatHelp(v interface{}) (r string) {
typeOfV := reflect.TypeOf(v)
r = fmt.Sprintf(`

View File

@ -19,6 +19,7 @@ var (
buildDate string
)
// BuildVersionString returns the tool's version
func BuildVersionString() string {
osArch := runtime.GOOS + "/" + runtime.GOARCH
@ -33,6 +34,8 @@ func BuildVersionString() string {
return fmt.Sprintf("%s %s %s BuildDate: %s", programName, version, osArch, buildDate)
}
// BuildUseAgentString returns the tool's User-Agent in requests to the
// Portainer API
func BuildUseAgentString() string {
var theVersion = version
if theVersion == "" {