Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Commit 5adf095

Browse files
committed
Naming warnings from golint are fixed
1 parent d363a2b commit 5adf095

5 files changed

Lines changed: 68 additions & 68 deletions

File tree

cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func (cmd commandAuth) Execute(conn *Conn, param string) {
859859
log.Println(param, conn)
860860
if param == "TLS" && conn.tlsConfig != nil {
861861
conn.writeMessage(234, "AUTH command OK")
862-
err := conn.upgradeToTls()
862+
err := conn.upgradeToTLS()
863863
if err != nil {
864864
conn.logger.Printf("Error upgrading conection to TLS %v", err)
865865
}

conn.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Conn struct {
2828
logger *Logger
2929
server *Server
3030
tlsConfig *tls.Config
31-
sessionId string
31+
sessionID string
3232
namePrefix string
3333
reqUser string
3434
user string
@@ -48,7 +48,7 @@ func (conn *Conn) IsLogin() bool {
4848
}
4949

5050
// returns a random 20 char string that can be used as a unique session ID
51-
func newSessionId() string {
51+
func newSessionID() string {
5252
hash := sha256.New()
5353
_, err := io.CopyN(hash, rand.Reader, 50)
5454
if err != nil {
@@ -100,39 +100,39 @@ func (conn *Conn) Close() {
100100
}
101101
}
102102

103-
func (Conn *Conn) upgradeToTls() error {
104-
Conn.logger.Print("Upgrading connectiion to TLS")
105-
tlsConn := tls.Server(Conn.conn, Conn.tlsConfig)
103+
func (conn *Conn) upgradeToTLS() error {
104+
conn.logger.Print("Upgrading connectiion to TLS")
105+
tlsConn := tls.Server(conn.conn, conn.tlsConfig)
106106
err := tlsConn.Handshake()
107107
if err == nil {
108-
Conn.conn = tlsConn
109-
Conn.controlReader = bufio.NewReader(tlsConn)
110-
Conn.controlWriter = bufio.NewWriter(tlsConn)
111-
Conn.tls = true
108+
conn.conn = tlsConn
109+
conn.controlReader = bufio.NewReader(tlsConn)
110+
conn.controlWriter = bufio.NewWriter(tlsConn)
111+
conn.tls = true
112112
}
113113
return err
114114
}
115115

116116
// receiveLine accepts a single line FTP command and co-ordinates an
117117
// appropriate response.
118-
func (Conn *Conn) receiveLine(line string) {
119-
command, param := Conn.parseLine(line)
120-
Conn.logger.PrintCommand(command, param)
118+
func (conn *Conn) receiveLine(line string) {
119+
command, param := conn.parseLine(line)
120+
conn.logger.PrintCommand(command, param)
121121
cmdObj := commands[strings.ToUpper(command)]
122122
if cmdObj == nil {
123-
Conn.writeMessage(500, "Command not found")
123+
conn.writeMessage(500, "Command not found")
124124
return
125125
}
126126
if cmdObj.RequireParam() && param == "" {
127-
Conn.writeMessage(553, "action aborted, required param missing")
128-
} else if cmdObj.RequireAuth() && Conn.user == "" {
129-
Conn.writeMessage(530, "not logged in")
127+
conn.writeMessage(553, "action aborted, required param missing")
128+
} else if cmdObj.RequireAuth() && conn.user == "" {
129+
conn.writeMessage(530, "not logged in")
130130
} else {
131-
cmdObj.Execute(Conn, param)
131+
cmdObj.Execute(conn, param)
132132
}
133133
}
134134

135-
func (Conn *Conn) parseLine(line string) (string, string) {
135+
func (conn *Conn) parseLine(line string) (string, string) {
136136
params := strings.SplitN(strings.Trim(line, "\r\n"), " ", 2)
137137
if len(params) == 1 {
138138
return params[0], ""
@@ -141,11 +141,11 @@ func (Conn *Conn) parseLine(line string) (string, string) {
141141
}
142142

143143
// writeMessage will send a standard FTP response back to the client.
144-
func (Conn *Conn) writeMessage(code int, message string) (wrote int, err error) {
145-
Conn.logger.PrintResponse(code, message)
144+
func (conn *Conn) writeMessage(code int, message string) (wrote int, err error) {
145+
conn.logger.PrintResponse(code, message)
146146
line := fmt.Sprintf("%d %s\r\n", code, message)
147-
wrote, err = Conn.controlWriter.WriteString(line)
148-
Conn.controlWriter.Flush()
147+
wrote, err = conn.controlWriter.WriteString(line)
148+
conn.controlWriter.Flush()
149149
return
150150
}
151151

@@ -166,43 +166,43 @@ func (Conn *Conn) writeMessage(code int, message string) (wrote int, err error)
166166
// The driver implementation is responsible for deciding how to treat this path.
167167
// Obviously they MUST NOT just read the path off disk. The probably want to
168168
// prefix the path with something to scope the users access to a sandbox.
169-
func (Conn *Conn) buildPath(filename string) (fullPath string) {
169+
func (conn *Conn) buildPath(filename string) (fullPath string) {
170170
if len(filename) > 0 && filename[0:1] == "/" {
171171
fullPath = filepath.Clean(filename)
172172
} else if len(filename) > 0 && filename != "-a" {
173-
fullPath = filepath.Clean(Conn.namePrefix + "/" + filename)
173+
fullPath = filepath.Clean(conn.namePrefix + "/" + filename)
174174
} else {
175-
fullPath = filepath.Clean(Conn.namePrefix)
175+
fullPath = filepath.Clean(conn.namePrefix)
176176
}
177177
fullPath = strings.Replace(fullPath, "//", "/", -1)
178178
return
179179
}
180180

181181
// sendOutofbandData will send a string to the client via the currently open
182182
// data socket. Assumes the socket is open and ready to be used.
183-
func (Conn *Conn) sendOutofbandData(data []byte) {
183+
func (conn *Conn) sendOutofbandData(data []byte) {
184184
bytes := len(data)
185-
if Conn.dataConn != nil {
186-
Conn.dataConn.Write(data)
187-
Conn.dataConn.Close()
188-
Conn.dataConn = nil
185+
if conn.dataConn != nil {
186+
conn.dataConn.Write(data)
187+
conn.dataConn.Close()
188+
conn.dataConn = nil
189189
}
190190
message := "Closing data connection, sent " + strconv.Itoa(bytes) + " bytes"
191-
Conn.writeMessage(226, message)
191+
conn.writeMessage(226, message)
192192
}
193193

194-
func (Conn *Conn) sendOutofBandDataWriter(data io.ReadCloser) error {
195-
Conn.lastFilePos = 0
196-
bytes, err := io.Copy(Conn.dataConn, data)
194+
func (conn *Conn) sendOutofBandDataWriter(data io.ReadCloser) error {
195+
conn.lastFilePos = 0
196+
bytes, err := io.Copy(conn.dataConn, data)
197197
if err != nil {
198-
Conn.dataConn.Close()
199-
Conn.dataConn = nil
198+
conn.dataConn.Close()
199+
conn.dataConn = nil
200200
return err
201201
}
202202
message := "Closing data connection, sent " + strconv.Itoa(int(bytes)) + " bytes"
203-
Conn.writeMessage(226, message)
204-
Conn.dataConn.Close()
205-
Conn.dataConn = nil
203+
conn.writeMessage(226, message)
204+
conn.dataConn.Close()
205+
conn.dataConn = nil
206206

207207
return nil
208208
}

logger.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77

88
// Use an instance of this to log in a standard format
99
type Logger struct {
10-
sessionId string
10+
sessionID string
1111
}
1212

1313
func newLogger(id string) *Logger {
1414
l := new(Logger)
15-
l.sessionId = id
15+
l.sessionID = id
1616
return l
1717
}
1818

1919
func (logger *Logger) Print(message interface{}) {
20-
log.Printf("%s %s", logger.sessionId, message)
20+
log.Printf("%s %s", logger.sessionID, message)
2121
}
2222

2323
func (logger *Logger) Printf(format string, v ...interface{}) {
@@ -26,12 +26,12 @@ func (logger *Logger) Printf(format string, v ...interface{}) {
2626

2727
func (logger *Logger) PrintCommand(command string, params string) {
2828
if command == "PASS" {
29-
log.Printf("%s > PASS ****", logger.sessionId)
29+
log.Printf("%s > PASS ****", logger.sessionID)
3030
} else {
31-
log.Printf("%s > %s %s", logger.sessionId, command, params)
31+
log.Printf("%s > %s %s", logger.sessionID, command, params)
3232
}
3333
}
3434

3535
func (logger *Logger) PrintResponse(code int, message string) {
36-
log.Printf("%s < %d %s", logger.sessionId, code, message)
36+
log.Printf("%s < %d %s", logger.sessionID, code, message)
3737
}

server.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func NewServer(opts *ServerOpts) *Server {
123123
opts = serverOptsWithDefaults(opts)
124124
s := new(Server)
125125
s.ServerOpts = opts
126-
s.listenTo = buildTcpString(opts.Hostname, opts.Port)
126+
s.listenTo = buildTCPString(opts.Hostname, opts.Port)
127127
s.name = opts.Name
128128
s.driverFactory = opts.Factory
129129
s.logger = newLogger("")
@@ -143,8 +143,8 @@ func (server *Server) newConn(tcpConn net.Conn, driver Driver) *Conn {
143143
c.driver = driver
144144
c.auth = server.Auth
145145
c.server = server
146-
c.sessionId = newSessionId()
147-
c.logger = newLogger(c.sessionId)
146+
c.sessionID = newSessionID()
147+
c.logger = newLogger(c.sessionID)
148148
c.tlsConfig = server.tlsConfig
149149
driver.Init(c)
150150
return c
@@ -173,59 +173,59 @@ func simpleTLSConfig(certFile, keyFile string) (*tls.Config, error) {
173173
// errors are trying to bind to a privileged port or something else is already
174174
// listening on the same port.
175175
//
176-
func (Server *Server) ListenAndServe() error {
176+
func (server *Server) ListenAndServe() error {
177177
var listener net.Listener
178178
var err error
179179

180-
if Server.ServerOpts.TLS {
181-
Server.tlsConfig, err = simpleTLSConfig(Server.CertFile, Server.KeyFile)
180+
if server.ServerOpts.TLS {
181+
server.tlsConfig, err = simpleTLSConfig(server.CertFile, server.KeyFile)
182182
if err != nil {
183183
return err
184184
}
185185

186-
if Server.ServerOpts.ExplicitFTPS {
187-
listener, err = net.Listen("tcp", Server.listenTo)
186+
if server.ServerOpts.ExplicitFTPS {
187+
listener, err = net.Listen("tcp", server.listenTo)
188188
} else {
189-
listener, err = tls.Listen("tcp", Server.listenTo, Server.tlsConfig)
189+
listener, err = tls.Listen("tcp", server.listenTo, server.tlsConfig)
190190
}
191191
} else {
192-
listener, err = net.Listen("tcp", Server.listenTo)
192+
listener, err = net.Listen("tcp", server.listenTo)
193193
}
194194
if err != nil {
195195
return err
196196
}
197197

198-
Server.logger.Printf("%s listening on %d", Server.Name, Server.Port)
198+
server.logger.Printf("%s listening on %d", server.Name, server.Port)
199199

200-
Server.listener = listener
200+
server.listener = listener
201201
for {
202-
tcpConn, err := Server.listener.Accept()
202+
tcpConn, err := server.listener.Accept()
203203
if err != nil {
204-
Server.logger.Printf("listening error: %v", err)
204+
server.logger.Printf("listening error: %v", err)
205205
break
206206
}
207-
driver, err := Server.driverFactory.NewDriver()
207+
driver, err := server.driverFactory.NewDriver()
208208
if err != nil {
209-
Server.logger.Printf("Error creating driver, aborting client connection: %v", err)
209+
server.logger.Printf("Error creating driver, aborting client connection: %v", err)
210210
tcpConn.Close()
211211
} else {
212-
ftpConn := Server.newConn(tcpConn, driver)
212+
ftpConn := server.newConn(tcpConn, driver)
213213
go ftpConn.Serve()
214214
}
215215
}
216216
return nil
217217
}
218218

219219
// Gracefully stops a server. Already connected clients will retain their connections
220-
func (Server *Server) Shutdown() error {
221-
if Server.listener != nil {
222-
return Server.listener.Close()
220+
func (server *Server) Shutdown() error {
221+
if server.listener != nil {
222+
return server.listener.Close()
223223
}
224224
// server wasnt even started
225225
return nil
226226
}
227227

228-
func buildTcpString(hostname string, port int) (result string) {
228+
func buildTCPString(hostname string, port int) (result string) {
229229
if strings.Contains(hostname, ":") {
230230
// ipv6
231231
if port == 0 {

socket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ftpActiveSocket struct {
3434
}
3535

3636
func newActiveSocket(host string, port int, logger *Logger) (DataSocket, error) {
37-
connectTo := buildTcpString(host, port)
37+
connectTo := buildTCPString(host, port)
3838
logger.Print("Opening active data connection to " + connectTo)
3939
raddr, err := net.ResolveTCPAddr("tcp", connectTo)
4040
if err != nil {

0 commit comments

Comments
 (0)