Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #5

Merged
merged 2 commits into from
Aug 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func getEC2Instances(config map[string]string) (instances Instances) {
config["region"] = "us-east-1"
}

auth := aws.Auth{config["access_key"], config["secret_key"]}
auth := aws.Auth{AccessKey: config["access_key"], SecretKey: config["secret_key"]}

e := ec2.New(auth, aws.Regions[config["region"]])
resp, err := e.Instances(nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"gopkg.in/yaml.v1"
"gopkg.in/yaml.v1"
"io/ioutil"
"log"
"os"
Expand Down
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"sort"
)

type Tag struct {
Expand Down Expand Up @@ -58,9 +58,10 @@ func getInstances(config Config) (clouds CloudInstances) {
}

type SortByTagValue []StrMap

func (a SortByTagValue) Len() int { return len(a) }
func (a SortByTagValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByTagValue) Less(i, j int) bool { return a[i]["tag_value"] < a[j]["tag_value"]}
func (a SortByTagValue) Less(i, j int) bool { return a[i]["tag_value"] < a[j]["tag_value"] }

func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap) {
// Fuzzy matching, like SublimeText
Expand All @@ -74,7 +75,7 @@ func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap
if rHost.MatchString(cloud + tag.Value) {
matched = append(matched, StrMap{
"cloud": cloud,
"addr": addr,
"addr": addr,
"tag_name": tag.Name,
"tag_value": tag.Value,
})
Expand All @@ -84,10 +85,10 @@ func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap
}
}
}

sort.Sort(SortByTagValue(matched))

return
return
}

func formatMatchedInstance(inst StrMap) string {
Expand All @@ -104,7 +105,7 @@ func main() {

match := getMatchedInstances(instances, hostname)

var matched_instance map[string]string
var matched_instance map[string]string

if len(match) == 0 {
fmt.Println("Can't find cloud instance, trying to connect anyway")
Expand Down Expand Up @@ -137,7 +138,7 @@ func main() {
fmt.Println("Connecting to instance:")
fmt.Println(formatMatchedInstance(matched_instance))
}

if len(args) == 0 {
args = append(args, joinHostname(user, hostname))
} else {
Expand Down