Archive for category tutorials

Creating ubuntu service for go app

Step 1

Install go program with go install in the app folder

Step 2

Download service script file from here: Service for go app

Step 3

Change {{USERNAME}} in the script to the user you use in ubuntu to run your app and change  {{APPNAME}}  to binary name in your $GOPATH/bin/, if needed fix the path in cmd variable to point to your own $GOPATH folder

Step 4

Rename the service remove ending ‘.sh’ and copy the service file in the folder  /etc/init.d/

Step 5

Run in the terminal chmod 700 /etc/init.d/goappservice

Step 6

Run sudo update-rc.d goappservice defaults

Step 7

Run sudo update-rc.d goappservice enable

Done!

Use usual service commands to work with your new service.

sudo service goappservice start|stop|restart|status

If there is a new version of the app then just run go install in the app folder and restart the service.

Enjoy

, ,

Leave a comment

Step by step tutorial: how to setup new Raspberry PI from command line

Writing image

Connect RPI to Wi-Fi

  • Check wireless connection with “sudo iwlist wlan0 scan”
  • Setup wireless with nano “sudo nano /etc/wpa_supplicant/wpa_supplicant.conf”
  • Add the config below to wpa_supplicant.conf in the end of the file
network={
    ssid="The_ESSID_from_earlier"
    psk="Your_wifi_password"
}
  • do “sudo ifdown wlan0” then “sudo ifup wlan0”
  • check address with ifconfig

Upgrade RPI to the latest packages, install mc

  • do “sudo apt update”
  • do “sudo apt upgrade”
  • do “sudo apt install mc”
  • set default editor to mcedit “sudo update-alternatives –set editor /usr/bin/mcedit”

Add your own user, configure sudoers, change password of pi

  • add new user with a command “sudo adduser youruser”
  • add the user to sudoers with visudo “sudo visudo”
  • add the following line in the end “youruser ALL=(ALL) NOPASSWD: ALL”
  • change password of pi user “passwd”
  • reboot your RPI with “sudo rpi”

Setup firewall

  • Install ufw with “sudo apt install ufw”
  • Allow minimum ssh ports with “sudo ufw allow 22/tcp”
  • Allow all other port you are going to use, i.e web “sudo ufw allow 80/tcp”
  • Enable ufw “sudo ufw enable”
  • Check the status “sudo ufw status”

Login with your user, fix locales

if you have the issue “warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)”, you can solve it with the command “sudo dpkg-reconfigure locales”, select en_US.UTF-8 as default

Make a backup

  • Make backup with ApplePI-Baker.app downloaded in the beginning

DONE

, , , ,

Leave a comment

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

How to create simple webservice using GO (golang) on GAE

This tutorial will show how to create simple webservice application using GO on Google Application Engine (GAE), I’m going to cover the following topics:

  1. Creating project in GAE
  2. Creating and testing application locally
  3. Using martini package to simplify service development
  4. Deployment of the services to GAE

First of all, go to Google Developer Console and create new project:

https://console.developers.google.com/project

Screenshot 2015-09-09 09.22.54

Select project name and open advanced options, make sure that you are selecting the proper region you want to use, it is important as if we are going to add SQL Cloud later to our project and the region of the project & SQL Cloud should be the same to work together.

Screenshot 2015-09-09 09.29.28

Give some minutes to Google and you should see the picture as shown below with your project ready to be developed. Copy Project ID (in my case it is tutorial-golang, you will defenitely have different name) to you favourite text editor on your computer, we will need it later when we prepare our first deploy of the application

Screenshot 2015-09-09 09.35.42

Read the rest of this entry »

, , , , , , , , , ,

Leave a comment