Thursday, August 22, 2013

GoREST (golang web services) Simple Examples

In my last post, Installing GoREST on Ubuntu Linux, I mentioned that I should really post a simple example of using GoREST. Here’s some example code for a Get and Post request using GoREST web services in golang.

Note that I’m also using the go-sql-driver/mysql driver for MySQL in golang. To install the driver, simply run:

$ go get github.com/go-sql-driver/mysql

Also, this example isn’t actually using JSON. Check out the link at the end of this post for a JSON example.

package main
import (
      "code.google.com/p/gorest"
    _ "github.com/go-sql-driver/mysql"
      "database/sql"
      "net/http"
      "log"
      "time"
      "os"
      "strconv"
)

func main() {
    // GoREST usage: http://localhost:8181/tutorial/hello
    gorest.RegisterService(new(Tutorial)) //Register our service
    http.Handle("/",gorest.Handle())    
    http.ListenAndServe(":8181",nil)
}

//Service Definition
type Tutorial struct {
    gorest.RestService `root:"/tutorial/" consumes:"application/json" produces:"application/json"`
    hello  gorest.EndPoint `method:"GET" path:"/hello/" output:"string"`
    insert   gorest.EndPoint `method:"POST" path:"/insert/" postdata:"int"`
}

func(serv Tutorial) Hello() string{
    return "Hello World"
}

func(serv Tutorial) Insert(number int) {
    db, err := sql.Open("mysql", "root:password@/dbname?charset=utf8")
    db.Exec("INSERT INTO table (number) VALUES(strconv.Itoa(number) + ");")
    db.Close()
    serv.ResponseBuilder().SetResponseCode(200)
}

I’m using Postman REST Client for my post tests, you can download Postman for free from the Chrome web store. (Blog post on using Postman with JSON.)

image

Monday, August 19, 2013

Installing GoREST on Ubuntu Linux

Previous posts on setting up a developer environment on an Ubuntu Linux virtual machine running on Windows Azure:
- Linux (Ubuntu) Virtual Machine on Windows Azure
- Remote Access to Ubuntu Linux VM on Windows Azure
- Installing LAMP on Ubuntu
- Installing Git on Ubuntu Linux

GoREST is a useful RESTful style web-services framework for the Go (golang) language. The commands to install GoREST are simple, but there’s more than one step involved. Although, having said that, this post will still be really light, so I’ll have to make sure I write another one soon with some GoREST examples. (Update: I wrote a post with some simple examples: GoREST (golang web services) Simple Examples)

First, you’ll need to install Mercurial so that you can run the “go get” command for GoREST:

$ sudo apt-get install mercurial

image

Next, run the command to install GoREST:

$ sudo go get code.google.com/p/gorest

The GoREST install is silent, so you won’t see any feedback.  My advice is to have a simple Hello World style example ready to go, so you can test your GoREST install.

Installing Go (golang) on Ubuntu Linux

Previous posts:
- Linux (Ubuntu) Virtual Machine on Windows Azure
- Remote Access to Ubuntu Linux VM on Windows Azure
- Installing LAMP on Ubuntu
- Installing Git on Ubuntu Linux

As part of my series on setting up a development environment on Ubuntu Linux running in Windows Azure, here are the steps to install and test the Go (golang) language.

First you have to SSH to your VM and install Go, which is super easy. Note that apt-get might not install the latest version of Go, see thread on Stack Overflow about installing latest version of Go.

$ ssh -p portnumber username@yourvmname.cloudapp.net
$
sudo apt-get install golang-go

image

You’ll be asking whether or not you’d like to participate in a program to track which packages are being installed.

image

To check that it’s installed, you can run: $ go version

You may want to do some additional customization. For more details, refer to this post: How to Install Google Go in Ubuntu by Joshua Price.

Sunday, August 18, 2013

Installing Git on Ubuntu Linux

Previous posts:
- Linux (Ubuntu) Virtual Machine on Windows Azure
- Remote Access to Ubuntu Linux VM on Windows Azure
- Installing LAMP on Ubuntu

I’ve been writing some posts about setting up a development environment for Ubuntu running on Windows Azure. Here’s the short post on getting Git source control working.

Install Git

Installing LAMP is easy, there isn’t a word for how easy it is to install Git. It’s one command and you’re done. Done with the install that is… you’ll need to do a little config and then clone a repository or initialize one.

$ sudo apt-get install git

image

Once you’ve got your install done, you can quickly configure your user settings with these commands.
$ git config --global user.name NewUser
$ git config --global user.email

Check your Git install

Where is Git installed?

$ which git

What’s your config?

$ git config –list

Start Using Git by Cloning a Repository

Clone your repository to a directory (for example, from GitHub):
$ git clone git@github.com:whatever folderName
Note that you don’t have to pay for a private repository. See my post on a Free Private Git Repository Using TFS Online Git Integration. (Need help? See Cloning a Git Repository.)
Also, if you’re new to Git, keep in mind that you can get the Pro Git book for free.

Saturday, August 17, 2013

Installing LAMP on Ubuntu Linux

Previous posts:
- Linux (Ubuntu) Virtual Machine on Windows Azure
- Remote Access to Ubuntu Linux VM on Windows Azure

Installing the rest of the L.A.M.P. stack (Linux, Apache, MySQL, PHP) on a Windows Azure Ubuntu image is remarkably simple. You simply need to run two commands. First install tasksel and then run tasksel to install the lamp-server package. It’s so easy that I’m also including instructions for testing that each component is installed and running correctly.

cawood@ubuntu:~$ sudo apt-get install tasksel

(At this point, you may be told that you can run sudo apt-get autoremove to get rid of walinuxagent-data-saver. This is optional.)

cawood@ubuntu:~$ sudo tasksel install lamp-server

image

After you’ve installed the LAMP stack, you can test that each component is working.

Testing the Apache Web Server Install

First you can simply test that the index file exists by running these commands:

$ cd /var/www
$ cat index.html

<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>

To start editing your index page, you can run:

$ sudo nano index.html

On Azure, you must create an endpoint for the Apache port. This opens the Azure firewall to allow communication across a port for Apache.

image

Go to the Virtual Machine > Endpoints > Add. These are the standard values: name: http, protocol: tcp, public port :80, private port: 80. Once you’ve created the endpoint, you can browse to your new Apache server.

image

Test your MySQL Install

To make sure your MySQL install is working, simply run mysql and then type show databases; and press Enter. Couldn’t be easier. The result should look the window below.

image

Test PHP on your Server

Finally, to test your PHP install, you’ll need to create a file and then launch it in your favourite browser. Maybe because I'm nostalgic about the days of Pine, I’m a fan of the  GNU nano editor, so I use this command:

$ sudo nano /var/www/info.php

Add this content to the file:

<?php
phpinfo();
?>

After you’ve made your changes, Save and Exit by typing Ctrl+x, then y and Enter. Then you can open the info.php page using your machine IP or DNS name. For example, http://myvm.cloudapp.net/info.php.

image


There you go. The LAMP stack running on Windows Azure.

Tuesday, August 13, 2013

Remote Access to Ubuntu Linux VM on Windows Azure

Previous post: Linux (Ubuntu) Virtual Machine on Windows Azure

I was getting ready to write a post about connecting remotely to Ubuntu running on Windows Azure, when I found this post: Remote Desktop to Ubuntu in Windows Azure. Unfortunately, it doesn’t work with Ubuntu 13.4 (Raring Ringtail); which just happens to be the image I choose to install in my virtual machine. Rather than wrestle with it any longer, I’ve decided to create a new VM using the Ubuntu 12.04 LTS Server (Precise Pangolin) image.

You may wonder why anyone would bother setting up remote access since you can SSH into the machine remotely and do everything through the command line. For me, the answer is quite simple, I want another way to connect in case something goes wrong. I’ve had VMs get into bad states (both one Amazon AWS EC2 and Windows Azure), so I’d like the option to connect as many ways as possible.

Note: I've used the Ubuntu 12.04 LTS server image since newer versions of the Ubuntu Unity desktop don't have a 2D mode and therefore are difficult to use with remote client software. If someone has the solution to this issue, please leave a comment.

[Update: Of course, you fist have to set up SSH: How to Use SSH with Linux on Windows Azure. You should create an SSH key first and associate the certificate (*.pem file) with the VM when you create the VM.]

To get remote access to 12.04, here are the steps:

1. Connect using SSH. I like the Git Bash terminal that comes with the Git install. PuTTY is also a good SSH client.

2. Install a desktop. This command will take a while, so get yourself a cup of joe... and feel free to make it a grande.

sudo apt-get install ubuntu-desktop

image

3. Install XRDP/ VNC Server.

sudo apt-get install xrdp

4. In the Azure Management Portal, create a VM endpoint for XRDP. 3389 is the default port.

5. Use the "Connect" button from the Azure portal to download an RDP shortcut for your VM.

image

6. Open the shortcut and login.

image

Here are a couple of other posts on this topic:
http://azurecoder.azurewebsites.net/tag/ssh-to-linux-virtual-machine/
http://www.liberiangeek.net/2012/05/connect-to-ubuntu-12-04-precise-pangolin-via-windows-remote-desktop/

Tuesday, August 06, 2013

Enable SharePoint Document Sets in Office 365

This still requires a number of steps, so here’s the rundown:

This first key point is that this feature is only available to Office 365 Enterprise plans. If you’re not sure which plan you’re on, check with an admin.

Note: You must be a Site Collection Administrator or a Site Owner to create or configure Document Set content types.

image
- Creating a new document set

1. Enable Document Sets for a site collection

2. Create a new Document Set content type

Note: you don’t need to worry about the “Configure or customize a Document Set content type” unless you actually want to customize something.

3. Create a new instance of a Document Set

image

After you create and configure a Document Set content type, you must add it to the library where you want users to create their Document Sets.

To do this, go to Library Settings > Content Types (section) > Add from existing site content types

image
- adding the new content type to the site