Skip to content

Setting Up a Development Environment

Bruce Spidel edited this page Apr 24, 2017 · 21 revisions

Install Go (golang) if not already installed

Note: As of 12 APR 2017 these steps require Go 1.7 or greater, so modify the Go installation instructions accordingly.

Follow these instruction for Ubuntu/Xubuntu: https://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04.

Note: I used ~/Projects/go as GOPATH.

Get the source code

Download and install go-bindata

This is needed to package the localization files. After you update a locale_LANG.ini file, run make bindata to package it.

cd ~/Projects/go
go get -u github.com/jteeuwen/go-bindata
go install github.com/jteeuwen/go-bindata/go-bindata

Download and build Gitea

cd ~/Projects/go
go get code.gitea.io/gitea
cd ~/Projects/go/src/code.gitea.io/gitea
make build

Fork the https://github.com/unfoldingWord-dev/gogs repository into your own github account.

Change origin to unfoldingWord-dev/gogs

cd ~/Projects/go/src/code.gitea.io/gitea
git remote set-url origin https://github.com/unfoldingWord-dev/gogs.git
git fetch --all && git reset --hard origin/master

Note: Do not switch to the develop branch before you have finished the steps above.

Switch to develop branch

git branch --no-track develop refs/remotes/origin/develop
git branch --set-upstream-to=origin/develop develop
git checkout develop

Add your fork as an additional remote

git remote add myfork https://github.com/phillip-hopper/gogs.git

Create a sym-link to the gogs-custom repository

cd ~/Projects
git clone git@github.com:unfoldingWord-dev/gogs-custom.git
cd ~/Projects/go/src/code.gitea.io/gitea
ln -s ~/Projects/gogs-custom custom

Configure IntelliJ

Create a new IntelliJ project - New from source

See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/wiki/Documentation.

First, install the Golang plugin in IntelliJ:

  • File > Settings > Plugins
  • Click the "Install JetBrains plugin..." button. A dialog called "Browse JetBrains Plugins" will open.
  • Type "Go" into the search box in the top-left corner of the dialog.
  • Select "Go (LANGUAGES)" from the list.
  • Click the green "Install" button in the right pane.
  • When installation is finished, restart IntelliJ.

Next, create a new project using the Gitea source you cloned:

  • File > New > Project from Existing Sources...
  • In the dialog that open, select the ~/Projects/go/src/code.gitea.io/gitea directory and click "OK."
  • Select "Create project from existing sources" and click "Next."
  • Leave the project name as "gitea" and click "Next."
  • Click "Next" until you get to "Please select the Go SDK for this module."
  • Click "Configure."
  • Select the Go installation directory, probably /usr/local/go or possibly $(echo $GOROOT) and click "OK."
  • If Python is detected, clear the check box.
  • Click "Finish."

Add the gitea directory to go libraries for this project

  • File > Settings > Languages & Frameworks > Go > Go Libraries
  • Add ~/Projects/go/src/code.gitea.io/gitea to "Project libraries"

Add the GO SDK for this project (if not done already)

  • File > Project Structure > Project > Project SDK > New > GO SDK
  • Select the directory where GO was installed (not your project directory)

If you get "EditorConfig is overriding code style settings for this file" click OK.

See https://intellij-support.jetbrains.com/hc/en-us/community/posts/207009225-EditorConfig-is-overriding-code-style-settings-for-this-file

Add a run configuration for building and testing

  • Run > Edit configurations
  • Add "Go Application"
  • Name it "gitea". This is the name IntelliJ will use for the executable, it should be ignored in .gitignore.
  • Run kind = "File"
  • File = "/home/team43/Projects/go/src/code.gitea.io/gitea/main.go"
  • Output directory = "/home/team43/Projects/go/src/code.gitea.io/gitea"
  • Working directory = "/home/team43/Projects/go/src/code.gitea.io/gitea"
  • Program arguments = "web"

Assign a module to the project

  • File > Project Structure
  • Add > New Module > go > Next
  • Select Previously established SDK
  • Next > name gitea
  • Finish

You should now be able to run and debug Gitea/Gogs

  • in IntelliJ Run > Run 'gitea'
  • In local web browser enter URL: localhost:3000

Unit testing in IntelliJ

I added a "Go Test" configuration running all the tests in a directory, as described in the documentation for the plugin

Note: I was receiving an error during testing that said security/pam_appl.h was not found. I resolved this by installing libpam0g-dev:

 sudo apt-get install libpam0g-dev

Note: when the yaml library was updated, I started receiving an error saying gopkg.in/check.v1 was missing. This is a dependency of the yaml library that is only needed for unit testing:

go get gopkg.in/check.v1