Golang

From campisano.org
Jump to navigation Jump to search

Golang

Install

Using golang binaries

  • to use last version, in this example 1.11.13

shared/opt install schema v1.2

su -
#### as root
# cleanup
apt-get autoremove --purge golang\*
# dependencies
apt-get install curl tar gzip
# binary
DESTINATION="/home/shared/opt/software"                 # Edit when needed
VERSION="1.11.13"                                       # Edit when needed
URL="https://dl.google.com/go/go${VERSION}.linux-amd64.tar.gz"
umask 0027
mkdir -p "${DESTINATION}/tmp"
cd "${DESTINATION}/tmp"
curl -C - -kLO "${URL}"
tar -xzf "go${VERSION}.linux-amd64.tar.gz"
cd "${DESTINATION}"
chown -R root:users "tmp"
find "tmp" -type d -exec chmod a-s,u+rwx,g+rx,g-w,o-rwx {} \;
find "tmp" -type f -exec chmod a-s,u+rw,g+r,g-w,o-rwx {} \;
mv tmp/go "golang-${VERSION}.linux-amd64"
rm -rf tmp golang
ln -s "golang-${VERSION}.linux-amd64" golang
exit
  • and setup your user environment (you can put the follow in ~/.profile)
export GOROOT="/home/shared/opt/software/golang"        # Edit when needed
export GOPATH="${HOME}/.golang" 
export PATH="${PATH}:${GOROOT}/bin:${GOPATH}/bin" 

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

Test

mkdir -p "$HOME/tmp"
cd "$HOME/tmp"
cat > hello.go <<EOF
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
EOF
go build
./tmp
# hello, world

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

Install

shared/opt install schema v1.2

su -
#### as root
# dependencies
apt-get install curl tar gzip qt5-default gcc g++ gdb
# binary
DESTINATION="/home/shared/opt/software"                 # Edit when needed
VERSION="x36.2"                                         # Edit when needed
URL="https://github.com/visualfc/liteide/archive/${VERSION}.tar.gz"
umask 0027
mkdir -p "${DESTINATION}/tmp"
cd "${DESTINATION}/tmp"
curl -C - -kLO "${URL}"
tar -xzf "${VERSION}.tar.gz"
cd "liteide-${VERSION}/build/"
chmod -R 777 ../
su -c "/bin/bash" USERNAME
#### as common user
./update_pkg.sh
./build_linux_qt5.sh
./deploy_linux_x64_qt5.sh
exit
#### as root
cd "${DESTINATION}"
chown -R root:users "tmp"
find "tmp" -type d -exec chmod a-s,u+rwx,g+rx,g-w,o-rwx {} \;
find "tmp" -type f -exec chmod a-s,u+rw,g+r,g-w,o-rwx {} \;
mv "tmp/liteide-${VERSION}/build/liteide" "liteide_${VERSION}"
rm -rf tmp liteide
ln -s "liteide_${VERSION}" liteide
exit
#### as final user
SOFTWARE_PATH="/home/shared/opt/software"               # Edit when needed
"${SOFTWARE_PATH}/liteide/bin/liteide"

GoWorks (NetBeans)

NOTE - OUTDATED SINCE 2013

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)
                  ))