I think my question at least at first is more generic and I lack developer experience as I am a sysadmin/network guy by trade. Anyhow, I have built a golang server with about 200 lines of code. The program has a web server but also another go routine that accepts JSON data on another port and does things with the data to display. The code seems to work fine as it does exactly what I want it to do as far as I can tell. The problem is the server goes down after a couple days running. Or the most recent change I made it stays up for maybe half a day before being killed. What are ways to troubleshoot, build defensive code, etc. I am not used to building applications that stay running as standalone for long periods of time.
In production, have some service manager run your program. Systemd is adequate and there are other choices out there that are easier to work with (runit is my favorite). Make sure that it logs both stdout and stderr from your program. This way it will catch and log any panics, fatal errors or out of memory crashes that may happen, log them so you can figure out what happened, and restart your process. Add logging (to stdout) at relevant points in your program. Inspect the logs now and then and act on any irregularities.
At scale, add metrics instead perhaps using the Prometheus client library and run a Prometheus or similar server to collect and view them. This lets you trend memory usage, requests, errors etc and get an understanding of how your server works over time.
Based on your variables such as MinerResultArray, GpuAvgHashRate etc, I am guessing this may be crypto mining related. If thats the case some services such as Google Compute Engine do not allow it in their Free Tier.
If neither of those apply to you, then do some profiling using go tool pprof every few hours. It may point to a memory leak, timing bug or some process gone awry.
First of all I am running the machine on a stand-alone server running a Kali Linux 64 bit OS.
I am not sure what all your thoughts are on this but I stripped about half that code out to create a mini-server and I still have problems with it the program existing. The last thing I did was when I start the program I did this:
nohup ./miniserver
When using nohub it at least ran over night without exiting. I am not sure if this is an ideal method but I am going to let it run to see how long it stays up.