[lxc-devel] [lxd/master] lxd-agent: Fix golint

stgraber on Github lxc-bot at linuxcontainers.org
Fri Nov 8 21:41:49 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191108/87f6586b/attachment.bin>
-------------- next part --------------
From d31ab3dfe52646bd1a3ef87904e67ff6bc7e7c19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 8 Nov 2019 16:35:49 -0500
Subject: [PATCH] lxd-agent: Fix golint
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd-agent/exec.go              |  6 +++---
 lxd-agent/file.go              | 38 +++++++++++++++++-----------------
 lxd-agent/main.go              |  4 ++--
 lxd-agent/network.go           |  2 +-
 lxd-agent/server.go            |  2 +-
 test/suites/static_analysis.sh |  2 ++
 6 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/lxd-agent/exec.go b/lxd-agent/exec.go
index 516f38c910..75343f970f 100644
--- a/lxd-agent/exec.go
+++ b/lxd-agent/exec.go
@@ -119,8 +119,8 @@ type execWs struct {
 	command []string
 	env     map[string]string
 
-	rootUid          int64
-	rootGid          int64
+	rootUID          int64
+	rootGID          int64
 	conns            map[int]*websocket.Conn
 	connsLock        sync.Mutex
 	allConnected     chan bool
@@ -207,7 +207,7 @@ func (s *execWs) Do(op *operations.Operation) error {
 	if s.interactive {
 		ttys = make([]*os.File, 1)
 		ptys = make([]*os.File, 1)
-		ptys[0], ttys[0], err = shared.OpenPty(s.rootUid, s.rootGid)
+		ptys[0], ttys[0], err = shared.OpenPty(s.rootUID, s.rootGID)
 		if err != nil {
 			return err
 		}
diff --git a/lxd-agent/file.go b/lxd-agent/file.go
index 5cb8d5fd6c..e5bce0616f 100644
--- a/lxd-agent/file.go
+++ b/lxd-agent/file.go
@@ -42,7 +42,7 @@ func fileHandler(r *http.Request) response.Response {
 }
 
 func containerFileGet(path string, r *http.Request) response.Response {
-	uid, gid, mode, type_, dirEnts, err := getFileInfo(path)
+	uid, gid, mode, fType, dirEnts, err := getFileInfo(path)
 	if err != nil {
 		return response.SmartError(err)
 	}
@@ -51,10 +51,10 @@ func containerFileGet(path string, r *http.Request) response.Response {
 		"X-LXD-uid":  fmt.Sprintf("%d", uid),
 		"X-LXD-gid":  fmt.Sprintf("%d", gid),
 		"X-LXD-mode": fmt.Sprintf("%04o", mode),
-		"X-LXD-type": type_,
+		"X-LXD-type": fType,
 	}
 
-	if type_ == "file" || type_ == "symlink" {
+	if fType == "file" || fType == "symlink" {
 		// Make a file response struct
 		files := make([]response.FileResponseEntry, 1)
 		files[0].Identifier = filepath.Base(path)
@@ -65,7 +65,7 @@ func containerFileGet(path string, r *http.Request) response.Response {
 		}
 		defer f.Close()
 
-		if type_ == "file" {
+		if fType == "file" {
 			src, err := os.Open(path)
 			if err != nil {
 				return response.SmartError(err)
@@ -92,22 +92,22 @@ func containerFileGet(path string, r *http.Request) response.Response {
 		files[0].Filename = filepath.Base(path)
 
 		return response.FileResponse(r, files, headers, true)
-	} else if type_ == "directory" {
+	} else if fType == "directory" {
 		return response.SyncResponseHeaders(true, dirEnts, headers)
 	}
 
-	return response.InternalError(fmt.Errorf("bad file type %s", type_))
+	return response.InternalError(fmt.Errorf("bad file type %s", fType))
 }
 
 func containerFilePost(path string, r *http.Request) response.Response {
 	// Extract file ownership and mode from headers
-	uid, gid, mode, type_, write := shared.ParseLXDFileHeaders(r.Header)
+	uid, gid, mode, fType, write := shared.ParseLXDFileHeaders(r.Header)
 
 	if !shared.StringInSlice(write, []string{"overwrite", "append"}) {
 		return response.BadRequest(fmt.Errorf("Bad file write mode: %s", write))
 	}
 
-	if type_ == "file" {
+	if fType == "file" {
 		// Write file content to a tempfile
 		temp, err := ioutil.TempFile("", "lxd_forkputfile_")
 		if err != nil {
@@ -130,7 +130,7 @@ func containerFilePost(path string, r *http.Request) response.Response {
 		}
 
 		return response.EmptySyncResponse
-	} else if type_ == "symlink" {
+	} else if fType == "symlink" {
 		target, err := ioutil.ReadAll(r.Body)
 		if err != nil {
 			return response.InternalError(err)
@@ -141,7 +141,7 @@ func containerFilePost(path string, r *http.Request) response.Response {
 			return response.InternalError(err)
 		}
 		return response.EmptySyncResponse
-	} else if type_ == "directory" {
+	} else if fType == "directory" {
 		err := filePush("directory", "", path, uid, gid, mode, write)
 		if err != nil {
 			return response.InternalError(err)
@@ -149,7 +149,7 @@ func containerFilePost(path string, r *http.Request) response.Response {
 		return response.EmptySyncResponse
 	}
 
-	return response.BadRequest(fmt.Errorf("Bad file type: %s", type_))
+	return response.BadRequest(fmt.Errorf("Bad file type: %s", fType))
 }
 
 func containerFileDelete(path string, r *http.Request) response.Response {
@@ -179,11 +179,11 @@ func getFileInfo(path string) (int64, int64, os.FileMode, string, []string, erro
 		return -1, -1, 0, "", nil, err
 	}
 
-	var type_ string
+	var fType string
 	var dirEnts []string
 
 	if fi.Mode().IsDir() {
-		type_ = "directory"
+		fType = "directory"
 
 		f, err := os.Open(path)
 		if err != nil {
@@ -197,18 +197,18 @@ func getFileInfo(path string) (int64, int64, os.FileMode, string, []string, erro
 
 	} else {
 		if fi.Mode()&os.ModeSymlink != 0 {
-			type_ = "symlink"
+			fType = "symlink"
 		} else {
-			type_ = "file"
+			fType = "file"
 		}
 	}
 
 	// 0xFFF = 0b7777
-	return int64(stat.Uid), int64(stat.Gid), fi.Mode() & 0xFFF, type_, dirEnts, nil
+	return int64(stat.Uid), int64(stat.Gid), fi.Mode() & 0xFFF, fType, dirEnts, nil
 }
 
-func filePush(type_ string, srcpath string, dstpath string, uid int64, gid int64, mode int, write string) error {
-	switch type_ {
+func filePush(fType string, srcpath string, dstpath string, uid int64, gid int64, mode int, write string) error {
+	switch fType {
 	case "file":
 		if !shared.PathExists(dstpath) {
 			if uid == -1 {
@@ -301,5 +301,5 @@ func filePush(type_ string, srcpath string, dstpath string, uid int64, gid int64
 		return nil
 	}
 
-	return fmt.Errorf("Bad file type: %s", type_)
+	return fmt.Errorf("Bad file type: %s", fType)
 }
diff --git a/lxd-agent/main.go b/lxd-agent/main.go
index da133b6795..0b5a77cd4b 100644
--- a/lxd-agent/main.go
+++ b/lxd-agent/main.go
@@ -34,12 +34,12 @@ func main() {
 		log.Fatalln(errors.Wrap(err, "Failed to read client certificate"))
 	}
 
-	tlsConfig, err := ServerTLSConfig()
+	tlsConfig, err := serverTLSConfig()
 	if err != nil {
 		log.Fatalln(errors.Wrap(err, "Failed to get TLS config"))
 	}
 
-	httpServer := RestServer(tlsConfig)
+	httpServer := restServer(tlsConfig)
 
 	log.Println(httpServer.ServeTLS(networkTLSListener(l, tlsConfig), tlsServerCertFile, tlsServerKeyFile))
 }
diff --git a/lxd-agent/network.go b/lxd-agent/network.go
index 1f09d49726..07b5648ebc 100644
--- a/lxd-agent/network.go
+++ b/lxd-agent/network.go
@@ -56,7 +56,7 @@ func (l *networkListener) Accept() (net.Conn, error) {
 	return tls.Server(c, l.config), nil
 }
 
-func ServerTLSConfig() (*tls.Config, error) {
+func serverTLSConfig() (*tls.Config, error) {
 	certInfo, err := shared.KeyPairAndCA(filepath.Join("/", "media", "lxd_config"), "agent", shared.CertServer)
 	if err != nil {
 		return nil, err
diff --git a/lxd-agent/server.go b/lxd-agent/server.go
index 4e4a1c756e..2140789411 100644
--- a/lxd-agent/server.go
+++ b/lxd-agent/server.go
@@ -16,7 +16,7 @@ import (
 	"github.com/lxc/lxd/shared/logger"
 )
 
-func RestServer(tlsConfig *tls.Config) *http.Server {
+func restServer(tlsConfig *tls.Config) *http.Server {
 	mux := mux.NewRouter()
 	mux.StrictSlash(false)
 
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index c525971714..a65f5d62c8 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -67,6 +67,8 @@ test_static_analysis() {
       golint -set_exit_status lxc/config/
       golint -set_exit_status lxc/utils/
 
+      golint -set_exit_status lxd-agent
+
       golint -set_exit_status lxd-benchmark
       golint -set_exit_status lxd-benchmark/benchmark
 


More information about the lxc-devel mailing list