Fixes golint errors in pkg/kubecfg

pull/6/head
Yuki Sonoda (Yugui) 2014-07-10 20:48:48 +09:00
parent 056f871bed
commit 2d888539dc
5 changed files with 30 additions and 22 deletions

View File

@ -39,7 +39,7 @@ func promptForString(field string) string {
return result
}
// Parse an AuthInfo object from a file path. Prompt user and create file if it doesn't exist.
// LoadAuthInfo parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.
func LoadAuthInfo(path string) (*client.AuthInfo, error) {
var auth client.AuthInfo
if _, err := os.Stat(path); os.IsNotExist(err) {
@ -63,7 +63,7 @@ func LoadAuthInfo(path string) (*client.AuthInfo, error) {
return &auth, err
}
// Perform a rolling update of a collection of pods.
// Update performs a rolling update of a collection of pods.
// 'name' points to a replication controller.
// 'client' is used for updating pods.
// 'updatePeriod' is the time between pod updates.

View File

@ -29,9 +29,8 @@ var storageToType = map[string]reflect.Type{
"replicationControllers": reflect.TypeOf(api.ReplicationController{}),
}
// Takes input 'data' as either json or yaml, checks that it parses as the
// appropriate object type, and returns json for sending to the API or an
// error.
// ToWireFormat takes input 'data' as either json or yaml, checks that it parses as the
// appropriate object type, and returns json for sending to the API or an error.
func ToWireFormat(data []byte, storage string) ([]byte, error) {
prototypeType, found := storageToType[storage]
if !found {

View File

@ -31,26 +31,26 @@ func TestParseBadStorage(t *testing.T) {
}
func DoParseTest(t *testing.T, storage string, obj interface{}) {
json_data, _ := api.Encode(obj)
yaml_data, _ := yaml.Marshal(obj)
t.Logf("Intermediate yaml:\n%v\n", string(yaml_data))
jsonData, _ := api.Encode(obj)
yamlData, _ := yaml.Marshal(obj)
t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
json_got, json_err := ToWireFormat(json_data, storage)
yaml_got, yaml_err := ToWireFormat(yaml_data, storage)
jsonGot, jsonErr := ToWireFormat(jsonData, storage)
yamlGot, yamlErr := ToWireFormat(yamlData, storage)
if json_err != nil {
t.Errorf("json err: %#v", json_err)
if jsonErr != nil {
t.Errorf("json err: %#v", jsonErr)
}
if yaml_err != nil {
t.Errorf("yaml err: %#v", yaml_err)
if yamlErr != nil {
t.Errorf("yaml err: %#v", yamlErr)
}
if string(json_got) != string(json_data) {
if string(jsonGot) != string(jsonData) {
t.Errorf("json output didn't match:\nGot:\n%v\n\nWanted:\n%v\n",
string(json_got), string(json_data))
string(jsonGot), string(jsonData))
}
if string(yaml_got) != string(json_data) {
if string(yamlGot) != string(jsonData) {
t.Errorf("yaml parsed output didn't match:\nGot:\n%v\n\nWanted:\n%v\n",
string(yaml_got), string(json_data))
string(yamlGot), string(jsonData))
}
}

View File

@ -24,6 +24,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
// ProxyServer is a http.Handler which proxies Kubenetes APIs to remote API server.
type ProxyServer struct {
Host string
Auth *client.AuthInfo
@ -34,6 +35,8 @@ func makeFileHandler(prefix, base string) http.Handler {
return http.StripPrefix(prefix, http.FileServer(http.Dir(base)))
}
// NewProxyServer creates and installs a new ProxyServer.
// It automatically registers the created ProxyServer to http.DefaultServeMux.
func NewProxyServer(filebase, host string, auth *client.AuthInfo) *ProxyServer {
server := &ProxyServer{
Host: host,
@ -45,7 +48,7 @@ func NewProxyServer(filebase, host string, auth *client.AuthInfo) *ProxyServer {
return server
}
// Starts the server, loops forever.
// Serve starts the server (http.DefaultServeMux) on TCP port 8001, loops forever.
func (s *ProxyServer) Serve() error {
return http.ListenAndServe(":8001", nil)
}

View File

@ -35,14 +35,16 @@ type ResourcePrinter interface {
PrintObj(interface{}, io.Writer) error
}
// Identity printer simply copies the body out to the output stream
// IdentityPrinter is an implementation of ResourcePrinter which simply copies the body out to the output stream
type IdentityPrinter struct{}
// Print is an implementation of ResourcePrinter.Print which simply writes the data to the Writer.
func (i *IdentityPrinter) Print(data []byte, w io.Writer) error {
_, err := w.Write(data)
return err
}
// PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer.
func (i *IdentityPrinter) PrintObj(obj interface{}, output io.Writer) error {
data, err := api.Encode(obj)
if err != nil {
@ -51,9 +53,10 @@ func (i *IdentityPrinter) PrintObj(obj interface{}, output io.Writer) error {
return i.Print(data, output)
}
// YAMLPrinter parses JSON, and re-formats as YAML
// YAMLPrinter is an implementation of ResourcePrinter which parsess JSON, and re-formats as YAML
type YAMLPrinter struct{}
// Print parses the data as JSON, re-formats as YAML and prints the YAML.
func (y *YAMLPrinter) Print(data []byte, w io.Writer) error {
var obj interface{}
if err := json.Unmarshal(data, &obj); err != nil {
@ -67,6 +70,7 @@ func (y *YAMLPrinter) Print(data []byte, w io.Writer) error {
return err
}
// PrintObj prints the data as YAML.
func (y *YAMLPrinter) PrintObj(obj interface{}, w io.Writer) error {
output, err := yaml.Marshal(obj)
if err != nil {
@ -76,7 +80,7 @@ func (y *YAMLPrinter) PrintObj(obj interface{}, w io.Writer) error {
return err
}
// HumanReadablePrinter attempts to provide more elegant output
// HumanReadablePrinter is an implementation of ResourcePrinter which attempts to provide more elegant output.
type HumanReadablePrinter struct{}
var podColumns = []string{"Name", "Image(s)", "Host", "Labels"}
@ -177,6 +181,7 @@ func (h *HumanReadablePrinter) printStatus(status *api.Status, w io.Writer) erro
return err
}
// Print parses the data as JSON, then prints the parsed data in a human-friendly format according to the type of the data.
func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error {
var mapObj map[string]interface{}
if err := json.Unmarshal([]byte(data), &mapObj); err != nil {
@ -194,6 +199,7 @@ func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error {
return h.PrintObj(obj, output)
}
// PrintObj prints the obj in a human-friendly format according to the type of the obj.
func (h *HumanReadablePrinter) PrintObj(obj interface{}, output io.Writer) error {
w := tabwriter.NewWriter(output, 20, 5, 3, ' ', 0)
defer w.Flush()