Amalegeni-Go > Step-by-step | |||||||||||
Amalegeni-Go | |||||||||||
Primitive : Ex 1 Struct : Ex 2 Map : Ex 3 Copy : Ex 4 Json Grab : Ex 5 CSV Load: Ex 6 |
Example 1 : returning a primitiveA function returning a single value(uses template se.tpl) Let's start with a simple example: a function that returns an int. The question answered by this function is: "how many tables do I have in the database?".
You put this code in the file src/ex01/ex01.amg, and then run 'amgo' (the amalegeni-go executable) on it. This converts it into go-code. The full build instructions are further down this page. The code calling your Count() function can look like the following:
Line 2 is where the function gets called. After an error check is done on the following line, the result of the count is printed. All the above code is pretty self-explanatory, ask for a more detailed explanation if it's unclear. A function returning a sliceLet's move ahead, and look at a function that returns a number of rows, eg. a slice of strings.
Again, it is called in a similar fashion:
Instructions on how to build itPrerequisites
InstructionsDownload and unpack the ex01.zip that contains the code for above examples, plus some boiler-plate code for connecting. When you open the 'ex01.amg' file, you'll notice it contains both the above examples. First edit the 'setenv.sh' script, see instructions in the file on what to do. Then execute it, to set the PATH and GOPATH environment variables.
Now run amgo (amalegeni-go) on the ex01.amg file:
Have a look at the generated file, the ..func.go file. Then compile the code:
And run...
| ||||||||||
© Willem Moors, 2013 - 2020 |