Golang

From campisano.org
Jump to navigation Jump to search

Golang

Install

Using system packages

  • just a package:
## from Debian STABLE:
$ sudo apt-get install golang # Stable package
## or Debian BACKPORT:
$ sudo apt-get -t stretch-backports install golang
## to DEBUG, install also gdb:
$ sudo apt-get install gdb
  • and setup your user environment (you can put the follow in ~/.profile)
$ export GOPATH=${HOME}/go
$ export PATH=${PATH}:${GOPATH}/bin

Using golang binaries

  • to use last version, in this example 1.11.2
$ su -
$ apt-get autoremove --purge golang*
$ export VER_NAME=go1.11.2.linux-amd64
$ cd /home/shared/opt/software/
$ wget https://dl.google.com/go/${VER_NAME}.tar.gz
$ tar -xzf ${VER_NAME}.tar.gz
$ rm -f ${VER_NAME}.tar.gz
$ mv go ${VER_NAME}
$ ln -s ${VER_NAME} go
  • and setup your user environment (you can put the follow in ~/.profile)
$ export GOROOT="/home/shared/opt/software/go";
$ export GOPATH="${HOME}/go";
$ export PATH="${PATH}:${GOROOT}/bin:${GOPATH}/bin";

Test

$ mkdir -p $HOME/go/src/hello
$ cd $HOME/go/src/hello
$ cat > hello.go <<EOF
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
EOF
$ go build
$ ./hello
hello, world
$ go install
$ hello
hello, world
$ type -p hello
/home/user/go/bin/hello

Troubles

In case of dependencies problems, e.g.

go: verifying github.com/labstack/echo@v3.3.5+incompatible: checksum mismatch

clean the checksum file:

rm go.sum
go clean -modcache

Source: go/issues/29281

IDEs

GoClipse

  • NOTE, the project is outdated

1) add goclipse plugin from http://goclipse.github.io/releases/

2) configure and install gocode, guru, godef tools

go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/guru
go get -u github.com/rogpeppe/godef

3) configure build target using a Makefile, and run it from project_folder->right_click->build

make -C ${project_loc} debug

4) add a simple Makefile, like

debug:
    go build -v -gcflags=all="-N -l" ./cmd/YOUR_PACKAGE

LiteIDE

  • Compile
## Install Qt5
$ sudo apt-get install qt5-default
$ git clone https://github.com/visualfc/liteide.git
$ cd liteide/build
$ ./update_pkg.sh
$ ./build_linux_qt5.sh
$ ./deploy_linux_x64_qt5.sh
$ cat ./liteide/README.md | grep 'Version:'
$ sudo mv liteide /home/shared/opt/software/liteide_X33.4

GoWorks (NetBeans)

Emacs

;; from https://github.com/dominikh/go-mode.el
(use-package go-mode
  :ensure t
  :config
  (autoload 'go-mode "go-mode" nil t)
  (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  )

;; from https://github.com/mdempsky/gocode/tree/master/emacs-company
;; remember to install gocode with
;;   go get -u github.com/mdempsky/gocode
(use-package company-go
  :ensure t
  :config
  (add-hook 'go-mode-hook
            (lambda()
              (set (make-local-variable 'company-backends) '(company-go))
              (company-mode)))
  )

;; from https://github.com/benma/go-dlv.el/blob/master/go-dlv.el
;;      http://tleyden.github.io/blog/2014/05/22/
;;                               configure-emacs-as-a-go-editor-from-scratch/
;; remember to install dlv with
;;   go get -u github.com/derekparker/delve/cmd/dlv
(use-package go-dlv
  :ensure t
  )

;; defining a custom layout for DLV
;; from http://www.campisano.org/wiki/en/Emacs
(defun fun_set-dlv-layout(var_editing_buffer)
  ;; (defvar-local var_source_window (selected-window))
  ;; (defvar-local var_debugging_window                     ; bottom
  ;;   (split-window var_source_window (floor(* 0.66 (window-body-height)))
  ;;                 'below))

  ;; (set-window-dedicated-p var_debugging_window t)
  ;; (select-window var_source_window)
  (set-window-buffer var_source_window var_editing_buffer)
  )

;; (defvar global-config-editing)
(global-set-key (kbd "C-c g")
                (lambda() (interactive)
                  ;; (setq global-config-editing (current-window-configuration))
                  (setq var_editing_buffer (window-buffer (selected-window)))
                  ;; (dlv (concat "debug " (buffer-file-name)))
                  (dlv-current-func)
                  (fun_set-dlv-layout var_editing_buffer)
                  ;; (set-window-configuration global-config-editing)
                  ))