Researching Google Go: golang

Clarumedia DMS File-1601.73
Modified: 14/11/2019 21:42
Time to check out a new language. Google Go.
Having met a dev team manager on the wonderful "Heartspace" course at the Concord Institute, I was embarrassed to discover my ignorance of the Google Go language (golang) which has soared into popularity.

I ran it up on the workbench to see what it's about. To my great surprise, rather than a sense of "oh no, not another framework" I've found myself with a refreshing sense of excitement I haven't experienced since the adoption of HTML5 and W3C compliance by the major browser vendors !

So, here's a new "Technology Choice Conundrum": Would I be prepared to make the jump from PHP to GOLang for the back end of the Relator system ?
 

The Kickoff Test

  • How easy is it to install and get running on Linux using standard repositories ?
  • Does it perform ?
  • Is it easy to implement ?
  • Does it have useful libraries ?
  • Can it connect to the database ?
  • Does it have wide uptake ?
  • Will it still be relevant in 10 years time ?
 

Will it install natively on Ubuntu ?

 sudo apt-get install golang-go
I like that it's maintained in the Debian Repo. (40Mb)

Create a workspace

mkdir -p ~/go/{bin,src}
mkdir ~/go/src/test_project1
Nothing to write home about

Try a test webserver program

From their documentation:
 
vim ~/go/src/test_project1/test1.go
package main

import (
    "fmt"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello World:  %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}
 
Syntax highlighting is working in vim and Geany. Good start.

Let's compile and run

go build ~/go/src/test_project1/test1.go
/test1
It runs OK.

Webserver up and running

nmap localhost

Starting Nmap 7.60 ( https://nmap.org ) at 2019-11-13 12:43 GMT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000052s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
631/tcp  open  ipp
8080/tcp open  http-proxy
 
Port 8080 is open and working. Browser test works. So far so good.
I like the endpoint approach which I had to engineer for my DMS with Apache in Relator
 

Where is it logging and what happens when it blows up ?

I like that the compiler blows up with syntax errors.

Binding the Webserver process to port 631 (which I know is in use by CUPS on my machine) rightly throws a startup error.
 
2019/11/13 13:09:45 listen tcp :631: bind: permission denied

Errors are going to stderr as per this documentation

Reinventing Apache ?

Whilst it's appealing to start having visions of database managed website instances, I can see myself wanting to reinvent the Apache wheel. However, it has always been a source of frustration that aspects of Apache are unavailable to me in PHP. The chance to get in at a low level directly from the web server process is making me wide eyed with possibility. I'm wondering if the overhead in web process maintenance and setting up daemons with SystemD is actually going to be any more work than getting Apache configurations going.....
 

Errors and error handling

I am in love with the GoLang approach to error handling. I've never liked exception errors or the try / catch approaches of PHP and other languages because there's always the danger that the application will be sick all over the interface if it gets ill. Golang has adopted the approach that function calls return error codes if they go wrong and it's up to you to handle it. Great !
 

How about writing to syslog ?

They have a syslog package which works a treat in test.

It all feels very solid.

More Questions

  • Can it be called from Apache or do we have to use their system ? (Reinventing the wheel ?). Received Wisdom in November 2019 is to use the golang http daemon
  • What about process thread separation and security ? It requires specific implementation.
  • Templating ? Yes
  • Which RDBMS do they support and what are the driver interfaces ? All the DBs I use (Info)
  • What about database abstraction ?
  • Where are objects ? It works in a different way.
  • How do they handle arrays containing data with different data types ?










 

GoLang Server Running

Hello World