Posts Tagged sublime text

Setup Sublime Text to work with golang and Google App Engine (mac)

If you want to create applications with GO, deploy them to google app engine and use Sublime Text as your IDE then this step-by-step tutorial is for you (tutorial is  for Mac but it can be used for other platforms)

Step 0:

Download and install golang SDK from Google:
https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go

Unpack it somewhere (I usually use the folder “$HOME/SDKs”)

Step 1:

Install Sublime Text 3, you can find it here:
https://www.sublimetext.com

Step 2:

Install package control for Sublime Text, find all relevant information about installation process here: https://packagecontrol.io/installation

Step 3:

Install GoSublime package: https://github.com/DisposaBoy/GoSublime

Press cmd+shift+p, type ‘Package Control: Install Package’ or select it from the list, then type GoSublime and install the package

Step 4:

Setup  variables GOROOT & GOPATH in your environment (put the information below into .bash_profile on Mac/Linux)

Type in command line

cd ~
open .bash_profile -a "Sublime Text"

And add following lines to the end of the file

# Change the variables below to the path where you installed go_appengine
export GOSDK=/Users/user/SDKs/go_appengine
export GOROOT=$GOSDK/goroot
export GOPATH=$GOSDK/gopath
export PATH=$GOSDK:$GOROOT/bin:$PATH

Step 5:

Go to $GOROOT/bin & $GOROOT/pkg folders and execute the a commands below to create appropriate symlinks (GoSublime does not know anything about ‘goapp’, it knows only about ‘go’, we should simulate it)

cd $GOROOT/bin
ln -s goapp go
cd $GOROOT/pkg
ln -s darwin_amd64_appengine darwin_amd64

Step 6:

Create your first go app for GAE: create folder somewhere and create there 2 files, hello.go with the following content

package hello

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, world!")
}

and app.yaml with the following content (change gae-app-name-hello to real gae ID before deploying!)

application: gae-app-name
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

If you did everything correctly then your Sublime Text should have code completion and console to run go commands. Press in Sublime Text cmd+9 and type ‘build’ in the console, it should compile and build your app. If build is successful then go to terminal and type in the app folder ‘goapp serve’, the app will run locally, you can check it with your web browser on the link http://localhost:8080

Step 7:

Deploy your app using command ‘goapp deploy’ in your app folder (do not forget to perform all the prerequisites to setup app engine, check this link for more info: https://cloud.google.com/appengine/docs/go/gettingstarted/uploading)

Enjoy!

, , , , , , ,

Leave a comment

Using GO + Sublime Text + GoSublime + GAE

Sometimes easy things are not so obvious as they really are. If you are using GO language together with Sublime Text and want to have in place such features as code completion, you obviously will start using GoSublime plugin. If you are using GO in GAE (Google Application Engine) for your developments than you need small tuning to make it work.

  1. First of all, make sure  GOROOT and GOPATH are set in your environment (or in Sublime Text settings) and pointing to the GAE version of GO
  2. Go to GOROOT/bin folder and make a symlink for “goapp” naming it “go”
  3. Go to GOROOT/pkg folder and make a symlink for “darwin_amd64_appengine” naming it “darwin_amd64”

Enjoy.

, , , , , , , , , , ,

1 Comment