Golang is weird!

I have just managed to get Golang to use local packages.

Go takes the approach that all packages are to be considered to be remote even if they are not.
This means that you need to define your projects package location in go.mod as if it were installed from the remote repository that you will deploy it to. You can then import the local module as if it were from that location but it will resolve to a local copy.

package github.com/company-name/project-name/project-root

You can then import github.com/company-name/project-name/project-root/mymodule

from a ./mymodule folder in your project. All go files in that folder will be imported.

The practical advantage is that you can use the same sample code if the library is local or remote without needing a distinct bundling tool.

The go test command is also odd. It by default only runs the tests in the current folder.
You need to use go test. ./... to get all the tests to run (which will be all files named *_test.go in the filesystem.

This is not very intuitive.

Integrating Typescript and Frontend Javascript

Recently I have been working on a AngularJS/Angular hybrid application.
Part of this involve having parallel routers. This requires coordinating the two systems as to which routes should be Angular and which should be AngularJS

Typescript does not allow build time metaprogramming that can generate the required javascript.

The typescript compiler cannot generate browser js.

Angular CLI does not allow the creation of modules that are not used for dynamic loading.

I considered using xslt to create both files that we needed.

In the end I used a json file that is checked by the typescript tests and put in the assets area so deployed by the Angular CLI.

Golang Magical Reference Date

Go solves the date parsing by using a magical reference date.

You start with this date

Mon Jan 2 15:04:05 MST 2006

Adjust it into whatever format that you use and use it for parsing dates.
This is neat solution. It would be even better if the go documentation for time.Parse were to mention it.

I found the solution here: https://programming.guide/go/format-parse-string-time-date-example.html

This has now been raised as https://github.com/golang/go/issues/48757

Thoughts on Golang

I am currently studying Golang as I may need to use it in an upcoming project.

So far it is C-- `as it is C with certain dangerous features removed.

There is no macro system. You can’t do pointer arithmetic.

The compiler is not quite as helpful as some languages that I have used recently (Elm and Elixir).

It’s not object-oriented or functional. You get old school procedural programming.

Given that it is compiled there is no repl to help. The documentation is a bit restricted. For example when looking at date parsing there are no examples on building custom strings.

It is fast and handles complex numbers natively.

Not yet reached using goroutines.