Skip to content

Commit

Permalink
Require a clean golint
Browse files Browse the repository at this point in the history
Some of my comments/changes might not be great, but its better than
where we were!
  • Loading branch information
eparis committed Sep 25, 2015
1 parent 8471a10 commit 9eb227f
Show file tree
Hide file tree
Showing 27 changed files with 230 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ install:
- mkdir -p $HOME/gopath/src/k8s.io
- mv $TRAVIS_BUILD_DIR $HOME/gopath/src/k8s.io/contrib
- go get github.com/tools/godep
- go get github.com/golang/lint/golint
- export PATH=$GOPATH/bin:$PATH
- godep go install ./...


script:
- hack/verify-all.sh
- godep go test ./...
Expand Down
20 changes: 9 additions & 11 deletions diurnal/dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ func parseTimeCounts(times string, counts string) ([]timeCount, error) {
return tc, nil
}

type Scaler struct {
type scaler struct {
timeCounts []timeCount
selector labels.Selector
start time.Time
pos int
done chan struct{}
}

var posError = errors.New("could not find position")

func findPos(tc []timeCount, cur int, offset time.Duration) int {
first := true
for i := cur; i != cur || first; i = (i + 1) % len(tc) {
Expand All @@ -127,7 +125,7 @@ func findPos(tc []timeCount, cur int, offset time.Duration) int {
return 0
}

func (s *Scaler) setCount(c int) {
func (s *scaler) setCount(c int) {
glog.Infof("scaling to %d replicas", c)
rcList, err := client.ReplicationControllers(namespace).List(s.selector)
if err != nil {
Expand All @@ -142,15 +140,15 @@ func (s *Scaler) setCount(c int) {
}
}

func (s *Scaler) timeOffset() time.Duration {
func (s *scaler) timeOffset() time.Duration {
return time.Since(s.start) % dayPeriod
}

func (s *Scaler) curpos(offset time.Duration) int {
func (s *scaler) curpos(offset time.Duration) int {
return findPos(s.timeCounts, s.pos, offset)
}

func (s *Scaler) scale() {
func (s *scaler) scale() {
for {
select {
case <-s.done:
Expand All @@ -168,7 +166,7 @@ func (s *Scaler) scale() {
}
}

func (s *Scaler) Start() error {
func (s *scaler) Start() error {
now := time.Now().UTC()
s.start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
if *startNow {
Expand Down Expand Up @@ -196,7 +194,7 @@ func safeclose(c chan<- struct{}) (err error) {
return nil
}

func (s *Scaler) Stop() error {
func (s *scaler) Stop() error {
if err := safeclose(s.done); err != nil {
return errors.New("already stopped scaling")
}
Expand All @@ -211,7 +209,7 @@ var (
local = flag.Bool("local", false, "set to true if running on local machine not within cluster")
localPort = flag.Int("localport", 8001, "port that kubectl proxy is running on (local must be true)")

namespace string = os.Getenv("POD_NAMESPACE")
namespace = os.Getenv("POD_NAMESPACE")

client *kclient.Client
)
Expand Down Expand Up @@ -259,7 +257,7 @@ func main() {
if namespace == "" {
glog.Fatal("POD_NAMESPACE is not set. Set to the namespace of the replication controller if running locally.")
}
scaler := Scaler{timeCounts: tc, selector: selector}
scaler := scaler{timeCounts: tc, selector: selector}
if err != nil {
glog.Fatal(err)
}
Expand Down
14 changes: 7 additions & 7 deletions for-demos/serve_hostname/serve_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (
)

var (
doTcp = flag.Bool("tcp", false, "Serve raw over TCP.")
doUdp = flag.Bool("udp", false, "Serve raw over UDP.")
doHttp = flag.Bool("http", true, "Serve HTTP.")
doTCP = flag.Bool("tcp", false, "Serve raw over TCP.")
doUDP = flag.Bool("udp", false, "Serve raw over UDP.")
doHTTP = flag.Bool("http", true, "Serve HTTP.")
port = flag.Int("port", 9376, "Port number.")
)

func main() {
flag.Parse()

if *doHttp && (*doTcp || *doUdp) {
if *doHTTP && (*doTCP || *doUDP) {
log.Fatalf("Can't server TCP/UDP mode and HTTP mode at the same time")
}

Expand All @@ -45,7 +45,7 @@ func main() {
log.Fatalf("Error from os.Hostname(): %s", err)
}

if *doTcp {
if *doTCP {
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("Error from net.Listen(): %s", err)
Expand All @@ -62,7 +62,7 @@ func main() {
}
}()
}
if *doUdp {
if *doUDP {
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("Error from net.ResolveUDPAddr(): %s", err)
Expand All @@ -83,7 +83,7 @@ func main() {
}
}()
}
if *doHttp {
if *doHTTP {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("HTTP request from %s", r.RemoteAddr)
fmt.Fprintf(w, "%s", hostname)
Expand Down
Loading

0 comments on commit 9eb227f

Please sign in to comment.