Skip to content
This repository was archived by the owner on Nov 1, 2025. It is now read-only.

Commit 839df2c

Browse files
author
Dan Vittegleo
committed
go fmt
1 parent cb78a56 commit 839df2c

File tree

16 files changed

+113
-113
lines changed

16 files changed

+113
-113
lines changed

cmd/awslambdaproxy/awslambdaproxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package main
22

33
import (
44
"fmt"
5-
"os"
65
"github.com/dan-v/awslambdaproxy/cmd/awslambdaproxy/cmd"
6+
"os"
77
)
88

99
func main() {
1010
if err := cmd.RootCmd.Execute(); err != nil {
1111
fmt.Println(err)
1212
os.Exit(-1)
1313
}
14-
}
14+
}

cmd/awslambdaproxy/cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func initConfig() {
4040
}
4141

4242
viper.SetConfigName(".awslambdaproxy") // name of config file (without extension)
43-
viper.AddConfigPath("$HOME") // adding home directory as first search path
44-
viper.AutomaticEnv() // read in environment variables that match
43+
viper.AddConfigPath("$HOME") // adding home directory as first search path
44+
viper.AutomaticEnv() // read in environment variables that match
4545

4646
// If a config file is found, read it in.
4747
if err := viper.ReadInConfig(); err == nil {

cmd/awslambdaproxy/cmd/run.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package cmd
22

33
import (
4-
"github.com/spf13/cobra"
5-
"os/user"
4+
"fmt"
65
"github.com/dan-v/awslambdaproxy"
7-
"time"
6+
"github.com/spf13/cobra"
87
"github.com/spf13/viper"
9-
"strings"
108
"os"
11-
"fmt"
9+
"os/user"
1210
"strconv"
11+
"strings"
12+
"time"
1313
)
1414

1515
var (
16-
frequency time.Duration
17-
memory int64
16+
frequency time.Duration
17+
memory int64
1818
sshUser, sshPort, regions, listeners string
1919
// Max execution time on lambda is 300 seconds currently
20-
lambdaMaxFrequency = time.Duration(290 * time.Second) // leave 10 seconds of leeway
21-
lambdaMinMemorySize = 128
22-
lambdaMaxMemorySize = 1536
20+
lambdaMaxFrequency = time.Duration(290 * time.Second) // leave 10 seconds of leeway
21+
lambdaMinMemorySize = 128
22+
lambdaMaxMemorySize = 1536
2323
)
2424

2525
// runCmd represents the run command
@@ -93,19 +93,19 @@ func getCurrentUserName() string {
9393
func init() {
9494
RootCmd.AddCommand(runCmd)
9595

96-
runCmd.Flags().StringVarP(&regions, "regions", "r", "us-west-2","Regions to " +
96+
runCmd.Flags().StringVarP(&regions, "regions", "r", "us-west-2", "Regions to "+
9797
"run proxy.")
98-
runCmd.Flags().DurationVarP(&frequency, "frequency", "f", time.Duration(time.Second * 260), "Frequency " +
99-
"to execute Lambda function. Maximum is " + lambdaMaxFrequency.String() + ". If multiple " +
100-
"lambda-regions are specified, this will cause traffic to rotate round robin at the interval " +
98+
runCmd.Flags().DurationVarP(&frequency, "frequency", "f", time.Duration(time.Second*260), "Frequency "+
99+
"to execute Lambda function. Maximum is "+lambdaMaxFrequency.String()+". If multiple "+
100+
"lambda-regions are specified, this will cause traffic to rotate round robin at the interval "+
101101
"specified here.")
102-
runCmd.Flags().Int64VarP(&memory, "memory", "m", 128, "Memory size in MB for Lambda function. " +
102+
runCmd.Flags().Int64VarP(&memory, "memory", "m", 128, "Memory size in MB for Lambda function. "+
103103
"Higher memory may allow for faster network throughput.")
104-
runCmd.Flags().StringVarP(&listeners, "listeners", "l", "admin:awslambdaproxy@:8080","Add as many listeners" +
104+
runCmd.Flags().StringVarP(&listeners, "listeners", "l", "admin:awslambdaproxy@:8080", "Add as many listeners"+
105105
"as you'd like.")
106-
runCmd.Flags().StringVarP(&sshUser, "ssh-user", "", getCurrentUserName(),"SSH user for tunnel " +
106+
runCmd.Flags().StringVarP(&sshUser, "ssh-user", "", getCurrentUserName(), "SSH user for tunnel "+
107107
"connections from Lambda.")
108-
runCmd.Flags().StringVarP(&sshPort, "ssh-port", "", "22","SSH port for tunnel " +
108+
runCmd.Flags().StringVarP(&sshPort, "ssh-port", "", "22", "SSH port for tunnel "+
109109
"connections from Lambda.")
110110

111111
viper.BindPFlag("regions", runCmd.Flags().Lookup("regions"))

cmd/awslambdaproxy/cmd/setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4-
"github.com/spf13/cobra"
5-
"github.com/dan-v/awslambdaproxy"
64
"fmt"
5+
"github.com/dan-v/awslambdaproxy"
6+
"github.com/spf13/cobra"
77
"os"
88
)
99

infrastructure.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ package awslambdaproxy
33
// majority of this is borrowed from https://github.com/goadapp/goad/blob/master/infrastructure/infrastructure.go
44

55
import (
6-
"time"
76
"log"
7+
"time"
88

9-
"github.com/pkg/errors"
109
"github.com/aws/aws-sdk-go/aws"
1110
"github.com/aws/aws-sdk-go/aws/awserr"
1211
"github.com/aws/aws-sdk-go/aws/session"
1312
"github.com/aws/aws-sdk-go/service/iam"
1413
"github.com/aws/aws-sdk-go/service/lambda"
14+
"github.com/pkg/errors"
1515
)
1616

1717
const (
18-
lambdaFunctionName = "awslambdaproxy"
19-
lambdaFunctionHandler = "main.handler"
20-
lambdaFunctionRuntime = "python2.7"
21-
lambdaFunctionIamRole = "awslambdaproxy-role"
18+
lambdaFunctionName = "awslambdaproxy"
19+
lambdaFunctionHandler = "main.handler"
20+
lambdaFunctionRuntime = "python2.7"
21+
lambdaFunctionIamRole = "awslambdaproxy-role"
2222
lambdaFunctionIamRolePolicyName = "awslambdaproxy-role-policy"
23-
lambdaFunctionZipLocation = "data/lambda.zip"
23+
lambdaFunctionZipLocation = "data/lambda.zip"
2424
)
2525

2626
type LambdaInfrastructure struct {
@@ -30,7 +30,7 @@ type LambdaInfrastructure struct {
3030
lambdaMemorySize int64
3131
}
3232

33-
func SetupLambdaInfrastructure() (error) {
33+
func SetupLambdaInfrastructure() error {
3434
svc := iam.New(session.New(), &aws.Config{})
3535

3636
_, err := svc.GetRole(&iam.GetRoleInput{
@@ -96,24 +96,24 @@ func (infra *LambdaInfrastructure) setup() error {
9696
RoleName: aws.String(lambdaFunctionIamRole),
9797
})
9898
if err != nil {
99-
return errors.Wrap(err, "Could not find IAM role " + lambdaFunctionIamRole + ". Probably need to run setup.")
99+
return errors.Wrap(err, "Could not find IAM role "+lambdaFunctionIamRole+". Probably need to run setup.")
100100
}
101101
roleArn := *resp.Role.Arn
102102
zip, err := Asset(lambdaFunctionZipLocation)
103103
if err != nil {
104-
return errors.Wrap(err, "Could not read ZIP file: " + lambdaFunctionZipLocation)
104+
return errors.Wrap(err, "Could not read ZIP file: "+lambdaFunctionZipLocation)
105105
}
106106
for _, region := range infra.regions {
107107
log.Println("Setting up Lambda function in region: " + region)
108108
err = infra.createOrUpdateLambdaFunction(region, roleArn, zip)
109109
if err != nil {
110-
return errors.Wrap(err, "Could not create Lambda function in region " + region)
110+
return errors.Wrap(err, "Could not create Lambda function in region "+region)
111111
}
112112
}
113113
return nil
114114
}
115115

116-
func setupLambdaInfrastructure(regions []string, memorySize int64, timeout int64) (error) {
116+
func setupLambdaInfrastructure(regions []string, memorySize int64, timeout int64) error {
117117
infra := LambdaInfrastructure{
118118
regions: regions,
119119
config: &aws.Config{},
@@ -276,4 +276,4 @@ func (infra *LambdaInfrastructure) createIAMLambdaRolePolicy(roleName string) er
276276
RoleName: aws.String(roleName),
277277
})
278278
return err
279-
}
279+
}

init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package awslambdaproxy
22

33
import (
4-
"time"
54
"log"
65
"runtime"
6+
"time"
77
)
88

99
func ServerInit(sshUser string, sshPort string, regions []string, memory int64, frequency time.Duration,
10-
listeners []string, timeout int64) {
10+
listeners []string, timeout int64) {
1111
publicIp, err := getPublicIp()
1212
if err != nil {
1313
log.Fatal("Error getting public IP address", err.Error())
@@ -49,4 +49,4 @@ func ServerInit(sshUser string, sshPort string, regions []string, memory int64,
4949
log.Println("#######################################")
5050

5151
runtime.Goexit()
52-
}
52+
}

lambda/lambda.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4+
"flag"
45
"log"
56
"os"
6-
"flag"
77
)
88

99
func LambdaInit(tunnelHost string, sshPort string, sshPrivateKeyFile string, sshUsername string) {
@@ -13,7 +13,7 @@ func LambdaInit(tunnelHost string, sshPort string, sshPrivateKeyFile string, ssh
1313
log.Println("Establishing tunnel connection to", tunnelHost)
1414
lambdaTunnelConnection, err := setupLambdaTunnelConnection(tunnelHost, sshPort, sshUsername, sshPrivateKeyFile)
1515
if err != nil {
16-
log.Fatal("Failed to establish connection to " + tunnelHost, err)
16+
log.Fatal("Failed to establish connection to "+tunnelHost, err)
1717
}
1818

1919
log.Println("Starting LambdaDataCopyManager")
@@ -48,4 +48,3 @@ func main() {
4848

4949
LambdaInit(*addressPtr, *sshPortPtr, *sshPrivateKeyFilePtr, *sshUsernamePtr)
5050
}
51-

lambda/lambdadatacopy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package main
22

33
import (
4-
"os"
4+
"io"
55
"log"
66
"net"
7-
"io"
7+
"os"
88
"sync"
99
"time"
1010
)
1111

1212
type LambdaDataCopyManager struct {
1313
lambdaTunnelConnection *LambdaTunnelConnection
14-
lambdaProxyServer *LambdaProxyServer
14+
lambdaProxyServer *LambdaProxyServer
1515
}
1616

1717
func (l *LambdaDataCopyManager) run() {
@@ -38,7 +38,7 @@ func (l *LambdaDataCopyManager) run() {
3838
func newLambdaDataCopyManager(p *LambdaProxyServer, t *LambdaTunnelConnection) *LambdaDataCopyManager {
3939
return &LambdaDataCopyManager{
4040
lambdaTunnelConnection: t,
41-
lambdaProxyServer: p,
41+
lambdaProxyServer: p,
4242
}
4343
}
4444

@@ -59,4 +59,4 @@ func bidirectionalCopy(src io.ReadWriteCloser, dst io.ReadWriteCloser) {
5959
wg.Done()
6060
}()
6161
wg.Wait()
62-
}
62+
}

lambda/lambdaproxyserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ func startLambdaProxyServer() *LambdaProxyServer {
3333
}
3434
go server.run()
3535
return server
36-
}
36+
}

lambda/lambdatunnelconnection.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4+
"log"
45
"net"
56
"os"
6-
"log"
77

88
"github.com/hashicorp/yamux"
99
"golang.org/x/crypto/ssh"
@@ -15,11 +15,11 @@ const (
1515
)
1616

1717
type LambdaTunnelConnection struct {
18-
tunnelHost string
18+
tunnelHost string
1919
sshUsername string
20-
sshSigner ssh.Signer
21-
conn net.Conn
22-
sess *yamux.Session
20+
sshSigner ssh.Signer
21+
conn net.Conn
22+
sess *yamux.Session
2323
}
2424

2525
func (l *LambdaTunnelConnection) publicKeyFile() ssh.AuthMethod {
@@ -28,7 +28,7 @@ func (l *LambdaTunnelConnection) publicKeyFile() ssh.AuthMethod {
2828

2929
func (l *LambdaTunnelConnection) setup() {
3030
sshConfig := &ssh.ClientConfig{
31-
User: l.sshUsername,
31+
User: l.sshUsername,
3232
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
3333
Auth: []ssh.AuthMethod{
3434
l.publicKeyFile(),
@@ -37,14 +37,14 @@ func (l *LambdaTunnelConnection) setup() {
3737

3838
tunnelConn, err := ssh.Dial("tcp", l.tunnelHost, sshConfig)
3939
if err != nil {
40-
log.Println("Failed to start SSH tunnel to: " + l.tunnelHost + ". Error: ", err)
40+
log.Println("Failed to start SSH tunnel to: "+l.tunnelHost+". Error: ", err)
4141
os.Exit(1)
4242
}
4343
log.Println("Created SSH tunnel to: " + l.tunnelHost)
4444

4545
localConn, err := tunnelConn.Dial("tcp", remoteTunnelPort)
4646
if err != nil {
47-
log.Println("Failed to create local tunnel to " + remoteTunnelPort, err)
47+
log.Println("Failed to create local tunnel to "+remoteTunnelPort, err)
4848
os.Exit(1)
4949
}
5050
l.conn = localConn
@@ -60,7 +60,7 @@ func (l *LambdaTunnelConnection) setup() {
6060
}
6161

6262
func setupLambdaTunnelConnection(tunnelHost string, sshPort string, sshUsername string,
63-
sshPrivateKeyFile string) (*LambdaTunnelConnection, error) {
63+
sshPrivateKeyFile string) (*LambdaTunnelConnection, error) {
6464
data, err := ioutil.ReadFile(sshPrivateKeyFile)
6565
if err != nil {
6666
log.Println("Failed to read private key file", sshPrivateKeyFile)
@@ -73,11 +73,11 @@ func setupLambdaTunnelConnection(tunnelHost string, sshPort string, sshUsername
7373
}
7474

7575
tunnel := &LambdaTunnelConnection{
76-
tunnelHost: tunnelHost + ":" + sshPort,
76+
tunnelHost: tunnelHost + ":" + sshPort,
7777
sshUsername: sshUsername,
78-
sshSigner: signer,
78+
sshSigner: signer,
7979
}
8080

8181
tunnel.setup()
8282
return tunnel, nil
83-
}
83+
}

0 commit comments

Comments
 (0)