Skip to content

Commit

Permalink
closes #52 migrate from dep to go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gbolo committed Aug 11, 2020
1 parent f55b235 commit f9ad216
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.11.x
- 1.13.x

services:
- docker
Expand Down
228 changes: 0 additions & 228 deletions Gopkg.lock

This file was deleted.

42 changes: 0 additions & 42 deletions Gopkg.toml

This file was deleted.

11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ $(BIN):

$(BIN)/%: | $(BIN) ; $(info $(M) building $(REPOSITORY)...)
$Q tmp=$$(mktemp -d); \
env GO111MODULE=off GOCACHE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(REPOSITORY) \
env GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(REPOSITORY) \
|| ret=$$?; \
rm -rf $$tmp ; exit $$ret

DEP = $(BIN)/dep
$(BIN)/dep: REPOSITORY=github.com/golang/dep/cmd/dep

GOIMPORTS = $(BIN)/goimports
$(BIN)/goimports: REPOSITORY=golang.org/x/tools/cmd/goimports

Expand All @@ -39,7 +36,7 @@ $(BIN)/golint: REPOSITORY=golang.org/x/lint/golint
# Targets for our app --------------------------------------------------------------------------------------------------

.PHONY: all
all: $(BIN) fmt dep frontend backend; @ ## Build both backend and frontend
all: $(BIN) frontend backend; @ ## Build both backend and frontend

.PHONY: backend
backend: ; $(info $(M) building backend executable...) @ ## Build backend binary
Expand All @@ -54,10 +51,6 @@ frontend: ; $(info $(M) building web frontend ui...) @ ## Build frontend
$Q npm install --prefix $(FRONTEND) \
&& npm run build --prefix $(FRONTEND)

.PHONY: dep
dep: | $(DEP) ; $(info $(M) running dep...) @ ## Run dep ensure to fetch dependencies
$Q $(DEP) ensure -v

.PHONY: fmt
fmt: ; $(info $(M) running gofmt...) @ ## Run gofmt on all source files
$Q $(GO) fmt ./...
Expand Down
15 changes: 8 additions & 7 deletions backend/aws.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backend

import (
"context"
"encoding/json"
"fmt"
"strconv"
Expand Down Expand Up @@ -28,7 +29,7 @@ const (

var (
// global aws clients (based on regions)
awsClients map[string]*ec2.EC2
awsClients map[string]*ec2.Client
// global cached env list
cachedTable envList
// lock to prevent concurrent refreshes
Expand Down Expand Up @@ -294,7 +295,7 @@ func refreshTable() (err error) {

for region, awsSvcClient := range awsClients {
req := awsSvcClient.DescribeInstancesRequest(params)
resp, respErr := req.Send()
resp, respErr := req.Send(context.Background())
if respErr != nil {
log.Errorf("failed to describe instances, %s, %v", region, respErr)
err = respErr
Expand Down Expand Up @@ -365,7 +366,7 @@ func getInstanceIDs(envID, state string) (instanceIds []string) {
}

// toggleInstances can start or stop a list of instances
func toggleInstances(instanceIDs []string, desiredState string, awsClient *ec2.EC2) (response []byte, err error) {
func toggleInstances(instanceIDs []string, desiredState string, awsClient *ec2.Client) (response []byte, err error) {
if len(instanceIDs) < 1 {
err = fmt.Errorf("no instanceIDs have been provided")
return
Expand All @@ -380,7 +381,7 @@ func toggleInstances(instanceIDs []string, desiredState string, awsClient *ec2.E
}

req := awsClient.StartInstancesRequest(input)
awsResponse, reqErr := req.Send()
awsResponse, reqErr := req.Send(context.Background())
response, _ = json.MarshalIndent(awsResponse, "", " ")
err = reqErr
if experimentalEnabled && err == nil {
Expand All @@ -396,7 +397,7 @@ func toggleInstances(instanceIDs []string, desiredState string, awsClient *ec2.E
}

req := awsClient.StopInstancesRequest(input)
awsResponse, reqErr := req.Send()
awsResponse, reqErr := req.Send(context.Background())
response, _ = json.MarshalIndent(awsResponse, "", " ")
err = reqErr
if experimentalEnabled && err == nil {
Expand Down Expand Up @@ -550,7 +551,7 @@ func getEnvironmentByID(envID string) (environment, bool) {
}

// returns awsClient for the specific environment ID
func getEnvironmentAwsClient(envID string) *ec2.EC2 {
func getEnvironmentAwsClient(envID string) *ec2.Client {
for _, env := range cachedTable {
if env.ID == envID {
return awsClients[env.Region]
Expand All @@ -560,7 +561,7 @@ func getEnvironmentAwsClient(envID string) *ec2.EC2 {
}

// returns awsClient for the specific environment ID
func getInstanceAwsClient(instanceID string) *ec2.EC2 {
func getInstanceAwsClient(instanceID string) *ec2.Client {
for _, env := range cachedTable {
for _, instance := range env.Instances {
if instance.ID == instanceID {
Expand Down
2 changes: 1 addition & 1 deletion backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func StartBackendDeamon(cfgFile string) {
log.Fatalf("failed to load config, %v", err)
}

awsClients = make(map[string]*ec2.EC2, len(awsRegions))
awsClients = make(map[string]*ec2.Client, len(awsRegions))
for _, region := range awsRegions {
if region != "" {
cfg.Region = region
Expand Down
Loading

0 comments on commit f9ad216

Please sign in to comment.