CutCodeDown

Web Development => Other Web Programming => Topic started by: John_Betong on 24 Nov 2019, 12:41:15 am

Title: Anyone interested in Golang?
Post by: John_Betong on 24 Nov 2019, 12:41:15 am
I have previously delved into Golang, was impressed with the relatively simple language and especially the minimum amount of functions available. There is not a great deal to learn in order to get "Hello world" up and running on a local machine but I found it remarkably difficult to get it to sit side by side with an Apache2 VPS. I struggled and eventually managed to get Golang called with its very own URL. Shortly after life took over and Golang was pushed to the side. A couple of changed Internet Service Providers and failed hard-drives resulted in the relevant script beings lost :(


I am once again interested in Golang and appreciate that it is ideal where there is a lot of traffic per minute involved and currently PHP/MySql is perfectly adequate. The main reason I am interested is that a recent innovation has reduced the compiled executable file size to about twenty percent of previous compilations. I am under the impression the file size reduction should also reduce the "Time to First Byte" which would decrease rendering time.

I would like assistance in:
1. installing the Golang application on my localhost
2. compile the reduced "Hello world" application
3. upload the "Hello world" application to my server

Special notes:
a. Golang is not required to be installed on the remote server.
b. I have a VPS 1 Gb currently running Apache2
c. online Golang help available usually supplied by boffins way above my programming expertise :(

I would be grateful for help and advice preferably with others who would like a Golang URL. FreeNom.com has URLs that I use for this type of project They are free and propagate very quickly.





Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 24 Nov 2019, 10:08:42 am
I wanted to like Go, but gave up on it rather quickly.

There were things I liked, like the use of := for assignement and the parser not being as stupid as C, actually being able to figure out that anything after a "if" might be a evaluation not needing excess ()...

But I quickly soured on how painfully cryptic it was. Even the little bits of derp like having "func" for people too lazy to type the word "function" set off my BS alarm.

... and painfully cryptic it is. I mean lands sake the first code they present you uses "I cans haz teh ranguage moist goodry" of something called "fmt"... WTF is "fmt"?

The painful way it wants you to pointlessly dick around with directory structure, that they want to shove GIT down your throat even first starting out with their idiotic "workspaces" trash for people too stupid to manage their own directories... I mean lands sake anyone who would put code like this:

Code: [Select]
func Reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}

... into their beginners guide needs such a massive pimp-slap upside the head, their brains would shoot out one ear and go into orbit!

You get down to code like this:

Code: [Select]
for _, c := range cases {
got := Reverse(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}

...and it's like plow this AND the horse it rode in on.

Maybe it's my grounding in Wirth family languages like Pascal, Modula, and Ada, but this level of cryptic, shortened garbage is the antithesis of good practices, making even C++ look good. Good gravy it's only one step removed from brainf***!

Every codebase I've seen written with it reads like that joke about C and Unix I'm not convinced is a joke (https://www.gnu.org/fun/jokes/unix-hoax.html)

Where once they knew they had a clean compile on this:

Code: [Select]
for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);
They knew it was ready.

Much like Rust, the deeper into "go" you get, the more if feels like the language itself was made to win the IOCCC competition! (https://www.ioccc.org/)

Though so much of this seems to be the "wah wah, eye dunz wunna tie-p" nonsense that's guaranteed to make people create buggy unreliable unsustainable code bases. Perfect for today's twitter generation mouth-breathers who run around screaming "Aah, wall of text" over anything longer than two paragraphs.

... and I wanted to like it, I do like a lot of its concepts... but once I got into the syntax, the examples, and just trying to install the blasted thing, and honestly... my advice to anyone wanting to use it is to just use GCC and compile to native. It offers no real benefits whilst making C look good.

Making C look good NOT being something to aim for.
Title: Re: Anyone interested in Golang?
Post by: benanamen on 25 Nov 2019, 12:08:26 am
Last month I spent a solid week learning Go. Some stuff I liked but much I didn't care for. When it comes to web applications, you just cant beat PHP which was purposely built for the web.
Title: Re: Anyone interested in Golang?
Post by: John_Betong on 25 Nov 2019, 12:19:38 am
Many thanks for your rant although most surprised you actually gave up on such trivial matters especially when they are far from insurmountable?

I gather from the "just trying to install the blasted thing" comment that you failed to create an online version. I have vague memories there are at least four difference methods to create a Golang web site depending on ease of installation and performance.

[off-topic]
GCC was recommended instead of Golang so maybe create a thread detailing how an  executable C program can be created locally and uploaded without the need to install the C Framework.

Also how about a Christmassy Golang or C competition? 
[/off-topic]

Regarding their fmt() function, if you really, really wanted to a myFormat() function could have been created which called their fmt() function.

Both the directory structure and Git usage is optional and recommended no doubt due to their experience. I must admit most of their documentation is above my head along with the forum users.

The Reverse string function was typical of how the Boffins can optimise their functions. Why not just call the function, pass the parameter and appreciate not having to write the function yourself. Incidentally the only reverse string function usage that crossed my mind was to alphabetically sort emails by their provider and user name - any other uses?

Other complaints about the syntax being too cryptic was not really valid. A couple of their simple online examples managed to successfully compile.

Anyway what I like about Golang compilation fails with redundant variables, function calls, etc

To me it is akin to being able to drive a top notch racing car even though my driving skills lack the capability to glean the full performance. Far better than driving an old tractor where, through daily usage, my increased driving skills would be wasted.

As mentioned I would like some other users to help me to upload the locally produced "Hello world" executable. One small step for man, etc   

Another reason for wanting to install Golang is to increase my programming language skills because like yourself learning about Pascal, Delphi, Borland/Microsoft C, Prolog (a mind bender) and quite a few other flavours help me think outside of the box :)  Reminds me of the quote from your friend (Dan?)

The day you stop learning is the day the rest of the world leaves you behind.



Title: Re: Anyone interested in Golang?
Post by: John_Betong on 25 Nov 2019, 12:31:17 am
Last month I spent a solid week learning Go. Some stuff I liked but much I didn't care for. When it comes to web applications, you just cant beat PHP which was purposely built for the web.
Did you manage to create an online web site?

I agree Golang is different and that PHP appears to be the best tool for web programming especially with the ease to include the vast amount of libraries.

As mentioned I struggled with Golang but did manage to include the cached web page text joke pages. I believe there are quite a few Golang  static blog applications. I have tried a couple and dropped them because no current interest in creating a personal blog site.
Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 25 Nov 2019, 01:23:15 am
Many thanks for your rant although most surprised you actually gave up on such trivial matters especially when they are far from insurmountable?
Not insurmountable, annoying enough to make me wonder why I should use a language so cryptic when there are better alternatives. Like Pascal or Ada... or even C. And me praising or suggesting C would be like my suggesting someone use bootcrap.

But if it came down to w3.css and bootcrap, bootcrap wins.

I gather from the "just trying to install the blasted thing" comment that you failed to create an online version. I have vague memories there are at least four difference methods to create a Golang web site depending on ease of installation and performance.
Not sure what's so different that makes installing it to use it any different local or delivering online content. Certainly saw nothing in my experience to say that "online version" is even a THING differentiated from any other method of installation.

without the need to install the C Framework.
WTF is a "C Framework"? Do you mean the COMPILER. C doesn't need "frameworks" or any dependency bullshit, much less GCC should already be installed on 99%+ of web servers. You compile a native application, tell apache to call it via httpd.conf or .htaccess, and be done with it. All you need is a library for fastcgi interfacing, and that's barely 30 lines of code if done the "easy" way.

Same could be said of FPC. Ada... not so much.

NOT that I'd use EITHER language for websites. PHP is ubiquitous, it's fast enough, and it lacks much (but not all) of the BS that makes me dislike Go.

Regarding their fmt() function, if you really, really wanted to a myFormat() function could have been created which called their fmt() function.
So add a pointless bloated wrapper to compensate for the language or its libraries being needlessly and painfully cryptic? /FAIL/ at language design. Just one of the reasons I dislike PHP's idiotic "wrapper functions" for mysqli that exist just to mollycoddle the people who can't handle something as ridiculously simple as objects.

But to be fair, I'm one of those programmers who wants to find out who thought naming a function strstr was a good idea, and deliver a backhanded slap. That or introduce them to a rather large lady friend of mine who can explain what snusnu is. C is not my favorite programming language, and for something to be MORE cryptic than C is just astoundingly stupid.

High level languages should not be more cryptic than assembler mnemonics!

Both the directory structure and Git usage is optional and recommended no doubt due to their experience. I must admit most of their documentation is above my head along with the forum users.
Which is where it violates one of the basic rules of good programming and programming language creation. If you can't document it, don't write it... and if you HAVE to document it with more than a paragraph, you probably wrote it wrong.

The Reverse string function was typical of how the Boffins can optimise their functions. Why not just call the function, pass the parameter and appreciate not having to write the function yourself. Incidentally the only reverse string function usage that crossed my mind was to alphabetically sort emails by their provider and user name - any other uses?
My problem wasn't with what it does, or how they did it, or why they did it. My problem was with the simple fact it's a painfully cryptic mess filled with single letter variables and references, with endless pointless cryptic symbology that makes it ten times harder to figure out what the blazes it is even doing!

Other complaints about the syntax being too cryptic was not really valid. A couple of their simple online examples managed to successfully compile.
What does it compiling have to do with it being so cryptic it's hard for even PROGRAMMERS to figure out what it's doing. The compiler has dick-all to do with why cryptic is bad. By that logic and reasoning we should all be programming assembly language in binary.

Anyway what I like about Golang compilation fails with redundant variables, function calls, etc
Why I like Ada... But that isn't sufficient reason for me to use it when the code is so painfully and aggravatingly hard to understand.

... for someone who used to hand-assemble RCA 1802 and Z80 Machine language for a living, and has code running on satellites in orbit.

It reeks of "how pointlessly and aggravatingly complex can we make the syntax" L33tism. Again, it's one dead brain cell away from languages like brainf*** where code like this:

Code: [Select]
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Is the norm.
Title: Re: Anyone interested in Golang?
Post by: John_Betong on 25 Nov 2019, 01:36:56 am
Quote
Not sure what's so different that makes installing it to use it any different local or delivering online content. Certainly saw nothing in my experience to say that "online version" is even a THING differentiated from any other method of installation.
Golang compiles to an executable with a .go extension that Apache2 does not recognise.

As mentioned the compiled version is now reduced to about 20% of the former executable which should improve the "Time to First Byte".

I gather that I will not receive any positive feedback from my request so will try to solve the Online Server problem myself :(
Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 25 Nov 2019, 01:46:10 am
Golang compiles to an executable with a .go extension that Apache2 does not recognise.
if it's an executable, and the execute bit is set, you add it to the .htaccess or httpd.conf as a executable.

You make sure modCGI is loaded, allow execute in its directory, and add a handler. If for httpd.conf that would look something like:

Code: [Select]
ScriptAlias /browser/path "/var/www/siteName/executables"

<Directory "/var/www/siteName/executables">
AllowOverride None
Options ExecCGI
AddHandler cgi-script .go
</Directory>

(don't quote me on that, I might have botched the syntax)

/browser/path being the local path to the web-facing directory, such as /var/www/siteName/web/

If it's a native executable, it should work. Which is what go makes, native executables.

You're throwing a lot of terminology in there that does'nae make much sense. You bring "local host" into it, and "remote server"... it makes me wonder if you know what a native executable is and how they work. This is born out by your talking about "installing C framework" -- which isn't a thing -- or other such questions.

If it compiles to a native executable -- like C, Like modern Pascals, like GoLang -- the process for hooking it for fastCGI and html / other output should be the same.

I might just be looking at this in a different light as I've made websites and web applications using other real compilers. IF you're using a REAL compiler that makes native executables, there's nothing "special" about Go so far as integrating to the web is concerned.

Hell, 20 years ago I made an online die-roller in Pascal that Apache called no problem. Taking a native console application online is old-hat for me.
Title: Re: Anyone interested in Golang?
Post by: John_Betong on 25 Nov 2019, 08:45:37 am
Many thanks for the additional information.

Unfortunately I could not get Hello world to work on the remote server.

https://peacevase.tk/hello.go (https://peacevase.tk/hello.go)

I will have another go tomorrow.


Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 25 Nov 2019, 09:18:09 am
Many thanks for the additional information.

Unfortunately I could not get Hello world to work on the remote server.

https://peacevase.tk/hello.go (https://peacevase.tk/hello.go)

I will have another go tomorrow.

It probably shouldn't have a uri of .go if you want it to execute. I'd be routing it as the handler.

What does your http.conf or .htaccess to make .go execute look like?

For fun I might get FPC running on my server just to do a comparison, and to mark out what I did to make it run.

-- edit --

Actually did you compile it on the server or on your local machine? Executables aren't portable if they're actually native code, and even when they are compatible if it's not a stable platform like Windows, it's a REALLY good idea to recompile both for OS specific optimization, or for system specific. In theory with what should be a glorified console application (that's all a web language really is) it should be less of a problem so long as your "local" OS and processor architecture is the same as the one on the server.
Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 25 Nov 2019, 09:43:29 am
Hah, so far my own attempts using FPC are getting further along than yours...

Mine generates a 500 error.  ;)
Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 25 Nov 2019, 10:39:49 am
Ok, so I was right, if you were in the local .htaccess it's

Code: [Select]
Options +ExecCGI
AddHandler fcgid-script .so
Order allow,deny
Allow from all

**NOTE** I renamed my Pascal executable to .so just to check by extension/mime-type. Was easier to apt-get install fpc than to dick with trying to get golang working.

But in httpd.conf you'd want to directory restrict it.

Code: [Select]
<IfModule mod_fastcgi.c>
<Directory "/var/www/cutcodedown.com/web/">
# replace above directory path as  appropriate
Options +ExecCGI
AddHandler fcgid-script .fcgi
Order allow,deny
Allow from all
</Directory>
</IfModule>

Of course, this assumes your hosting account has suExec rights, and that your file is owned by the page owner. I was getting 500 errors because I created it as my user account via ssh and not the site account.

Now I'm getting 500 errors as I didn't code it for fastCGI, so pascal's writeLN is dumping direct to the logfile (/var/log/apache2/error.log). But that the logfile is getting the output proves I've at least got the Apache code correct.

But if your .so is a native executable written to use fastCGI, and you're on Apache, it should work.
Title: Re: Anyone interested in Golang?
Post by: benanamen on 25 Nov 2019, 02:16:17 pm
Many thanks for the additional information.

Unfortunately I could not get Hello world to work on the remote server.

https://peacevase.tk/hello.go (https://peacevase.tk/hello.go)

I will have another go tomorrow.

You cant compile Go on windows and have it work on Linux. Compile it on what you want it to run on.
Title: Re: Anyone interested in Golang?
Post by: John_Betong on 26 Nov 2019, 09:35:59 am
I tried again this morning and could not get "Hello world" to work.try again tomorrow

I also tried tutorials about installing a Golang Server, got it to work locally calling port:8080. Unfortunately could not get it to work remotely.

A couple of years ago I did get Golang to work remotely but changed web hosting providers a coffee off times and had hard disk failed and also forgotten how I managed to have Golang running on its own iURL.

My local computer runs Linux Ubuntu 19.10 and the remote Vps server runs Linux Ubuntu, not sure which version. I have about a dozen web sites all running Apache2 and MySql.

These other forum suggestions may be of interest:
https://forum.golangbridge.org/t/any-recommendations-for-a-good-tutorial-to-install-golang-onto-my-server/14584 (https://forum.golangbridge.org/t/any-recommendations-for-a-good-tutorial-to-install-golang-onto-my-server/14584)

Why is it so difficult? I'm convinced there is just too much information and I just seem to follow the wrong advice :)
Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 26 Nov 2019, 06:12:33 pm
I think you're either getting confused on the terminology, or on their piss poor documentation. You're using a lot of terms like "remotely" or "golang server" in ways that don't -- at least to me -- make a lick of sense given the topic. Seem completely unrelated to what golang is or how it works, at least by my understanding of how compilers are used to make software.

Though that's another reason I walked away from it, the way THEY use the terminology almost felt like they were just making shit up in utter ignorance of what the words they were using actually mean.
Title: Re: Anyone interested in Golang?
Post by: John_Betong on 26 Nov 2019, 07:48:36 pm
Please supply the terminology that your familiar with.


I would like your terms for the following:
1. Name for your computer that actually has a keyboard, screen, etc (my attempt localhost?)
2. Name for the URL and server name on the Vps (my attempt remote server)



Title: Re: Anyone interested in Golang?
Post by: Jason Knight on 26 Nov 2019, 08:47:04 pm
1. Name for your computer that actually has a keyboard, screen, etc (my attempt localhost?)
"My Computer", "my workstation", "my machine". the handy domain "localhost" exists on servers as a reference to "Self" so saying localhost makes it unclear just what machine you're talking about. On EVERY machine with networking "localhost" refers to itself.

2. Name for the URL and server name on the Vps (my attempt remote server)
URL, The server itself. Live server.  A server is a server whether it's serving via URI or by IP. Not sure what "server name" has to do with anything.

It's a server, remote has nothing to do with it.